From 452eec8a881f0fcbdb2d5c75ae8253b158812d10 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 12:27:18 -0500 Subject: Use Map --- ext/bg/js/settings/dictionaries.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/settings/dictionaries.js b/ext/bg/js/settings/dictionaries.js index adad76fb..427f47f0 100644 --- a/ext/bg/js/settings/dictionaries.js +++ b/ext/bg/js/settings/dictionaries.js @@ -491,15 +491,18 @@ function dictionaryErrorsShow(errors) { dialog.textContent = ''; if (errors !== null && errors.length > 0) { - const uniqueErrors = {}; + const uniqueErrors = new Map(); for (let e of errors) { console.error(e); e = dictionaryErrorToString(e); - uniqueErrors[e] = hasOwn(uniqueErrors, e) ? uniqueErrors[e] + 1 : 1; + let count = uniqueErrors.get(e); + if (typeof count === 'undefined') { + count = 0; + } + uniqueErrors.set(e, count + 1); } - for (const e in uniqueErrors) { - const count = uniqueErrors[e]; + for (const [e, count] of uniqueErrors.entries()) { const div = document.createElement('p'); if (count > 1) { div.textContent = `${e} `; -- cgit v1.2.3 From 886278b19de3693f75bb6c7775da8db86a8dd008 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 12:30:07 -0500 Subject: Use Set --- ext/bg/js/translator.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 3471cb01..b850c6e4 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -400,16 +400,12 @@ class Translator { async findKanji(text, options) { const dictionaries = dictEnabledSet(options); const titles = Object.keys(dictionaries); - const kanjiUnique = {}; - const kanjiList = []; + const kanjiUnique = new Set(); for (const c of text) { - if (!hasOwn(kanjiUnique, c)) { - kanjiList.push(c); - kanjiUnique[c] = true; - } + kanjiUnique.add(c); } - const definitions = await this.database.findKanjiBulk(kanjiList, titles); + const definitions = await this.database.findKanjiBulk([...kanjiUnique], titles); if (definitions.length === 0) { return definitions; } -- cgit v1.2.3 From 1f62dfa572f2eff2a130ef5db7b12bdc2dc7db27 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 12:31:11 -0500 Subject: Use Set --- ext/bg/js/database.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 453cf15f..db59f982 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -153,11 +153,11 @@ class Database { this._validate(); const promises = []; - const visited = {}; + const visited = new Set(); const results = []; const processRow = (row, index) => { - if (titles.includes(row.dictionary) && !hasOwn(visited, row.id)) { - visited[row.id] = true; + if (titles.includes(row.dictionary) && !visited.has(row.id)) { + visited.add(row.id); results.push(Database._createTerm(row, index)); } }; -- cgit v1.2.3 From cae8ed276799f0171aa8a5d77b908b4a751c98e9 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 12:32:45 -0500 Subject: Use Array.isArray instead of hasOwn --- ext/bg/js/audio.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/audio.js b/ext/bg/js/audio.js index 6389528b..0ecfd5c4 100644 --- a/ext/bg/js/audio.js +++ b/ext/bg/js/audio.js @@ -168,10 +168,8 @@ async function audioInject(definition, fields, sources, optionsContext) { } try { - let audioSourceDefinition = definition; - if (hasOwn(definition, 'expressions')) { - audioSourceDefinition = definition.expressions[0]; - } + const expressions = definition.expressions; + const audioSourceDefinition = Array.isArray(expressions) ? expressions[0] : definition; const {url} = await audioGetFromSources(audioSourceDefinition, sources, optionsContext, true); if (url !== null) { -- cgit v1.2.3 From bc94970a46171c2cd0f5feb272811487e2e1e110 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 12:45:18 -0500 Subject: Use Map --- ext/bg/js/dictionary.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 491632a0..afdd71a0 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -123,7 +123,7 @@ function dictTermsCompressTags(definitions) { } function dictTermsGroup(definitions, dictionaries) { - const groups = {}; + const groups = new Map(); for (const definition of definitions) { const key = [definition.source, definition.expression]; key.push(...definition.reasons); @@ -132,26 +132,27 @@ function dictTermsGroup(definitions, dictionaries) { } const keyString = key.toString(); - if (hasOwn(groups, keyString)) { - groups[keyString].push(definition); - } else { - groups[keyString] = [definition]; + let groupDefinitions = groups.get(keyString); + if (typeof groupDefinitions === 'undefined') { + groupDefinitions = []; + groups.set(keyString, groupDefinitions); } + + groupDefinitions.push(definition); } const results = []; - for (const key in groups) { - const groupDefs = groups[key]; - const firstDef = groupDefs[0]; - dictTermsSort(groupDefs, dictionaries); + for (const groupDefinitions of groups.values()) { + const firstDef = groupDefinitions[0]; + dictTermsSort(groupDefinitions, dictionaries); results.push({ - definitions: groupDefs, + definitions: groupDefinitions, expression: firstDef.expression, reading: firstDef.reading, furiganaSegments: firstDef.furiganaSegments, reasons: firstDef.reasons, termTags: firstDef.termTags, - score: groupDefs.reduce((p, v) => v.score > p ? v.score : p, Number.MIN_SAFE_INTEGER), + score: groupDefinitions.reduce((p, v) => v.score > p ? v.score : p, Number.MIN_SAFE_INTEGER), source: firstDef.source }); } -- cgit v1.2.3 From 5587116baef8e243412eb9e5ad9690284944a7a3 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 12:55:21 -0500 Subject: Simplify spread --- ext/bg/js/dictionary.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index afdd71a0..52302e9b 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -125,8 +125,7 @@ function dictTermsCompressTags(definitions) { function dictTermsGroup(definitions, dictionaries) { const groups = new Map(); for (const definition of definitions) { - const key = [definition.source, definition.expression]; - key.push(...definition.reasons); + const key = [definition.source, definition.expression, ...definition.reasons]; if (definition.reading) { key.push(definition.reading); } -- cgit v1.2.3 From a4bdffbd9def55cdc8a8a5058be39d9eea42b5e9 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 12:55:35 -0500 Subject: Use Map --- ext/bg/js/dictionary.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 52302e9b..febb27cc 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -79,20 +79,16 @@ function dictTermsSort(definitions, dictionaries=null) { } function dictTermsUndupe(definitions) { - const definitionGroups = {}; + const definitionGroups = new Map(); for (const definition of definitions) { - const definitionExisting = definitionGroups[definition.id]; - if (!hasOwn(definitionGroups, definition.id) || definition.expression.length > definitionExisting.expression.length) { - definitionGroups[definition.id] = definition; + const id = definition.id; + const definitionExisting = definitionGroups.get(id); + if (typeof definitionExisting === 'undefined' || definition.expression.length > definitionExisting.expression.length) { + definitionGroups.set(id, definition); } } - const definitionsUnique = []; - for (const key in definitionGroups) { - definitionsUnique.push(definitionGroups[key]); - } - - return definitionsUnique; + return [...definitionGroups.values()]; } function dictTermsCompressTags(definitions) { -- cgit v1.2.3 From 163211ade323f09ad9de7861e1eeab8d344bacb8 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 13:12:03 -0500 Subject: Use Map --- ext/bg/js/translator.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index b850c6e4..a864712a 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -506,28 +506,29 @@ class Translator { const names = Object.keys(items); const tagMetaList = await this.getTagMetaList(names, title); - const stats = {}; + const statsGroups = new Map(); for (let i = 0; i < names.length; ++i) { const name = names[i]; const meta = tagMetaList[i]; if (meta === null) { continue; } const category = meta.category; - const group = ( - hasOwn(stats, category) ? - stats[category] : - (stats[category] = []) - ); + let group = statsGroups.get(category); + if (typeof group === 'undefined') { + group = []; + statsGroups.set(category, group); + } const stat = Object.assign({}, meta, {name, value: items[name]}); group.push(dictTagSanitize(stat)); } + const stats = {}; const sortCompare = (a, b) => a.notes - b.notes; - for (const category in stats) { - stats[category].sort(sortCompare); + for (const [category, group] of statsGroups.entries()) { + group.sort(sortCompare); + stats[category] = group; } - return stats; } -- cgit v1.2.3 From cc2e21cd866fd02120c593f6a5ad9b5840c0edbb Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 15:01:21 -0500 Subject: Use Map for dictEnabledSet --- ext/bg/js/database.js | 24 ++++++++++++------------ ext/bg/js/dictionary.js | 27 +++++++++++++++------------ ext/bg/js/translator.js | 37 ++++++++++++++++--------------------- 3 files changed, 43 insertions(+), 45 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index db59f982..1f6810cf 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -149,14 +149,14 @@ class Database { await Promise.all(promises); } - async findTermsBulk(termList, titles, wildcard) { + async findTermsBulk(termList, dictionaries, wildcard) { this._validate(); const promises = []; const visited = new Set(); const results = []; const processRow = (row, index) => { - if (titles.includes(row.dictionary) && !visited.has(row.id)) { + if (dictionaries.has(row.dictionary) && !visited.has(row.id)) { visited.add(row.id); results.push(Database._createTerm(row, index)); } @@ -184,13 +184,13 @@ class Database { return results; } - async findTermsExactBulk(termList, readingList, titles) { + async findTermsExactBulk(termList, readingList, dictionaries) { this._validate(); const promises = []; const results = []; const processRow = (row, index) => { - if (row.reading === readingList[index] && titles.includes(row.dictionary)) { + if (row.reading === readingList[index] && dictionaries.has(row.dictionary)) { results.push(Database._createTerm(row, index)); } }; @@ -234,16 +234,16 @@ class Database { return results; } - async findTermMetaBulk(termList, titles) { - return this._findGenericBulk('termMeta', 'expression', termList, titles, Database._createTermMeta); + async findTermMetaBulk(termList, dictionaries) { + return this._findGenericBulk('termMeta', 'expression', termList, dictionaries, Database._createTermMeta); } - async findKanjiBulk(kanjiList, titles) { - return this._findGenericBulk('kanji', 'character', kanjiList, titles, Database._createKanji); + async findKanjiBulk(kanjiList, dictionaries) { + return this._findGenericBulk('kanji', 'character', kanjiList, dictionaries, Database._createKanji); } - async findKanjiMetaBulk(kanjiList, titles) { - return this._findGenericBulk('kanjiMeta', 'character', kanjiList, titles, Database._createKanjiMeta); + async findKanjiMetaBulk(kanjiList, dictionaries) { + return this._findGenericBulk('kanjiMeta', 'character', kanjiList, dictionaries, Database._createKanjiMeta); } async findTagForTitle(name, title) { @@ -572,13 +572,13 @@ class Database { return count > 0; } - async _findGenericBulk(tableName, indexName, indexValueList, titles, createResult) { + async _findGenericBulk(tableName, indexName, indexValueList, dictionaries, createResult) { this._validate(); const promises = []; const results = []; const processRow = (row, index) => { - if (titles.includes(row.dictionary)) { + if (dictionaries.has(row.dictionary)) { results.push(createResult(row, index)); } }; diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index febb27cc..d9a7a865 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -19,15 +19,17 @@ /*global utilSetEqual, utilSetIntersection, apiTemplateRender*/ function dictEnabledSet(options) { - const dictionaries = {}; - for (const title in options.dictionaries) { - const dictionary = options.dictionaries[title]; - if (dictionary.enabled) { - dictionaries[title] = dictionary; - } + const enabledDictionaryMap = new Map(); + const optionsDictionaries = options.dictionaries; + for (const title in optionsDictionaries) { + if (!hasOwn(optionsDictionaries, title)) { continue; } + const dictionary = optionsDictionaries[title]; + if (!dictionary.enabled) { continue; } + enabledDictionaryMap.set(title, { + priority: dictionary.priority || 0 + }); } - - return dictionaries; + return enabledDictionaryMap; } function dictConfigured(options) { @@ -58,10 +60,11 @@ function dictTermsSort(definitions, dictionaries=null) { return definitions.sort((v1, v2) => { let i; if (dictionaries !== null) { - i = ( - ((dictionaries[v2.dictionary] || {}).priority || 0) - - ((dictionaries[v1.dictionary] || {}).priority || 0) - ); + const dictionaryInfo1 = dictionaries.get(v1.dictionary); + const dictionaryInfo2 = dictionaries.get(v2.dictionary); + const priority1 = typeof dictionaryInfo1 !== 'undefined' ? dictionaryInfo1.priority || 0 : 0; + const priority2 = typeof dictionaryInfo2 !== 'undefined' ? dictionaryInfo2.priority || 0 : 0; + i = priority2 - priority1; if (i !== 0) { return i; } } diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index a864712a..c7017328 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -85,7 +85,7 @@ class Translator { } } - const definitions = await this.database.findTermsExactBulk(expressionList, readingList, secondarySearchTitles); + const definitions = await this.database.findTermsExactBulk(expressionList, readingList, new Set(secondarySearchTitles)); for (const definition of definitions) { const definitionTags = await this.expandTags(definition.definitionTags, definition.dictionary); definitionTags.push(dictTagBuildSource(definition.dictionary)); @@ -156,11 +156,10 @@ class Translator { async findTermsGrouped(text, details, options) { const dictionaries = dictEnabledSet(options); - const titles = Object.keys(dictionaries); const [definitions, length] = await this.findTermsInternal(text, dictionaries, details, options); const definitionsGrouped = dictTermsGroup(definitions, dictionaries); - await this.buildTermMeta(definitionsGrouped, titles); + await this.buildTermMeta(definitionsGrouped, dictionaries); if (options.general.compactTags) { for (const definition of definitionsGrouped) { @@ -174,7 +173,6 @@ class Translator { async findTermsMerged(text, details, options) { const dictionaries = dictEnabledSet(options); const secondarySearchTitles = Object.keys(options.dictionaries).filter((dict) => options.dictionaries[dict].allowSecondarySearches); - const titles = Object.keys(dictionaries); const [definitions, length] = await this.findTermsInternal(text, dictionaries, details, options); const {sequencedDefinitions, defaultDefinitions} = await this.getSequencedDefinitions(definitions, options.general.mainDictionary); const definitionsMerged = []; @@ -198,7 +196,7 @@ class Translator { definitionsMerged.push(groupedDefinition); } - await this.buildTermMeta(definitionsMerged, titles); + await this.buildTermMeta(definitionsMerged, dictionaries); if (options.general.compactTags) { for (const definition of definitionsMerged) { @@ -211,10 +209,9 @@ class Translator { async findTermsSplit(text, details, options) { const dictionaries = dictEnabledSet(options); - const titles = Object.keys(dictionaries); const [definitions, length] = await this.findTermsInternal(text, dictionaries, details, options); - await this.buildTermMeta(definitions, titles); + await this.buildTermMeta(definitions, dictionaries); return [definitions, length]; } @@ -225,11 +222,10 @@ class Translator { return [[], 0]; } - const titles = Object.keys(dictionaries); const deinflections = ( details.wildcard ? - await this.findTermWildcard(text, titles, details.wildcard) : - await this.findTermDeinflections(text, titles, options) + await this.findTermWildcard(text, dictionaries, details.wildcard) : + await this.findTermDeinflections(text, dictionaries, options) ); let definitions = []; @@ -271,8 +267,8 @@ class Translator { return [definitions, length]; } - async findTermWildcard(text, titles, wildcard) { - const definitions = await this.database.findTermsBulk([text], titles, wildcard); + async findTermWildcard(text, dictionaries, wildcard) { + const definitions = await this.database.findTermsBulk([text], dictionaries, wildcard); if (definitions.length === 0) { return []; } @@ -287,7 +283,7 @@ class Translator { }]; } - async findTermDeinflections(text, titles, options) { + async findTermDeinflections(text, dictionaries, options) { const deinflections = this.getAllDeinflections(text, options); if (deinflections.length === 0) { @@ -309,7 +305,7 @@ class Translator { deinflectionArray.push(deinflection); } - const definitions = await this.database.findTermsBulk(uniqueDeinflectionTerms, titles, null); + const definitions = await this.database.findTermsBulk(uniqueDeinflectionTerms, dictionaries, null); for (const definition of definitions) { const definitionRules = Deinflector.rulesToRuleFlags(definition.rules); @@ -399,13 +395,12 @@ class Translator { async findKanji(text, options) { const dictionaries = dictEnabledSet(options); - const titles = Object.keys(dictionaries); const kanjiUnique = new Set(); for (const c of text) { kanjiUnique.add(c); } - const definitions = await this.database.findKanjiBulk([...kanjiUnique], titles); + const definitions = await this.database.findKanjiBulk([...kanjiUnique], dictionaries); if (definitions.length === 0) { return definitions; } @@ -425,12 +420,12 @@ class Translator { definition.stats = stats; } - await this.buildKanjiMeta(definitions, titles); + await this.buildKanjiMeta(definitions, dictionaries); return definitions; } - async buildTermMeta(definitions, titles) { + async buildTermMeta(definitions, dictionaries) { const terms = []; for (const definition of definitions) { if (definition.expressions) { @@ -464,7 +459,7 @@ class Translator { term.frequencies = []; } - const metas = await this.database.findTermMetaBulk(expressionsUnique, titles); + const metas = await this.database.findTermMetaBulk(expressionsUnique, dictionaries); for (const {expression, mode, data, dictionary, index} of metas) { switch (mode) { case 'freq': @@ -476,14 +471,14 @@ class Translator { } } - async buildKanjiMeta(definitions, titles) { + async buildKanjiMeta(definitions, dictionaries) { const kanjiList = []; for (const definition of definitions) { kanjiList.push(definition.character); definition.frequencies = []; } - const metas = await this.database.findKanjiMetaBulk(kanjiList, titles); + const metas = await this.database.findKanjiMetaBulk(kanjiList, dictionaries); for (const {character, mode, data, dictionary, index} of metas) { switch (mode) { case 'freq': -- cgit v1.2.3 From 1c828d205c7cb8fd095b70ee9cd70f14ac5b044d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 15:01:44 -0500 Subject: Remove unused dictRowsSort --- ext/bg/js/dictionary.js | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index d9a7a865..afdcc6b9 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -42,20 +42,6 @@ function dictConfigured(options) { return false; } -function dictRowsSort(rows, options) { - return rows.sort((ra, rb) => { - const pa = (options.dictionaries[ra.title] || {}).priority || 0; - const pb = (options.dictionaries[rb.title] || {}).priority || 0; - if (pa > pb) { - return -1; - } else if (pa < pb) { - return 1; - } else { - return 0; - } - }); -} - function dictTermsSort(definitions, dictionaries=null) { return definitions.sort((v1, v2) => { let i; -- cgit v1.2.3 From b6718dc4a402c07680b4f1e894a632373068350d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 15:09:59 -0500 Subject: Use findTerms instead of findTermsInternal --- ext/bg/js/backend.js | 7 ++++--- ext/bg/js/translator.js | 11 +++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index a4d085e0..16dffc85 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -319,7 +319,8 @@ class Backend { async _onApiTermsFind({text, details, optionsContext}) { const options = await this.getOptions(optionsContext); - const [definitions, length] = await this.translator.findTerms(text, details, options); + const mode = options.general.resultOutputMode; + const [definitions, length] = await this.translator.findTerms(mode, text, details, options); definitions.splice(options.general.maxResults); return {length, definitions}; } @@ -329,9 +330,9 @@ class Backend { const results = []; while (text.length > 0) { const term = []; - const [definitions, sourceLength] = await this.translator.findTermsInternal( + const [definitions, sourceLength] = await this.translator.findTerms( + 'simple', text.substring(0, options.scanning.length), - dictEnabledSet(options), {}, options ); diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index c7017328..17b9e4ff 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -141,14 +141,16 @@ class Translator { return result; } - async findTerms(text, details, options) { - switch (options.general.resultOutputMode) { + async findTerms(mode, text, details, options) { + switch (mode) { case 'group': return await this.findTermsGrouped(text, details, options); case 'merge': return await this.findTermsMerged(text, details, options); case 'split': return await this.findTermsSplit(text, details, options); + case 'simple': + return await this.findTermsSimple(text, details, options); default: return [[], 0]; } @@ -216,6 +218,11 @@ class Translator { return [definitions, length]; } + async findTermsSimple(text, details, options) { + const dictionaries = dictEnabledSet(options); + return await this.findTermsInternal(text, dictionaries, details, options); + } + async findTermsInternal(text, dictionaries, details, options) { text = Translator.getSearchableText(text, options); if (text.length === 0) { -- cgit v1.2.3 From 5e8b408a2317e8280a9c0e84681d304b6c8167f1 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 15:25:22 -0500 Subject: Change secondarySearchTitles to secondarySearchDictionaries --- ext/bg/js/dictionary.js | 3 ++- ext/bg/js/translator.js | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index afdcc6b9..4a0b46cb 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -26,7 +26,8 @@ function dictEnabledSet(options) { const dictionary = optionsDictionaries[title]; if (!dictionary.enabled) { continue; } enabledDictionaryMap.set(title, { - priority: dictionary.priority || 0 + priority: dictionary.priority || 0, + allowSecondarySearches: !!dictionary.allowSecondarySearches }); } return enabledDictionaryMap; diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 17b9e4ff..0a3d535f 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -70,8 +70,8 @@ class Translator { return {sequencedDefinitions, defaultDefinitions}; } - async getMergedSecondarySearchResults(text, expressionsMap, secondarySearchTitles) { - if (secondarySearchTitles.length === 0) { + async getMergedSecondarySearchResults(text, expressionsMap, secondarySearchDictionaries) { + if (secondarySearchDictionaries.length === 0) { return []; } @@ -85,7 +85,7 @@ class Translator { } } - const definitions = await this.database.findTermsExactBulk(expressionList, readingList, new Set(secondarySearchTitles)); + const definitions = await this.database.findTermsExactBulk(expressionList, readingList, secondarySearchDictionaries); for (const definition of definitions) { const definitionTags = await this.expandTags(definition.definitionTags, definition.dictionary); definitionTags.push(dictTagBuildSource(definition.dictionary)); @@ -101,7 +101,7 @@ class Translator { return definitions; } - async getMergedDefinition(text, dictionaries, sequencedDefinition, defaultDefinitions, secondarySearchTitles, mergedByTermIndices) { + async getMergedDefinition(text, dictionaries, sequencedDefinition, defaultDefinitions, secondarySearchDictionaries, mergedByTermIndices) { const result = sequencedDefinition.definitions; const rawDefinitionsBySequence = sequencedDefinition.rawDefinitions; @@ -114,7 +114,7 @@ class Translator { } const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence); - const secondarySearchResults = await this.getMergedSecondarySearchResults(text, result.expressions, secondarySearchTitles); + const secondarySearchResults = await this.getMergedSecondarySearchResults(text, result.expressions, secondarySearchDictionaries); dictTermsMergeByGloss(result, defaultDefinitions.concat(secondarySearchResults), definitionsByGloss, mergedByTermIndices); @@ -174,7 +174,12 @@ class Translator { async findTermsMerged(text, details, options) { const dictionaries = dictEnabledSet(options); - const secondarySearchTitles = Object.keys(options.dictionaries).filter((dict) => options.dictionaries[dict].allowSecondarySearches); + const secondarySearchDictionaries = new Map(); + for (const [title, dictionary] of dictionaries.entries()) { + if (!dictionary.allowSecondarySearches) { continue; } + secondarySearchDictionaries.set(title, dictionary); + } + const [definitions, length] = await this.findTermsInternal(text, dictionaries, details, options); const {sequencedDefinitions, defaultDefinitions} = await this.getSequencedDefinitions(definitions, options.general.mainDictionary); const definitionsMerged = []; @@ -186,7 +191,7 @@ class Translator { dictionaries, sequencedDefinition, defaultDefinitions, - secondarySearchTitles, + secondarySearchDictionaries, mergedByTermIndices ); definitionsMerged.push(result); -- cgit v1.2.3 From 89af73b61b04c9bf9042aec6bad9539492a4233c Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 16:17:11 -0500 Subject: Use Map --- ext/bg/js/dictionary.js | 27 ++++++++++++++------------- ext/bg/js/translator.js | 3 +-- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 4a0b46cb..5a85bb5b 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -175,10 +175,10 @@ function dictTermsMergeBySequence(definitions, mainDictionary) { return [sequencedDefinitions, nonSequencedDefinitions]; } -function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) { - const definitionsByGloss = appendTo || {}; +function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices=null) { + const definitionsByGloss = appendTo !== null ? appendTo : new Map(); for (const [index, definition] of definitions.entries()) { - if (appendTo) { + if (appendTo !== null) { let match = false; for (const expression of result.expressions.keys()) { if (definition.expression === expression) { @@ -196,14 +196,15 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) { if (!match) { continue; - } else if (mergedIndices) { + } else if (mergedIndices !== null) { mergedIndices.add(index); } } const gloss = JSON.stringify(definition.glossary.concat(definition.dictionary)); - if (!definitionsByGloss[gloss]) { - definitionsByGloss[gloss] = { + let glossDefinition = definitionsByGloss.get(gloss); + if (typeof glossDefinition === 'undefined') { + glossDefinition = { expression: new Set(), reading: new Set(), definitionTags: [], @@ -214,21 +215,22 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) { id: definition.id, dictionary: definition.dictionary }; + definitionsByGloss.set(gloss, glossDefinition); } - definitionsByGloss[gloss].expression.add(definition.expression); - definitionsByGloss[gloss].reading.add(definition.reading); + glossDefinition.expression.add(definition.expression); + glossDefinition.reading.add(definition.reading); result.expression.add(definition.expression); result.reading.add(definition.reading); for (const tag of definition.definitionTags) { - if (!definitionsByGloss[gloss].definitionTags.find((existingTag) => existingTag.name === tag.name)) { - definitionsByGloss[gloss].definitionTags.push(tag); + if (!glossDefinition.definitionTags.find((existingTag) => existingTag.name === tag.name)) { + glossDefinition.definitionTags.push(tag); } } - if (!appendTo) { + if (appendTo === null) { // result->expressions[ Expression1[ Reading1[ Tag1, Tag2 ] ], Expression2, ... ] if (!result.expressions.has(definition.expression)) { result.expressions.set(definition.expression, new Map()); @@ -245,8 +247,7 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) { } } - for (const gloss in definitionsByGloss) { - const definition = definitionsByGloss[gloss]; + for (const definition of definitionsByGloss.values()) { definition.only = []; if (!utilSetEqual(definition.expression, result.expression)) { for (const expression of utilSetIntersection(definition.expression, result.expression)) { diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 0a3d535f..9a69e30e 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -118,8 +118,7 @@ class Translator { dictTermsMergeByGloss(result, defaultDefinitions.concat(secondarySearchResults), definitionsByGloss, mergedByTermIndices); - for (const gloss in definitionsByGloss) { - const definition = definitionsByGloss[gloss]; + for (const definition of definitionsByGloss.values()) { dictTagsSort(definition.definitionTags); result.definitions.push(definition); } -- cgit v1.2.3 From 50a171bc75f3329fec9d0aa24c4838f675a1b66d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 17:00:01 -0500 Subject: Simplify update of mergedIndices --- ext/bg/js/dictionary.js | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 5a85bb5b..532d17c7 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -178,26 +178,15 @@ function dictTermsMergeBySequence(definitions, mainDictionary) { function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices=null) { const definitionsByGloss = appendTo !== null ? appendTo : new Map(); for (const [index, definition] of definitions.entries()) { - if (appendTo !== null) { - let match = false; - for (const expression of result.expressions.keys()) { - if (definition.expression === expression) { - for (const reading of result.expressions.get(expression).keys()) { - if (definition.reading === reading) { - match = true; - break; - } - } - } - if (match) { - break; - } - } - - if (!match) { - continue; - } else if (mergedIndices !== null) { + if (mergedIndices !== null) { + const expressionMap = result.expressions.get(definition.expression); + if ( + typeof expressionMap !== 'undefined' && + typeof expressionMap.get(definition.reading) !== 'undefined' + ) { mergedIndices.add(index); + } else { + continue; } } -- cgit v1.2.3 From 45c685d00a7b98c33118dc50efd780e5be483936 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 17:05:09 -0500 Subject: Add variables for expression and reading --- ext/bg/js/dictionary.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 532d17c7..3a4a58a1 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -178,11 +178,13 @@ function dictTermsMergeBySequence(definitions, mainDictionary) { function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices=null) { const definitionsByGloss = appendTo !== null ? appendTo : new Map(); for (const [index, definition] of definitions.entries()) { + const {expression, reading} = definition; + if (mergedIndices !== null) { - const expressionMap = result.expressions.get(definition.expression); + const expressionMap = result.expressions.get(expression); if ( typeof expressionMap !== 'undefined' && - typeof expressionMap.get(definition.reading) !== 'undefined' + typeof expressionMap.get(reading) !== 'undefined' ) { mergedIndices.add(index); } else { @@ -207,11 +209,11 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices definitionsByGloss.set(gloss, glossDefinition); } - glossDefinition.expression.add(definition.expression); - glossDefinition.reading.add(definition.reading); + glossDefinition.expression.add(expression); + glossDefinition.reading.add(reading); - result.expression.add(definition.expression); - result.reading.add(definition.reading); + result.expression.add(expression); + result.reading.add(reading); for (const tag of definition.definitionTags) { if (!glossDefinition.definitionTags.find((existingTag) => existingTag.name === tag.name)) { @@ -221,16 +223,16 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices if (appendTo === null) { // result->expressions[ Expression1[ Reading1[ Tag1, Tag2 ] ], Expression2, ... ] - if (!result.expressions.has(definition.expression)) { - result.expressions.set(definition.expression, new Map()); + if (!result.expressions.has(expression)) { + result.expressions.set(expression, new Map()); } - if (!result.expressions.get(definition.expression).has(definition.reading)) { - result.expressions.get(definition.expression).set(definition.reading, []); + if (!result.expressions.get(expression).has(reading)) { + result.expressions.get(expression).set(reading, []); } for (const tag of definition.termTags) { - if (!result.expressions.get(definition.expression).get(definition.reading).find((existingTag) => existingTag.name === tag.name)) { - result.expressions.get(definition.expression).get(definition.reading).push(tag); + if (!result.expressions.get(expression).get(reading).find((existingTag) => existingTag.name === tag.name)) { + result.expressions.get(expression).get(reading).push(tag); } } } @@ -251,7 +253,7 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices } return definitionsByGloss; -} + } function dictTagBuildSource(name) { return dictTagSanitize({name, category: 'dictionary', order: 100}); -- cgit v1.2.3 From 69b5007842e08a8fda4016712a5046f81799e638 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 17:15:24 -0500 Subject: Reduce number of redundant Map.get calls in dictTermsMergeByGloss --- ext/bg/js/dictionary.js | 31 ++++++++++++++++++++++++------- ext/bg/js/translator.js | 3 ++- 2 files changed, 26 insertions(+), 8 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 3a4a58a1..786546ea 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -222,17 +222,34 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices } if (appendTo === null) { - // result->expressions[ Expression1[ Reading1[ Tag1, Tag2 ] ], Expression2, ... ] - if (!result.expressions.has(expression)) { - result.expressions.set(expression, new Map()); + /* + Data layout: + result.expressions = new Map([ + [expression, new Map([ + [reading, new Map([ + [tagName, tagInfo], + ... + ])], + ... + ])], + ... + ]); + */ + let readingMap = result.expressions.get(expression); + if (typeof readingMap === 'undefined') { + readingMap = new Map(); + result.expressions.set(expression, readingMap); } - if (!result.expressions.get(expression).has(reading)) { - result.expressions.get(expression).set(reading, []); + + let termTagsMap = readingMap.get(reading); + if (typeof termTagsMap === 'undefined') { + termTagsMap = new Map(); + readingMap.set(reading, termTagsMap); } for (const tag of definition.termTags) { - if (!result.expressions.get(expression).get(reading).find((existingTag) => existingTag.name === tag.name)) { - result.expressions.get(expression).get(reading).push(tag); + if (!termTagsMap.has(tag.name)) { + termTagsMap.set(tag.name, tag); } } } diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 9a69e30e..6cf07d93 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -127,7 +127,8 @@ class Translator { const expressions = []; for (const [expression, readingMap] of result.expressions.entries()) { - for (const [reading, termTags] of readingMap.entries()) { + for (const [reading, termTagsMap] of readingMap.entries()) { + const termTags = [...termTagsMap.values()]; const score = termTags.map((tag) => tag.score).reduce((p, v) => p + v, 0); expressions.push(Translator.createExpression(expression, reading, dictTagsSort(termTags), Translator.scoreToTermFrequency(score))); } -- cgit v1.2.3 From 19fb7dacb4c951906c5ce3094711f436b0e06c02 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 17:23:29 -0500 Subject: Assign result properties to variables to reduce number of lookups --- ext/bg/js/dictionary.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 786546ea..1bc3c93c 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -177,11 +177,17 @@ function dictTermsMergeBySequence(definitions, mainDictionary) { function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices=null) { const definitionsByGloss = appendTo !== null ? appendTo : new Map(); + + const resultExpressionsMap = result.expressions; + const resultExpressionSet = result.expression; + const resultReadingSet = result.reading; + const resultSource = result.source; + for (const [index, definition] of definitions.entries()) { const {expression, reading} = definition; if (mergedIndices !== null) { - const expressionMap = result.expressions.get(expression); + const expressionMap = resultExpressionsMap.get(expression); if ( typeof expressionMap !== 'undefined' && typeof expressionMap.get(reading) !== 'undefined' @@ -200,7 +206,7 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices reading: new Set(), definitionTags: [], glossary: definition.glossary, - source: result.source, + source: resultSource, reasons: [], score: definition.score, id: definition.id, @@ -212,8 +218,8 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices glossDefinition.expression.add(expression); glossDefinition.reading.add(reading); - result.expression.add(expression); - result.reading.add(reading); + resultExpressionSet.add(expression); + resultReadingSet.add(reading); for (const tag of definition.definitionTags) { if (!glossDefinition.definitionTags.find((existingTag) => existingTag.name === tag.name)) { @@ -235,10 +241,10 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices ... ]); */ - let readingMap = result.expressions.get(expression); + let readingMap = resultExpressionsMap.get(expression); if (typeof readingMap === 'undefined') { readingMap = new Map(); - result.expressions.set(expression, readingMap); + resultExpressionsMap.set(expression, readingMap); } let termTagsMap = readingMap.get(reading); @@ -257,13 +263,13 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices for (const definition of definitionsByGloss.values()) { definition.only = []; - if (!utilSetEqual(definition.expression, result.expression)) { - for (const expression of utilSetIntersection(definition.expression, result.expression)) { + if (!utilSetEqual(definition.expression, resultExpressionSet)) { + for (const expression of utilSetIntersection(definition.expression, resultExpressionSet)) { definition.only.push(expression); } } - if (!utilSetEqual(definition.reading, result.reading)) { - for (const reading of utilSetIntersection(definition.reading, result.reading)) { + if (!utilSetEqual(definition.reading, resultReadingSet)) { + for (const reading of utilSetIntersection(definition.reading, resultReadingSet)) { definition.only.push(reading); } } -- cgit v1.2.3 From f143632f28d3bc2f89144958ff49e9e0b1932c96 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 17:31:08 -0500 Subject: Simplify only assignment --- ext/bg/js/dictionary.js | 43 +++++++++++++++++++++++++++++++++---------- ext/bg/js/util.js | 26 -------------------------- 2 files changed, 33 insertions(+), 36 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 1bc3c93c..bffa7afa 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -/*global utilSetEqual, utilSetIntersection, apiTemplateRender*/ +/*global apiTemplateRender*/ function dictEnabledSet(options) { const enabledDictionaryMap = new Map(); @@ -145,6 +145,30 @@ function dictTermsGroup(definitions, dictionaries) { return dictTermsSort(results); } +function dictAreSetsEqual(set1, set2) { + if (set1.size !== set2.size) { + return false; + } + + for (const value of set1) { + if (!set2.has(value)) { + return false; + } + } + + return true; +} + +function dictGetSetIntersection(set1, set2) { + const result = []; + for (const value of set1) { + if (set2.has(value)) { + result.push(value); + } + } + return result; +} + function dictTermsMergeBySequence(definitions, mainDictionary) { const sequencedDefinitions = new Map(); const nonSequencedDefinitions = []; @@ -262,16 +286,15 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices } for (const definition of definitionsByGloss.values()) { - definition.only = []; - if (!utilSetEqual(definition.expression, resultExpressionSet)) { - for (const expression of utilSetIntersection(definition.expression, resultExpressionSet)) { - definition.only.push(expression); - } + const only = []; + const expressionSet = definition.expression; + const readingSet = definition.reading; + definition.only = only; + if (!dictAreSetsEqual(expressionSet, resultExpressionSet)) { + only.push(...dictGetSetIntersection(expressionSet, resultExpressionSet)); } - if (!utilSetEqual(definition.reading, resultReadingSet)) { - for (const reading of utilSetIntersection(definition.reading, resultReadingSet)) { - definition.only.push(reading); - } + if (!dictAreSetsEqual(readingSet, resultReadingSet)) { + only.push(...dictGetSetIntersection(readingSet, resultReadingSet)); } } diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 333e814b..9ebd2ac4 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -59,32 +59,6 @@ function utilBackgroundFunctionIsolate(func) { return backgroundPage.utilFunctionIsolate(func); } -function utilSetEqual(setA, setB) { - if (setA.size !== setB.size) { - return false; - } - - for (const value of setA) { - if (!setB.has(value)) { - return false; - } - } - - return true; -} - -function utilSetIntersection(setA, setB) { - return new Set( - [...setA].filter((value) => setB.has(value)) - ); -} - -function utilSetDifference(setA, setB) { - return new Set( - [...setA].filter((value) => !setB.has(value)) - ); -} - function utilStringHashCode(string) { let hashCode = 0; -- cgit v1.2.3 From 54bb702b843ae9a312704f27e282bf340e8197fc Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 22 Feb 2020 11:30:24 -0500 Subject: Updates for PR feedback --- ext/bg/js/dictionary.js | 10 +++++----- ext/bg/js/translator.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index bffa7afa..f5c5b21b 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -49,8 +49,8 @@ function dictTermsSort(definitions, dictionaries=null) { if (dictionaries !== null) { const dictionaryInfo1 = dictionaries.get(v1.dictionary); const dictionaryInfo2 = dictionaries.get(v2.dictionary); - const priority1 = typeof dictionaryInfo1 !== 'undefined' ? dictionaryInfo1.priority || 0 : 0; - const priority2 = typeof dictionaryInfo2 !== 'undefined' ? dictionaryInfo2.priority || 0 : 0; + const priority1 = typeof dictionaryInfo1 !== 'undefined' ? dictionaryInfo1.priority : 0; + const priority2 = typeof dictionaryInfo2 !== 'undefined' ? dictionaryInfo2.priority : 0; i = priority2 - priority1; if (i !== 0) { return i; } } @@ -254,7 +254,7 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices if (appendTo === null) { /* Data layout: - result.expressions = new Map([ + resultExpressionsMap = new Map([ [expression, new Map([ [reading, new Map([ [tagName, tagInfo], @@ -289,17 +289,17 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices const only = []; const expressionSet = definition.expression; const readingSet = definition.reading; - definition.only = only; if (!dictAreSetsEqual(expressionSet, resultExpressionSet)) { only.push(...dictGetSetIntersection(expressionSet, resultExpressionSet)); } if (!dictAreSetsEqual(readingSet, resultReadingSet)) { only.push(...dictGetSetIntersection(readingSet, resultReadingSet)); } + definition.only = only; } return definitionsByGloss; - } +} function dictTagBuildSource(name) { return dictTagSanitize({name, category: 'dictionary', order: 100}); diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 6cf07d93..a675a9f7 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -71,7 +71,7 @@ class Translator { } async getMergedSecondarySearchResults(text, expressionsMap, secondarySearchDictionaries) { - if (secondarySearchDictionaries.length === 0) { + if (secondarySearchDictionaries.size === 0) { return []; } -- cgit v1.2.3