summaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authorAlex Yatskov <FooSoft@users.noreply.github.com>2019-10-05 19:49:54 -0700
committerGitHub <noreply@github.com>2019-10-05 19:49:54 -0700
commit14a5e3ce209cba41000251c460e790bbafe6de03 (patch)
tree8d1576b86c6d644ae14ba5f556ad96220afb2e8b /ext/bg/js/translator.js
parent4df8662ea9ae99d6e8a11c49dfc9b702eb360049 (diff)
parent50a47348a7a040d1bcaf0a12a38cca049dc207f7 (diff)
Merge pull request #238 from toasted-nutbread/deinflector-optimization
Deinflector optimization
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r--ext/bg/js/translator.js17
1 files changed, 3 insertions, 14 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 65d746ea..601ee30c 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -238,8 +238,10 @@ class Translator {
const definitions = await this.database.findTermsBulk(uniqueDeinflectionTerms, titles);
for (const definition of definitions) {
+ const definitionRules = Deinflector.rulesToRuleFlags(definition.rules);
for (const deinflection of uniqueDeinflectionArrays[definition.index]) {
- if (Translator.definitionContainsAnyRule(definition, deinflection.rules)) {
+ const deinflectionRules = deinflection.rules;
+ if (deinflectionRules === 0 || (definitionRules & deinflectionRules) !== 0) {
deinflection.definitions.push(definition);
}
}
@@ -248,19 +250,6 @@ class Translator {
return deinflections.filter(e => e.definitions.length > 0);
}
- static definitionContainsAnyRule(definition, rules) {
- if (rules.length === 0) {
- return true;
- }
- const definitionRules = definition.rules;
- for (const rule of rules) {
- if (definitionRules.includes(rule)) {
- return true;
- }
- }
- return false;
- }
-
getDeinflections(text) {
const deinflections = [];