summaryrefslogtreecommitdiff
path: root/ext/js/language/translator.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-06-05 22:27:58 -0400
committerGitHub <noreply@github.com>2021-06-05 22:27:58 -0400
commitd87515ec125189ceeae251d37013b511c7bf8baf (patch)
tree2c52130b8ced8efbd371cc2e9f5e5f0678242d76 /ext/js/language/translator.js
parent057283245e2a2ce55f89cacb42067b8c93dd28cd (diff)
Translator id updates (#1730)
* Allow unsequenced definitions to be added to multiple groups * Update translator data to store multiple IDs * Update Anki note data * Update test data * Update docs
Diffstat (limited to 'ext/js/language/translator.js')
-rw-r--r--ext/js/language/translator.js18
1 files changed, 9 insertions, 9 deletions
diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js
index bf2c7322..a36ef48c 100644
--- a/ext/js/language/translator.js
+++ b/ext/js/language/translator.js
@@ -358,7 +358,7 @@ class Translator {
const groupedDictionaryEntriesMap = new Map();
const ungroupedDictionaryEntriesMap = new Map();
for (const dictionaryEntry of dictionaryEntries) {
- const {id, definitions: [{dictionary, sequences: [sequence]}]} = dictionaryEntry;
+ const {ids: [id], definitions: [{dictionary, sequences: [sequence]}]} = dictionaryEntry;
if (mainDictionary === dictionary && sequence >= 0) {
let group = groupedDictionaryEntriesMap.get(sequence);
if (typeof group === 'undefined') {
@@ -448,12 +448,10 @@ class Translator {
for (const {ids, dictionaryEntries} of target.groups) {
if (ids.has(id)) { continue; }
-
dictionaryEntries.push(dictionaryEntry);
ids.add(id);
- ungroupedDictionaryEntriesMap.delete(id);
- break;
}
+ ungroupedDictionaryEntriesMap.delete(id);
}
// Search database for additional secondary terms
@@ -1039,10 +1037,10 @@ class Translator {
return {index, headwordIndex, dictionary, dictionaryIndex, dictionaryPriority, hasReading, frequency};
}
- _createTermDictionaryEntry(id, isPrimary, inflections, score, dictionaryIndex, dictionaryPriority, sourceTermExactMatchCount, maxTransformedTextLength, headwords, definitions) {
+ _createTermDictionaryEntry(ids, isPrimary, inflections, score, dictionaryIndex, dictionaryPriority, sourceTermExactMatchCount, maxTransformedTextLength, headwords, definitions) {
return {
type: 'term',
- id,
+ ids,
isPrimary,
inflections,
score,
@@ -1073,7 +1071,7 @@ class Translator {
if (definitionTags.length > 0) { definitionTagGroups.push(this._createTagGroup(dictionary, definitionTags)); }
return this._createTermDictionaryEntry(
- id,
+ [id],
isPrimary,
reasons,
score,
@@ -1111,6 +1109,7 @@ class Translator {
const definitions = [];
const definitionsMap = checkDuplicateDefinitions ? new Map() : null;
let inflections = null;
+ const ids = new Set();
for (const {dictionaryEntry, headwordIndexMap} of definitionEntries) {
score = Math.max(score, dictionaryEntry.score);
@@ -1124,6 +1123,7 @@ class Translator {
inflections = dictionaryEntryInflections;
}
}
+ for (const id of dictionaryEntry.ids) { ids.add(id); }
if (checkDuplicateDefinitions) {
this._addTermDefinitions(definitions, definitionsMap, dictionaryEntry.definitions, headwordIndexMap);
} else {
@@ -1144,7 +1144,7 @@ class Translator {
}
return this._createTermDictionaryEntry(
- -1,
+ [...ids],
isPrimary,
inflections !== null ? inflections : [],
score,
@@ -1380,7 +1380,7 @@ class Translator {
_sortTermDictionaryEntriesById(dictionaryEntries) {
if (dictionaryEntries.length <= 1) { return; }
- dictionaryEntries.sort((a, b) => a.id - b.id);
+ dictionaryEntries.sort((a, b) => a.ids[0] - b.ids[0]);
}
_sortTermDictionaryEntryData(dictionaryEntries) {