aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-12-19 16:47:32 -0500
committerGitHub <noreply@github.com>2020-12-19 16:47:32 -0500
commitaf9b4d2b93ac3ffe838881c940997bb659ee30d0 (patch)
treef43755bb75e101ffec27cd728072afdb65babcf7 /ext
parentbef8612665829b5b00cc049f3466057e89b52f1b (diff)
Update termTags for termGrouped mode to include all definition tags (#1138)
* Update termTags for termGrouped mode to include all definition tags * Update tests
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/translator.js38
1 files changed, 30 insertions, 8 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 26ce1f5a..df43993f 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -909,6 +909,30 @@ class Translator {
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) {
const ii = arrayVariants.length;
@@ -970,12 +994,9 @@ class Translator {
return this._createTag(name, category, notes, order, score, dictionary, redundant);
}
- _cloneTags(tags) {
- const results = [];
- for (const tag of tags) {
- results.push(this._cloneTag(tag));
- }
- return results;
+ _getTagMapKey(tag) {
+ const {name, category, notes} = tag;
+ return this._createMapKey([name, category, notes]);
}
_createMapKey(array) {
@@ -1066,10 +1087,11 @@ class Translator {
}
_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 dictionaryPriority = this._getMaxDictionaryPriority(definitions);
const dictionaryNames = this._getUniqueDictionaryNames(definitions);
+ const termTags = this._getUniqueTermTags(definitions);
const termDetailsList = [this._createTermDetails(sourceTerm, expression, reading, furiganaSegments, termTags)];
const sourceTermExactMatchCount = (sourceTerm === expression ? 1 : 0);
return {
@@ -1090,7 +1112,7 @@ class Translator {
furiganaSegments, // Contains duplicate data
// glossary
// definitionTags
- termTags: this._cloneTags(termTags),
+ termTags,
definitions, // type: 'term'
frequencies: [],
pitches: [],