From b24c70523479c16eca848f5aafaa887549689ac6 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Fri, 29 Sep 2017 05:41:29 +0300 Subject: basic structure for feature-merge-similar-results --- ext/bg/js/api.js | 6 +++--- ext/bg/js/database.js | 3 ++- ext/bg/js/dictionary.js | 3 ++- ext/bg/js/options.js | 2 +- ext/bg/js/settings.js | 4 ++-- ext/bg/js/translator.js | 15 ++++++++++++++- ext/bg/settings.html | 13 +++++++++---- 7 files changed, 33 insertions(+), 13 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index 9f65bb07..01322357 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -29,9 +29,9 @@ async function apiTermsFind(text) { const options = utilBackend().options; const translator = utilBackend().translator; - const searcher = options.general.groupResults ? - translator.findTermsGrouped.bind(translator) : - translator.findTermsSplit.bind(translator); + const searcher = (options.general.resultOutputMode === 'merge') && translator.findTermsMerged.bind(translator) + || (options.general.resultOutputMode === 'split') && translator.findTermsSplit.bind(translator) + || (options.general.resultOutputMode === 'group') && translator.findTermsGrouped.bind(translator); const {definitions, length} = await searcher( text, diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 6ceb3ec8..29ab6d4e 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -208,7 +208,7 @@ class Database { }); } } else { - for (const [expression, reading, tags, rules, score, glossary] of entries) { + for (const [expression, reading, tags, rules, score, glossary, sequence] of entries) { rows.push({ expression, reading, @@ -216,6 +216,7 @@ class Database { rules, score, glossary, + sequence, dictionary: summary.title }); } diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 57acbe5e..f3f573d3 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -207,7 +207,8 @@ async function dictFieldFormat(field, definition, mode, options) { const data = { marker, definition, - group: options.general.groupResults, + group: options.general.resultOutputMode === 'group', + merge: options.general.resultOutputMode === 'merge', modeTermKanji: mode === 'term-kanji', modeTermKana: mode === 'term-kana', modeKanji: mode === 'kanji' diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 36ab7694..de3da943 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -132,7 +132,7 @@ function optionsSetDefaults(options) { enable: true, audioSource: 'jpod101', audioVolume: 100, - groupResults: true, + resultOutputMode: 'group', debugInfo: false, maxResults: 32, showAdvanced: false, diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index a2f22371..c5a28a45 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -22,9 +22,9 @@ async function formRead() { const optionsNew = $.extend(true, {}, optionsOld); optionsNew.general.showGuide = $('#show-usage-guide').prop('checked'); + optionsNew.general.resultOutputMode = $('#result-output-mode').val(); optionsNew.general.audioSource = $('#audio-playback-source').val(); optionsNew.general.audioVolume = parseFloat($('#audio-playback-volume').val()); - optionsNew.general.groupResults = $('#group-terms-results').prop('checked'); optionsNew.general.debugInfo = $('#show-debug-info').prop('checked'); optionsNew.general.showAdvanced = $('#show-advanced-options').prop('checked'); optionsNew.general.maxResults = parseInt($('#max-displayed-results').val(), 10); @@ -124,9 +124,9 @@ async function onReady() { const options = await optionsLoad(); $('#show-usage-guide').prop('checked', options.general.showGuide); + $('#result-output-mode').val(options.general.resultOutputMode); $('#audio-playback-source').val(options.general.audioSource); $('#audio-playback-volume').val(options.general.audioVolume); - $('#group-terms-results').prop('checked', options.general.groupResults); $('#show-debug-info').prop('checked', options.general.debugInfo); $('#show-advanced-options').prop('checked', options.general.showAdvanced); $('#max-displayed-results').val(options.general.maxResults); diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index c915dbc0..8fa2b60b 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -48,6 +48,18 @@ class Translator { return {length, definitions: definitionsGrouped}; } + async findTermsMerged(text, dictionaries, alphanumeric) { + const titles = Object.keys(dictionaries); + const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric); + + const definitionsMerged = dictTermsGroup(definitions, dictionaries); + // for (const definition of definitionsMerged) { + // await this.buildTermFrequencies(definition, titles); + // } + + return {length, definitions: definitionsMerged}; + } + async findTermsSplit(text, dictionaries, alphanumeric) { const titles = Object.keys(dictionaries); const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric); @@ -90,7 +102,8 @@ class Translator { expression: definition.expression, reading: definition.reading, glossary: definition.glossary, - tags: dictTagsSort(tags) + tags: dictTagsSort(tags), + sequence: definition.sequence }); } } diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 4315d74b..6274f3cb 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -35,10 +35,6 @@ -
- -
-
@@ -47,6 +43,15 @@ +
+ + +
+