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/settings.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/bg/js/settings.js') 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); -- cgit v1.2.3 From cfad3b309976213c45f99bef3b8fad072c6bb9ec Mon Sep 17 00:00:00 2001 From: siikamiika Date: Thu, 5 Oct 2017 05:21:07 +0300 Subject: merged mode: add main dictionary selection --- ext/bg/js/database.js | 27 ++++++++++++++------------- ext/bg/js/dictionary.js | 4 ++-- ext/bg/js/options.js | 4 ++++ ext/bg/js/settings.js | 30 ++++++++++++++++++++++++++---- ext/bg/js/templates.js | 4 +++- ext/bg/js/translator.js | 5 +++-- tmpl/dictionary.html | 1 + 7 files changed, 53 insertions(+), 22 deletions(-) (limited to 'ext/bg/js/settings.js') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 0de0505d..7a893fc0 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -85,25 +85,26 @@ class Database { return results; } - async findTermsBySequence(sequence, dictionary) { + async findTermsBySequence(sequence, mainDictionary) { if (!this.db) { throw 'Database not initialized'; } const results = []; await this.db.terms.where('sequence').equals(sequence).each(row => { - // if (dictionary === row.dictionary) { - results.push({ - expression: row.expression, - reading: row.reading, - tags: dictFieldSplit(row.tags), - rules: dictFieldSplit(row.rules), - glossary: row.glossary, - score: row.score, - dictionary: row.dictionary, - id: row.id, - sequence: typeof row.sequence === 'undefined' ? -1 : row.sequence - }); + if (row.dictionary === mainDictionary) { + results.push({ + expression: row.expression, + reading: row.reading, + tags: dictFieldSplit(row.tags), + rules: dictFieldSplit(row.rules), + glossary: row.glossary, + score: row.score, + dictionary: row.dictionary, + id: row.id, + sequence: typeof row.sequence === 'undefined' ? -1 : row.sequence + }); + } }); return results; diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 2b289a23..c20df400 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -144,10 +144,10 @@ function dictTermsGroup(definitions, dictionaries) { return dictTermsSort(results); } -function dictTermsMergeBySequence(definitions) { +function dictTermsMergeBySequence(definitions, mainDictionary) { const definitionsBySequence = {'-1': []}; for (const definition of definitions) { - if (definition.sequence > 0) { + if (mainDictionary === definition.dictionary && definition.sequence > 0) { if (!definitionsBySequence[definition.sequence]) { definitionsBySequence[definition.sequence] = { reasons: definition.reasons, diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index b49c32da..0aa6d7c6 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -154,6 +154,10 @@ function optionsSetDefaults(options) { dictionaries: {}, + dictionary: { + main: '' + }, + anki: { enable: false, server: 'http://127.0.0.1:8765', diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index c5a28a45..4d248304 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -60,7 +60,11 @@ async function formRead() { const title = dictionary.data('title'); const priority = parseInt(dictionary.find('.dict-priority').val(), 10); const enabled = dictionary.find('.dict-enabled').prop('checked'); - optionsNew.dictionaries[title] = {priority, enabled}; + const main = dictionary.find('.dict-main').prop('checked'); + if (main) { + optionsNew.dictionary.main = title; + } + optionsNew.dictionaries[title] = {priority, enabled, main}; }); return {optionsNew, optionsOld}; @@ -237,6 +241,18 @@ function dictionaryGroupsSort() { dictGroups.append(dictGroupChildren); } +function dictionarySetMain(e) { + const mainDictionary = $(e.target).closest('.dict-group'); + const mainDictionaryTitle = mainDictionary.data('title'); + + $('.dict-group').each((index, element) => { + const dictionary = $(element); + if (dictionary.data('title') !== mainDictionaryTitle) { + dictionary.find('.dict-main').prop('checked', false); + } + }); +} + async function dictionaryGroupsPopulate(options) { const dictGroups = $('#dict-groups').empty(); const dictWarning = $('#dict-warning').hide(); @@ -247,13 +263,14 @@ async function dictionaryGroupsPopulate(options) { } for (const dictRow of dictRowsSort(dictRows, options)) { - const dictOptions = options.dictionaries[dictRow.title] || {enabled: false, priority: 0}; + const dictOptions = options.dictionaries[dictRow.title] || {enabled: false, priority: 0, main: false}; const dictHtml = await apiTemplateRender('dictionary.html', { title: dictRow.title, version: dictRow.version, revision: dictRow.revision, priority: dictOptions.priority, - enabled: dictOptions.enabled + enabled: dictOptions.enabled, + main: dictOptions.main }); dictGroups.append($(dictHtml)); @@ -265,6 +282,11 @@ async function dictionaryGroupsPopulate(options) { dictionaryGroupsSort(); onFormOptionsChanged(e); }); + + $('.dict-main').change(e => { + dictionarySetMain(e); + onFormOptionsChanged(e); + }); } async function onDictionaryPurge(e) { @@ -308,7 +330,7 @@ async function onDictionaryImport(e) { const options = await optionsLoad(); const summary = await utilDatabaseImport(e.target.files[0], updateProgress); - options.dictionaries[summary.title] = {enabled: true, priority: 0}; + options.dictionaries[summary.title] = {enabled: true, priority: 0, main: false}; await optionsSave(options); await dictionaryGroupsPopulate(options); diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index c6de8580..4341322a 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -13,7 +13,9 @@ templates['dictionary.html'] = template({"1":function(container,depth0,helpers,p + alias4(((helper = (helper = helpers.revision || (depth0 != null ? depth0.revision : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"revision","hash":{},"data":data}) : helper))) + "\n\n
\n \n
\n
\n \n \n
\n
\n \n +
-- cgit v1.2.3 From 7783aa4c1a36784b709aba768c17d9476a16a43d Mon Sep 17 00:00:00 2001 From: siikamiika Date: Wed, 11 Oct 2017 19:58:57 +0300 Subject: reset main dictionary on purge --- ext/bg/js/settings.js | 1 + 1 file changed, 1 insertion(+) (limited to 'ext/bg/js/settings.js') diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 4d248304..cab9c056 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -302,6 +302,7 @@ async function onDictionaryPurge(e) { await utilDatabasePurge(); const options = await optionsLoad(); options.dictionaries = {}; + options.dictionary.main = ''; await optionsSave(options); await dictionaryGroupsPopulate(options); -- cgit v1.2.3 From 4e57fa1ad1cd85e18b2ae2c1d43480832533f9a7 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Thu, 12 Oct 2017 01:10:05 +0300 Subject: merged mode: remove options.dictionary.main --- ext/bg/js/options.js | 4 ---- ext/bg/js/settings.js | 4 ---- ext/bg/js/translator.js | 5 +++-- 3 files changed, 3 insertions(+), 10 deletions(-) (limited to 'ext/bg/js/settings.js') diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 0aa6d7c6..b49c32da 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -154,10 +154,6 @@ function optionsSetDefaults(options) { dictionaries: {}, - dictionary: { - main: '' - }, - anki: { enable: false, server: 'http://127.0.0.1:8765', diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index cab9c056..6016b38a 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -61,9 +61,6 @@ async function formRead() { const priority = parseInt(dictionary.find('.dict-priority').val(), 10); const enabled = dictionary.find('.dict-enabled').prop('checked'); const main = dictionary.find('.dict-main').prop('checked'); - if (main) { - optionsNew.dictionary.main = title; - } optionsNew.dictionaries[title] = {priority, enabled, main}; }); @@ -302,7 +299,6 @@ async function onDictionaryPurge(e) { await utilDatabasePurge(); const options = await optionsLoad(); options.dictionaries = {}; - options.dictionary.main = ''; await optionsSave(options); await dictionaryGroupsPopulate(options); diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 737abd08..99344b95 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -50,10 +50,11 @@ class Translator { async findTermsMerged(text, dictionaries, alphanumeric) { const options = await apiOptionsGet(); + const mainDictionary = Object.keys(options.dictionaries).filter(dict => options.dictionaries[dict].main).concat([''])[0]; const titles = Object.keys(dictionaries); const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric); - const definitionsBySequence = dictTermsMergeBySequence(definitions, options.dictionary.main); + const definitionsBySequence = dictTermsMergeBySequence(definitions, mainDictionary); const definitionsMerged = []; const mergedByTermIndices = new Set(); @@ -64,7 +65,7 @@ class Translator { const result = definitionsBySequence[sequence]; - const rawDefinitionsBySequence = await this.database.findTermsBySequence(Number(sequence), options.dictionary.main); + const rawDefinitionsBySequence = await this.database.findTermsBySequence(Number(sequence), mainDictionary); const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence); dictTermsMergeByGloss(result, definitionsBySequence['-1'], definitionsByGloss, mergedByTermIndices); -- cgit v1.2.3 From 8d660e282911ffb5d7b504784a3c09f13b164953 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Thu, 12 Oct 2017 09:59:09 +0300 Subject: add compact tags --- ext/bg/js/dictionary.js | 26 ++++++++++++++++++++++++++ ext/bg/js/options.js | 3 ++- ext/bg/js/settings.js | 2 ++ ext/bg/js/templates.js | 36 ++++++++++++++++++------------------ ext/bg/js/translator.js | 13 +++++++++++++ ext/bg/settings.html | 4 ++++ tmpl/terms.html | 14 +++++++------- 7 files changed, 72 insertions(+), 26 deletions(-) (limited to 'ext/bg/js/settings.js') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index ee4f5946..14f90d29 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -110,6 +110,32 @@ function dictTermsUndupe(definitions) { return definitionsUnique; } +function dictTermsCompressTags(definitions) { + let lastDictionary = ''; + let lastPos = ''; + + for (const definition of definitions) { + const dictionary = JSON.stringify(definition.tags.filter(tag => tag.category === 'dictionary').map(tag => tag.name).sort()); + const pos = JSON.stringify(definition.tags.filter(tag => tag.category === 'pos').map(tag => tag.name).sort()); + + const filterOutCategories = []; + + if (lastDictionary === dictionary) { + filterOutCategories.push('dictionary'); + } else { + lastDictionary = dictionary; + } + + if (lastPos === pos) { + filterOutCategories.push('pos'); + } else { + lastPos = pos; + } + + definition.tags = definition.tags.filter(tag => !filterOutCategories.includes(tag.category)); + } +} + function dictTermsGroup(definitions, dictionaries) { const groups = {}; for (const definition of definitions) { diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index b49c32da..eef893c7 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -139,7 +139,8 @@ function optionsSetDefaults(options) { popupWidth: 400, popupHeight: 250, popupOffset: 10, - showGuide: true + showGuide: true, + compactTags: false }, scanning: { diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 6016b38a..f59c3ad0 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -22,6 +22,7 @@ async function formRead() { const optionsNew = $.extend(true, {}, optionsOld); optionsNew.general.showGuide = $('#show-usage-guide').prop('checked'); + optionsNew.general.compactTags = $('#compact-tags').prop('checked'); optionsNew.general.resultOutputMode = $('#result-output-mode').val(); optionsNew.general.audioSource = $('#audio-playback-source').val(); optionsNew.general.audioVolume = parseFloat($('#audio-playback-volume').val()); @@ -125,6 +126,7 @@ async function onReady() { const options = await optionsLoad(); $('#show-usage-guide').prop('checked', options.general.showGuide); + $('#compact-tags').prop('checked', options.general.compactTags); $('#result-output-mode').val(options.general.resultOutputMode); $('#audio-playback-source').val(options.general.audioSource); $('#audio-playback-volume').val(options.general.audioVolume); diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 19c49337..e8bd43e9 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -206,30 +206,16 @@ templates['model.html'] = template({"1":function(container,depth0,helpers,partia templates['terms.html'] = template({"1":function(container,depth0,helpers,partials,data) { var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {}); - return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.only : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.only : depth0),{"name":"if","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(9, data, 0),"inverse":container.program(13, data, 0),"data":data})) != null ? stack1 : ""); },"2":function(container,depth0,helpers,partials,data) { var stack1; - return "
\n (" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.only : depth0),{"name":"each","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + " only)\n
\n"; -},"3":function(container,depth0,helpers,partials,data) { - var stack1; - - return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : "") - + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.last),{"name":"unless","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "\n"; -},"4":function(container,depth0,helpers,partials,data) { - return ", "; -},"6":function(container,depth0,helpers,partials,data) { - var stack1; - return "
\n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n"; -},"7":function(container,depth0,helpers,partials,data) { +},"3":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; return " " + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + "\n"; +},"5":function(container,depth0,helpers,partials,data) { + var stack1; + + return "
\n (" + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.only : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + " only)\n
\n"; +},"6":function(container,depth0,helpers,partials,data) { + var stack1; + + return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : "") + + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.last),{"name":"unless","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n"; +},"7":function(container,depth0,helpers,partials,data) { + return ", "; },"9":function(container,depth0,helpers,partials,data) { var stack1; diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 99344b95..e307efc0 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -37,6 +37,7 @@ class Translator { } async findTermsGrouped(text, dictionaries, alphanumeric) { + const options = await apiOptionsGet(); const titles = Object.keys(dictionaries); const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric); @@ -45,6 +46,12 @@ class Translator { await this.buildTermFrequencies(definition, titles); } + if (options.general.compactTags) { + for (const definition of definitionsGrouped) { + dictTermsCompressTags(definition.definitions); + } + } + return {length, definitions: definitionsGrouped}; } @@ -120,6 +127,12 @@ class Translator { await this.buildTermFrequencies(definition, titles); } + if (options.general.compactTags) { + for (const definition of definitionsMerged) { + dictTermsCompressTags(definition.definitions); + } + } + return {length, definitions: dictTermsSort(definitionsMerged)}; } diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 6274f3cb..d4b71932 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -35,6 +35,10 @@
+
+ +
+
diff --git a/tmpl/terms.html b/tmpl/terms.html index 72bf9824..e037c544 100644 --- a/tmpl/terms.html +++ b/tmpl/terms.html @@ -1,4 +1,11 @@ {{#*inline "definition"}} +{{#if tags}} +
+ {{#each tags}} + {{name}} + {{/each}} +
+{{/if}} {{#if only}}
( @@ -8,13 +15,6 @@ only)
{{/if}} -{{#if tags}} -
- {{#each tags}} - {{name}} - {{/each}} -
-{{/if}} {{#if glossary.[1]}}