diff options
author | Alex Yatskov <alex@foosoft.net> | 2016-10-21 20:43:09 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2016-10-21 20:43:09 -0700 |
commit | 83f5bd24dfeb60637141ddc7cd0b99513ac74eec (patch) | |
tree | 49e4ea33d0366f0daf0d38bd89426dd8e5d8d436 /ext/bg/js/translator.js | |
parent | 5467ed11e10addf2ceedf062ce151d88ea448fd1 (diff) |
Enable katakana soft search (resolves #14)
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r-- | ext/bg/js/translator.js | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 8f895800..44f37e31 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -105,11 +105,24 @@ class Translator { return Promise.all(deinflectPromises).then(() => deinflectGroups); } - findTerm(text) { - return this.findTermGroups(text).then(deinflectGroups => { + findTerm(text, enableSoftKatakanaSearch) { + return this.findTermGroups(text).then(groups => { + const textHiragana = wanakana._katakanaToHiragana(text); + if (text !== textHiragana && enableSoftKatakanaSearch) { + return this.findTermGroups(textHiragana).then(groupsHiragana => { + for (const key in groupsHiragana) { + groups[key] = groups[key] || groupsHiragana[key]; + } + + return groups; + }); + } else { + return groups; + } + }).then(groups => { const definitions = []; - for (const key in deinflectGroups) { - definitions.push(deinflectGroups[key]); + for (const key in groups) { + definitions.push(groups[key]); } let length = 0; |