Merge pull request #97 from siikamiika/dev

merged mode: expand termTags earlier
This commit is contained in:
Alex Yatskov 2017-11-09 14:39:54 -08:00 committed by GitHub
commit a17e84de83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 19 deletions

View File

@ -245,22 +245,26 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) {
result.expression.add(definition.expression); result.expression.add(definition.expression);
result.reading.add(definition.reading); result.reading.add(definition.reading);
// result->expressions[ Expression1[ Reading1[ Tag1, Tag2 ] ], Expression2, ... ]
if (!result.expressions.has(definition.expression)) {
result.expressions.set(definition.expression, new Map());
}
if (!result.expressions.get(definition.expression).has(definition.reading)) {
result.expressions.get(definition.expression).set(definition.reading, new Set());
}
for (const tag of definition.definitionTags) { for (const tag of definition.definitionTags) {
if (!definitionsByGloss[gloss].definitionTags.find(existingTag => existingTag.name === tag.name)) { if (!definitionsByGloss[gloss].definitionTags.find(existingTag => existingTag.name === tag.name)) {
definitionsByGloss[gloss].definitionTags.push(tag); definitionsByGloss[gloss].definitionTags.push(tag);
} }
} }
for (const tag of definition.termTags) { if (!appendTo) {
result.expressions.get(definition.expression).get(definition.reading).add(tag); // result->expressions[ Expression1[ Reading1[ Tag1, Tag2 ] ], Expression2, ... ]
if (!result.expressions.has(definition.expression)) {
result.expressions.set(definition.expression, new Map());
}
if (!result.expressions.get(definition.expression).has(definition.reading)) {
result.expressions.get(definition.expression).set(definition.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);
}
}
} }
} }

View File

@ -75,9 +75,11 @@ class Translator {
const rawDefinitionsBySequence = await this.database.findTermsBySequence(Number(sequence), options.general.mainDictionary); const rawDefinitionsBySequence = await this.database.findTermsBySequence(Number(sequence), options.general.mainDictionary);
for (const definition of rawDefinitionsBySequence) { for (const definition of rawDefinitionsBySequence) {
const tags = await this.expandTags(definition.definitionTags, definition.dictionary); const definitionTags = await this.expandTags(definition.definitionTags, definition.dictionary);
tags.push(dictTagBuildSource(definition.dictionary)); definitionTags.push(dictTagBuildSource(definition.dictionary));
definition.definitionTags = tags; definition.definitionTags = definitionTags;
const termTags = await this.expandTags(definition.termTags, definition.dictionary);
definition.termTags = termTags;
} }
const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence); const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence);
@ -91,9 +93,11 @@ class Translator {
for (const reading of result.expressions.get(expression).keys()) { for (const reading of result.expressions.get(expression).keys()) {
for (const definition of await this.database.findTermsExact(expression, reading, secondarySearchTitles)) { for (const definition of await this.database.findTermsExact(expression, reading, secondarySearchTitles)) {
const tags = await this.expandTags(definition.definitionTags, definition.dictionary); const definitionTags = await this.expandTags(definition.definitionTags, definition.dictionary);
tags.push(dictTagBuildSource(definition.dictionary)); definitionTags.push(dictTagBuildSource(definition.dictionary));
definition.definitionTags = tags; definition.definitionTags = definitionTags;
const termTags = await this.expandTags(definition.termTags, definition.dictionary);
definition.termTags = termTags;
secondarySearchResults.push(definition); secondarySearchResults.push(definition);
} }
} }
@ -113,11 +117,11 @@ class Translator {
const expressions = []; const expressions = [];
for (const expression of result.expressions.keys()) { for (const expression of result.expressions.keys()) {
for (const reading of result.expressions.get(expression).keys()) { for (const reading of result.expressions.get(expression).keys()) {
const tags = await this.expandTags(result.expressions.get(expression).get(reading), result.dictionary); const termTags = result.expressions.get(expression).get(reading);
expressions.push({ expressions.push({
expression: expression, expression: expression,
reading: reading, reading: reading,
termTags: dictTagsSort(tags), termTags: dictTagsSort(termTags),
termFrequency: (score => { termFrequency: (score => {
if (score > 0) { if (score > 0) {
return 'popular'; return 'popular';
@ -126,7 +130,7 @@ class Translator {
} else { } else {
return 'normal'; return 'normal';
} }
})(tags.map(tag => tag.score).reduce((p, v) => p + v, 0)) })(termTags.map(tag => tag.score).reduce((p, v) => p + v, 0))
}); });
} }
} }