summaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-11-04 20:52:08 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-11-10 14:02:43 -0500
commit7333873244ccaeeefe01bd3a63447f39dd4f3bbe (patch)
tree96c75fbc5ddad4850132dfd6f59f47cb6925dac0 /ext/bg/js/translator.js
parent3a225c3f916d435e04fb30afa731c30c4309fc7f (diff)
Add support for wildcards
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r--ext/bg/js/translator.js27
1 files changed, 23 insertions, 4 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index dac53f93..583d6e31 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -227,9 +227,12 @@ class Translator {
}
}
- const textHiragana = jpKatakanaToHiragana(text);
const titles = Object.keys(dictionaries);
- const deinflections = await this.findTermDeinflections(text, textHiragana, titles);
+ const deinflections = (
+ details.wildcard ?
+ await this.findTermWildcard(text, titles) :
+ await this.findTermDeinflections(text, titles)
+ );
let definitions = [];
for (const deinflection of deinflections) {
@@ -265,7 +268,23 @@ class Translator {
return [definitions, length];
}
- async findTermDeinflections(text, text2, titles) {
+ async findTermWildcard(text, titles) {
+ const definitions = await this.database.findTermsBulk([text], titles, true);
+ if (definitions.length === 0) {
+ return [];
+ }
+
+ return [{
+ source: text,
+ term: text,
+ rules: 0,
+ definitions,
+ reasons: []
+ }];
+ }
+
+ async findTermDeinflections(text, titles) {
+ const text2 = jpKatakanaToHiragana(text);
const deinflections = (text === text2 ? this.getDeinflections(text) : this.getDeinflections2(text, text2));
if (deinflections.length === 0) {
@@ -289,7 +308,7 @@ class Translator {
deinflectionArray.push(deinflection);
}
- const definitions = await this.database.findTermsBulk(uniqueDeinflectionTerms, titles);
+ const definitions = await this.database.findTermsBulk(uniqueDeinflectionTerms, titles, false);
for (const definition of definitions) {
const definitionRules = Deinflector.rulesToRuleFlags(definition.rules);