diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-01-16 20:54:01 -0800 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-01-16 20:54:01 -0800 |
commit | 268e00435f081b81ac0426bd3e316acb1bb33915 (patch) | |
tree | 1b93e3110058a56b14e0cbf5fe52d89916af744e /ext/bg/js/translator.js | |
parent | e8840465f07f09fbb9acb6071b94489f02ecd87f (diff) |
support for dictionary priority sorting
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r-- | ext/bg/js/translator.js | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 4edf35ac..e7c2aac2 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -42,11 +42,13 @@ class Translator { } findTerms(text, dictionaries, softKatakana) { + const titles = Object.keys(dictionaries); const cache = {}; - return this.findTermsDeinflected(text, dictionaries, cache).then(deinfLiteral => { + + return this.findTermsDeinflected(text, titles, cache).then(deinfLiteral => { const textHiragana = wanakana._katakanaToHiragana(text); if (text !== textHiragana && softKatakana) { - return this.findTermsDeinflected(textHiragana, dictionaries, cache).then(deinfHiragana => deinfLiteral.concat(deinfHiragana)); + return this.findTermsDeinflected(textHiragana, titles, cache).then(deinfHiragana => deinfLiteral.concat(deinfHiragana)); } else { return deinfLiteral; } @@ -71,7 +73,7 @@ class Translator { } definitions = undupeTermDefs(definitions); - definitions = sortTermDefs(definitions); + definitions = sortTermDefs(definitions, dictionaries); let length = 0; for (const definition of definitions) { @@ -84,15 +86,18 @@ class Translator { findTermsGrouped(text, dictionaries, softKatakana) { return this.findTerms(text, dictionaries, softKatakana).then(({length, definitions}) => { - return {length, definitions: groupTermDefs(definitions)}; + return {length, definitions: groupTermDefs(definitions, dictionaries)}; }); } findKanji(text, dictionaries) { - const processed = {}, promises = []; + const titles = Object.keys(dictionaries); + const processed = {}; + const promises = []; + for (const c of text) { if (!processed[c]) { - promises.push(this.database.findKanji(c, dictionaries)); + promises.push(this.database.findKanji(c, titles)); processed[c] = true; } } |