aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-09-13 23:22:41 -0700
committerAlex Yatskov <alex@foosoft.net>2017-09-13 23:22:41 -0700
commitf5009cd63ccb9e9d9aed3a1d4994c5c8e011f3a4 (patch)
tree9b96f8444aef946a1fa4ccda82544de23f09a7b1 /ext/bg/js/translator.js
parent33d9d6ff573d72a8b1600b23b20faf2b0ca4419c (diff)
cleanup
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r--ext/bg/js/translator.js33
1 files changed, 26 insertions, 7 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 0ecae16b..19769536 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -37,8 +37,26 @@ class Translator {
}
async findTermsGrouped(text, dictionaries, alphanumeric) {
+ const titles = Object.keys(dictionaries);
const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric);
- return {length, definitions: dictTermsGroup(definitions, dictionaries)};
+
+ const definitionsGrouped = dictTermsGroup(definitions, dictionaries);
+ for (const definition of definitionsGrouped) {
+ this.buildTermFrequencies(definition, titles);
+ }
+
+ return {length, definitions: definitionsGrouped};
+ }
+
+ async findTermsSplit(text, dictionaries, alphanumeric) {
+ const titles = Object.keys(dictionaries);
+ const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric);
+
+ for (const definition of definitions) {
+ this.buildTermFrequencies(definition, titles);
+ }
+
+ return {length, definitions};
}
async findTerms(text, dictionaries, alphanumeric) {
@@ -63,13 +81,7 @@ class Translator {
const tags = await this.buildTags(definition.tags, definition.dictionary);
tags.push(dictTagBuildSource(definition.dictionary));
- let frequencies = await this.database.findTermFreq(definition.expression, titles);
- if (frequencies.length === 0) {
- frequencies = await this.database.findTermFreq(definition.reading, titles);
- }
-
definitions.push({
- frequencies,
source: deinflection.source,
reasons: deinflection.reasons,
score: definition.score,
@@ -134,6 +146,13 @@ class Translator {
return definitions;
}
+ async buildTermFrequencies(definition, titles) {
+ definition.frequencies = await this.database.findTermFreq(definition.expression, titles);
+ if (definition.frequencies.length === 0) {
+ definition.frequencies = await this.database.findTermFreq(definition.reading, titles);
+ }
+ }
+
async buildTags(names, title) {
const results = [];
for (const name of names) {