Update termTags for termGrouped mode to include all definition tags (#1138)

* Update termTags for termGrouped mode to include all definition tags

* Update tests
This commit is contained in:
toasted-nutbread 2020-12-19 16:47:32 -05:00 committed by GitHub
parent bef8612665
commit af9b4d2b93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 8 deletions

View File

@ -909,6 +909,30 @@ class Translator {
return [...uniqueDictionaryNames]; return [...uniqueDictionaryNames];
} }
_getUniqueTermTags(definitions) {
const newTermTags = [];
if (definitions.length <= 1) {
for (const {termTags} of definitions) {
for (const tag of termTags) {
newTermTags.push(this._cloneTag(tag));
}
}
} else {
const tagsSet = new Set();
let checkTagsMap = false;
for (const {termTags} of definitions) {
for (const tag of termTags) {
const key = this._getTagMapKey(tag);
if (checkTagsMap && tagsSet.has(key)) { continue; }
tagsSet.add(key);
newTermTags.push(this._cloneTag(tag));
}
checkTagsMap = true;
}
}
return newTermTags;
}
*_getArrayVariants(arrayVariants) { *_getArrayVariants(arrayVariants) {
const ii = arrayVariants.length; const ii = arrayVariants.length;
@ -970,12 +994,9 @@ class Translator {
return this._createTag(name, category, notes, order, score, dictionary, redundant); return this._createTag(name, category, notes, order, score, dictionary, redundant);
} }
_cloneTags(tags) { _getTagMapKey(tag) {
const results = []; const {name, category, notes} = tag;
for (const tag of tags) { return this._createMapKey([name, category, notes]);
results.push(this._cloneTag(tag));
}
return results;
} }
_createMapKey(array) { _createMapKey(array) {
@ -1066,10 +1087,11 @@ class Translator {
} }
_createGroupedTermDefinition(definitions) { _createGroupedTermDefinition(definitions) {
const {expression, reading, furiganaSegments, reasons, termTags, source, rawSource, sourceTerm} = definitions[0]; const {expression, reading, furiganaSegments, reasons, source, rawSource, sourceTerm} = definitions[0];
const score = this._getMaxDefinitionScore(definitions); const score = this._getMaxDefinitionScore(definitions);
const dictionaryPriority = this._getMaxDictionaryPriority(definitions); const dictionaryPriority = this._getMaxDictionaryPriority(definitions);
const dictionaryNames = this._getUniqueDictionaryNames(definitions); const dictionaryNames = this._getUniqueDictionaryNames(definitions);
const termTags = this._getUniqueTermTags(definitions);
const termDetailsList = [this._createTermDetails(sourceTerm, expression, reading, furiganaSegments, termTags)]; const termDetailsList = [this._createTermDetails(sourceTerm, expression, reading, furiganaSegments, termTags)];
const sourceTermExactMatchCount = (sourceTerm === expression ? 1 : 0); const sourceTermExactMatchCount = (sourceTerm === expression ? 1 : 0);
return { return {
@ -1090,7 +1112,7 @@ class Translator {
furiganaSegments, // Contains duplicate data furiganaSegments, // Contains duplicate data
// glossary // glossary
// definitionTags // definitionTags
termTags: this._cloneTags(termTags), termTags,
definitions, // type: 'term' definitions, // type: 'term'
frequencies: [], frequencies: [],
pitches: [], pitches: [],

View File

@ -7957,6 +7957,24 @@
"score": 0, "score": 0,
"dictionary": "Test Dictionary 2", "dictionary": "Test Dictionary 2",
"redundant": false "redundant": false
},
{
"name": "tag6",
"category": "default",
"notes": "",
"order": 0,
"score": 0,
"dictionary": "Test Dictionary 2",
"redundant": false
},
{
"name": "tag7",
"category": "default",
"notes": "",
"order": 0,
"score": 0,
"dictionary": "Test Dictionary 2",
"redundant": false
} }
], ],
"termFrequency": "normal", "termFrequency": "normal",
@ -8038,6 +8056,24 @@
"score": 0, "score": 0,
"dictionary": "Test Dictionary 2", "dictionary": "Test Dictionary 2",
"redundant": false "redundant": false
},
{
"name": "tag6",
"category": "default",
"notes": "",
"order": 0,
"score": 0,
"dictionary": "Test Dictionary 2",
"redundant": false
},
{
"name": "tag7",
"category": "default",
"notes": "",
"order": 0,
"score": 0,
"dictionary": "Test Dictionary 2",
"redundant": false
} }
], ],
"definitions": [ "definitions": [