diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-11-04 20:09:34 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-11-10 14:02:43 -0500 |
commit | af1662acadbfb7a96e06257a9dfad71ed6e2c478 (patch) | |
tree | 28e38fe7d35b70d41d4b6dcf766dc1b269ae109c /ext/bg/js/translator.js | |
parent | ae10bb7096fafc94ffb7227a16e13373c1c1c403 (diff) |
Update how apiTermsFind works
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r-- | ext/bg/js/translator.js | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 305619a5..d33a2e27 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -141,9 +141,23 @@ class Translator { return result; } - async findTermsGrouped(text, dictionaries, alphanumeric, options) { + async findTerms(text, options) { + switch (options.general.resultOutputMode) { + case 'group': + return await this.findTermsGrouped(text, options); + case 'merge': + return await this.findTermsMerged(text, options); + case 'split': + return await this.findTermsSplit(text, options); + default: + return [[], 0]; + } + } + + async findTermsGrouped(text, options) { + const dictionaries = dictEnabledSet(options); const titles = Object.keys(dictionaries); - const {length, definitions} = await this.findTermsInternal(text, dictionaries, alphanumeric); + const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric); const definitionsGrouped = dictTermsGroup(definitions, dictionaries); await this.buildTermFrequencies(definitionsGrouped, titles); @@ -154,13 +168,14 @@ class Translator { } } - return {length, definitions: definitionsGrouped}; + return [definitionsGrouped, length]; } - async findTermsMerged(text, dictionaries, alphanumeric, options) { + async findTermsMerged(text, options) { + const dictionaries = dictEnabledSet(options); const secondarySearchTitles = Object.keys(options.dictionaries).filter(dict => options.dictionaries[dict].allowSecondarySearches); const titles = Object.keys(dictionaries); - const {length, definitions} = await this.findTermsInternal(text, dictionaries, alphanumeric); + const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric); const {sequencedDefinitions, defaultDefinitions} = await this.getSequencedDefinitions(definitions, options.general.mainDictionary); const definitionsMerged = []; const mergedByTermIndices = new Set(); @@ -191,23 +206,24 @@ class Translator { } } - return {length, definitions: dictTermsSort(definitionsMerged)}; + return [dictTermsSort(definitionsMerged), length]; } - async findTermsSplit(text, dictionaries, alphanumeric) { + async findTermsSplit(text, options) { + const dictionaries = dictEnabledSet(options); const titles = Object.keys(dictionaries); - const {length, definitions} = await this.findTermsInternal(text, dictionaries, alphanumeric); + const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric); await this.buildTermFrequencies(definitions, titles); - return {length, definitions}; + return [definitions, length]; } async findTermsInternal(text, dictionaries, alphanumeric) { if (!alphanumeric && text.length > 0) { const c = text[0]; if (!jpIsKana(c) && !jpIsKanji(c)) { - return {length: 0, definitions: []}; + return [[], 0]; } } @@ -246,7 +262,7 @@ class Translator { length = Math.max(length, definition.source.length); } - return {length, definitions}; + return [definitions, length]; } async findTermDeinflections(text, text2, titles) { |