diff options
author | siikamiika <siikamiika@users.noreply.github.com> | 2017-10-05 06:56:45 +0300 |
---|---|---|
committer | siikamiika <siikamiika@users.noreply.github.com> | 2017-10-05 06:56:45 +0300 |
commit | 72fe83d353f83d0559f9c53e7e18f609805d6fd6 (patch) | |
tree | 591f92a8957da39e48b27d9eb3f2959aef901e88 /ext | |
parent | cfad3b309976213c45f99bef3b8fad072c6bb9ec (diff) |
merged mode: merge other results with main dict
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bg/js/dictionary.js | 2 | ||||
-rw-r--r-- | ext/bg/js/translator.js | 39 |
2 files changed, 37 insertions, 4 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index c20df400..41c90b1c 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -89,7 +89,7 @@ function dictTermsSort(definitions, dictionaries=null) { return 1; } - return v2.expression.localeCompare(v1.expression); + return v2.expression.toString().localeCompare(v1.expression.toString()); }); } diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 3442124f..f50c5725 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -55,7 +55,8 @@ class Translator { const definitionsBySequence = dictTermsMergeBySequence(definitions, options.dictionary.main); - const definitionsMerged = dictTermsGroup(definitionsBySequence['-1'], dictionaries); + // const definitionsMerged = dictTermsGroup(definitionsBySequence['-1'], dictionaries); + const definitionsMerged = []; for (const sequence in definitionsBySequence) { if (!(sequence > 0)) { continue; @@ -114,11 +115,43 @@ class Translator { result.expressions = expressions; - result.expression = Array.from(result.expression).join(', '); - result.reading = Array.from(result.reading).join(', '); + // result.expression = Array.from(result.expression).join(', '); + // result.reading = Array.from(result.reading).join(', '); definitionsMerged.push(result); } + const postMergedIndices = new Set(); + const mergeeIndicesByGloss = {}; + for (const [i, definition] of definitionsBySequence['-1'].entries()) { + for (const [j, mergedDefinition] of definitionsMerged.entries()) { + if (mergedDefinition.expression.has(definition.expression)) { + if (mergedDefinition.reading.has(definition.reading) || (definition.reading === '' && mergedDefinition.reading.size === 0)) { + if (!mergeeIndicesByGloss[definition.glossary]) { + mergeeIndicesByGloss[definition.glossary] = new Set(); + } + if (mergeeIndicesByGloss[definition.glossary].has(j)) { + continue; + } + mergedDefinition.definitions.push(definition); + mergeeIndicesByGloss[definition.glossary].add(j); + postMergedIndices.add(i); + } + } + } + } + + const strayDefinitions = []; + for (const [i, definition] of definitionsBySequence['-1'].entries()) { + if (postMergedIndices.has(i)) { + continue; + } + strayDefinitions.push(definition); + } + + for (const groupedDefinition of dictTermsGroup(strayDefinitions, dictionaries)) { + definitionsMerged.push(groupedDefinition); + } + for (const definition of definitionsMerged) { await this.buildTermFrequencies(definition, titles); } |