diff options
-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); } |