expand tags before dictTermsMergeByGloss
This commit is contained in:
parent
78442fff1a
commit
27a56dc236
@ -229,7 +229,7 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) {
|
|||||||
definitionsByGloss[gloss] = {
|
definitionsByGloss[gloss] = {
|
||||||
expression: new Set(),
|
expression: new Set(),
|
||||||
reading: new Set(),
|
reading: new Set(),
|
||||||
definitionTags: new Set(),
|
definitionTags: [],
|
||||||
glossary: definition.glossary,
|
glossary: definition.glossary,
|
||||||
source: result.source,
|
source: result.source,
|
||||||
reasons: [],
|
reasons: [],
|
||||||
@ -254,10 +254,8 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const tag of definition.definitionTags) {
|
for (const tag of definition.definitionTags) {
|
||||||
if (typeof tag === 'string') {
|
if (!definitionsByGloss[gloss].definitionTags.find(existingTag => existingTag.name === tag.name)) {
|
||||||
definitionsByGloss[gloss].definitionTags.add(tag);
|
definitionsByGloss[gloss].definitionTags.push(tag);
|
||||||
} else if (tag.category && tag.category !== 'dictionary') {
|
|
||||||
definitionsByGloss[gloss].definitionTags.add(tag.name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +73,13 @@ class Translator {
|
|||||||
const result = definitionsBySequence[sequence];
|
const result = definitionsBySequence[sequence];
|
||||||
|
|
||||||
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) {
|
||||||
|
const tags = await this.expandTags(definition.definitionTags, definition.dictionary);
|
||||||
|
tags.push(dictTagBuildSource(definition.dictionary));
|
||||||
|
definition.definitionTags = tags;
|
||||||
|
}
|
||||||
|
|
||||||
const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence);
|
const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence);
|
||||||
|
|
||||||
const secondarySearchResults = [];
|
const secondarySearchResults = [];
|
||||||
@ -84,6 +91,9 @@ 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);
|
||||||
|
tags.push(dictTagBuildSource(definition.dictionary));
|
||||||
|
definition.definitionTags = tags;
|
||||||
secondarySearchResults.push(definition);
|
secondarySearchResults.push(definition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,11 +104,7 @@ class Translator {
|
|||||||
|
|
||||||
for (const gloss in definitionsByGloss) {
|
for (const gloss in definitionsByGloss) {
|
||||||
const definition = definitionsByGloss[gloss];
|
const definition = definitionsByGloss[gloss];
|
||||||
|
dictTagsSort(definition.definitionTags);
|
||||||
const tags = await this.expandTags(definition.definitionTags, definition.dictionary);
|
|
||||||
tags.push(dictTagBuildSource(definition.dictionary));
|
|
||||||
definition.definitionTags = dictTagsSort(tags);
|
|
||||||
|
|
||||||
result.definitions.push(definition);
|
result.definitions.push(definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,9 +295,6 @@ class Translator {
|
|||||||
async expandTags(names, title) {
|
async expandTags(names, title) {
|
||||||
const tags = [];
|
const tags = [];
|
||||||
for (const name of names) {
|
for (const name of names) {
|
||||||
if (typeof name !== 'string') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const base = name.split(':')[0];
|
const base = name.split(':')[0];
|
||||||
const meta = await this.database.findTagForTitle(base, title);
|
const meta = await this.database.findTagForTitle(base, title);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user