merged mode: merge other results with main dict

This commit is contained in:
siikamiika 2017-10-05 06:56:45 +03:00
parent cfad3b3099
commit 72fe83d353
2 changed files with 37 additions and 4 deletions

View File

@ -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());
});
}

View File

@ -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);
}