diff options
author | Alex Yatskov <alex@foosoft.net> | 2016-04-16 20:11:27 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2016-04-16 20:11:27 -0700 |
commit | 9ceef4649f07211079017d2cfcbc3756dd9a509b (patch) | |
tree | 8bc506f337a19e165e1391229c12e32480accd24 /ext/bg/js/translator.js | |
parent | ccf545919054be4dc2aa9efdc7cd914c867775a8 (diff) |
Fixes to deinflection logic
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r-- | ext/bg/js/translator.js | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 101083e8..46d63ed0 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -77,11 +77,9 @@ class Translator { return tags; }); - if (dfs === null) { - this.processTerm(groups, term); - } else { + if (dfs !== null) { for (const df of dfs) { - this.processTerm(groups, df.source, df.rules, df.root); + this.processTerm(groups, df.source, df.tags, df.rules, df.root); } } } @@ -141,20 +139,30 @@ class Translator { return results; } - processTerm(groups, source, rules=[], root='') { - for (const entry of this.dictionary.findTerm(root || source)) { + processTerm(groups, source, tags, rules=[], root='') { + for (const entry of this.dictionary.findTerm(root)) { if (entry.id in groups) { continue; } - groups[entry.id] = { - expression: entry.expression, - reading: entry.reading, - glossary: entry.glossary, - tags: entry.tags, - source: source, - rules: rules - }; + let matched = tags.length == 0; + for (const tag of tags) { + if (entry.tags.indexOf(tag) !== -1) { + matched = true; + break; + } + } + + if (matched) { + groups[entry.id] = { + expression: entry.expression, + reading: entry.reading, + glossary: entry.glossary, + tags: entry.tags, + source: source, + rules: rules + }; + } } } |