diff options
author | siikamiika <siikamiika@users.noreply.github.com> | 2017-10-07 01:19:40 +0300 |
---|---|---|
committer | siikamiika <siikamiika@users.noreply.github.com> | 2017-10-07 01:19:40 +0300 |
commit | 981d9eddb69322494589c241d049652c9091ed06 (patch) | |
tree | 03bed3c902375969e5b2b94fb5fb2d35d298e45c /ext/bg/js/dictionary.js | |
parent | 72fe83d353f83d0559f9c53e7e18f609805d6fd6 (diff) |
merged mode: rewrite previous commit
Diffstat (limited to 'ext/bg/js/dictionary.js')
-rw-r--r-- | ext/bg/js/dictionary.js | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 41c90b1c..7d6d176c 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -170,9 +170,31 @@ function dictTermsMergeBySequence(definitions, mainDictionary) { return definitionsBySequence; } -function dictTermsMergeByGloss(result, definitions) { - const definitionsByGloss = {}; - for (const definition of definitions) { +function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) { + const definitionsByGloss = appendTo || {}; + for (const [index, definition] of definitions.entries()) { + if (appendTo) { + 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) { + mergedIndices.add(index); + } + } const gloss = JSON.stringify(definition.glossary); if (!definitionsByGloss[gloss]) { @@ -180,6 +202,7 @@ function dictTermsMergeByGloss(result, definitions) { expression: new Set(), reading: new Set(), tags: new Set(), + glossary: definition.glossary, source: result.source, reasons: [], score: definition.score, @@ -212,6 +235,21 @@ function dictTermsMergeByGloss(result, definitions) { } } + for (const gloss in definitionsByGloss) { + const definition = definitionsByGloss[gloss]; + definition.only = []; + if (!utilSetEqual(definition.expression, result.expression)) { + for (const expression of utilSetIntersection(definition.expression, result.expression)) { + definition.only.push(expression); + } + } + if (!utilSetEqual(definition.reading, result.reading)) { + for (const reading of utilSetIntersection(definition.reading, result.reading)) { + definition.only.push(reading); + } + } + } + return definitionsByGloss; } |