summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/deinflector.js19
-rw-r--r--ext/bg/js/translator.js36
2 files changed, 26 insertions, 29 deletions
diff --git a/ext/bg/js/deinflector.js b/ext/bg/js/deinflector.js
index 03f9d40a..3c24ae3a 100644
--- a/ext/bg/js/deinflector.js
+++ b/ext/bg/js/deinflector.js
@@ -32,7 +32,7 @@ class Deinflection {
}
for (const tag of this.tags) {
- if (this.searchTags(tag, tags)) {
+ if (tags.indexOf(tag) !== -1) {
return true;
}
}
@@ -43,7 +43,7 @@ class Deinflection {
deinflect(validator, rules) {
if (this.validate(validator)) {
- const child = new Deinflection(this.term);
+ const child = new Deinflection(this.term, this.tags);
this.children.push(child);
}
@@ -52,7 +52,7 @@ class Deinflection {
for (const v of variants) {
let allowed = this.tags.length === 0;
for (const tag of this.tags) {
- if (this.searchTags(tag, v.tagsIn)) {
+ if (v.tagsIn.indexOf(tag) !== -1) {
allowed = true;
break;
}
@@ -73,20 +73,9 @@ class Deinflection {
return this.children.length > 0;
}
- searchTags(tag, tags) {
- for (const t of tags) {
- const re = new RegExp(tag);
- if (re.test(t)) {
- return true;
- }
- }
-
- return false;
- }
-
gather() {
if (this.children.length === 0) {
- return [{root: this.term, rules: []}];
+ return [{root: this.term, tags: this.tags, rules: []}];
}
const paths = [];
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
+ };
+ }
}
}