aboutsummaryrefslogtreecommitdiff
path: root/ext/js/language/translator.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-07 17:55:51 -0500
committerGitHub <noreply@github.com>2021-03-07 17:55:51 -0500
commit19f6bf5a3a669cda311e5a3f162131d8a9823aef (patch)
treeb9e57be07764a782fa914a1faa877b2670d0e850 /ext/js/language/translator.js
parent7793e14e57639426cb9ca64c82004151f9eaba05 (diff)
Refactor furigana segment data (#1502)
* Remove redundant language assignment * Segment furigana from DisplayGenerator * Remove furiganaSegments from translator data * Add backwards compatibility for furiganaSegments * Update tests
Diffstat (limited to 'ext/js/language/translator.js')
-rw-r--r--ext/js/language/translator.js21
1 files changed, 7 insertions, 14 deletions
diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js
index 18668306..5aa8ee9c 100644
--- a/ext/js/language/translator.js
+++ b/ext/js/language/translator.js
@@ -1080,8 +1080,7 @@ class Translator {
this._sortTags(definitionTagsExpanded);
this._sortTags(termTagsExpanded);
- const furiganaSegments = this._japaneseUtil.distributeFurigana(expression, reading);
- const termDetailsList = [this._createTermDetails(sourceTerm, expression, reading, furiganaSegments, termTagsExpanded)];
+ const termDetailsList = [this._createTermDetails(sourceTerm, expression, reading, termTagsExpanded)];
const sourceTermExactMatchCount = (sourceTerm === expression ? 1 : 0);
return {
@@ -1100,7 +1099,6 @@ class Translator {
expression,
reading,
expressions: termDetailsList,
- furiganaSegments,
glossary,
definitionTags: definitionTagsExpanded,
termTags: termTagsExpanded,
@@ -1118,12 +1116,12 @@ class Translator {
* @returns A single 'termGrouped' definition.
*/
_createGroupedTermDefinition(definitions) {
- const {reasons, source, rawSource, sourceTerm, expressions: [{expression, reading, furiganaSegments}]} = definitions[0];
+ const {reasons, source, rawSource, sourceTerm, expressions: [{expression, reading}]} = definitions[0];
const score = this._getMaxDefinitionScore(definitions);
const dictionaryOrder = this._getBestDictionaryOrder(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, termTags)];
const sourceTermExactMatchCount = (sourceTerm === expression ? 1 : 0);
return {
type: 'termGrouped',
@@ -1141,7 +1139,6 @@ class Translator {
expression,
reading,
expressions: termDetailsList,
- furiganaSegments, // Contains duplicate data
// glossary
// definitionTags
termTags,
@@ -1173,7 +1170,6 @@ class Translator {
expression: expressions,
reading: readings,
expressions: termDetailsList,
- // furiganaSegments
// glossary
// definitionTags
// termTags
@@ -1221,7 +1217,6 @@ class Translator {
expression: [...expressions],
reading: [...readings],
expressions: termDetailsList,
- // furiganaSegments
glossary: [...glossary],
definitionTags,
// termTags
@@ -1240,7 +1235,7 @@ class Translator {
*/
_createTermDetailsList(definitions) {
const termInfoMap = new Map();
- for (const {expression, reading, sourceTerm, furiganaSegments, termTags} of definitions) {
+ for (const {expression, reading, sourceTerm, termTags} of definitions) {
let readingMap = termInfoMap.get(expression);
if (typeof readingMap === 'undefined') {
readingMap = new Map();
@@ -1251,7 +1246,6 @@ class Translator {
if (typeof termInfo === 'undefined') {
termInfo = {
sourceTerm,
- furiganaSegments,
termTagsMap: new Map()
};
readingMap.set(reading, termInfo);
@@ -1267,22 +1261,21 @@ class Translator {
const termDetailsList = [];
for (const [expression, readingMap] of termInfoMap.entries()) {
- for (const [reading, {termTagsMap, sourceTerm, furiganaSegments}] of readingMap.entries()) {
+ for (const [reading, {termTagsMap, sourceTerm}] of readingMap.entries()) {
const termTags = [...termTagsMap.values()];
this._sortTags(termTags);
- termDetailsList.push(this._createTermDetails(sourceTerm, expression, reading, furiganaSegments, termTags));
+ termDetailsList.push(this._createTermDetails(sourceTerm, expression, reading, termTags));
}
}
return termDetailsList;
}
- _createTermDetails(sourceTerm, expression, reading, furiganaSegments, termTags) {
+ _createTermDetails(sourceTerm, expression, reading, termTags) {
const termFrequency = this._scoreToTermFrequency(this._getTermTagsScoreSum(termTags));
return {
sourceTerm,
expression,
reading,
- furiganaSegments, // Contains duplicate data
termTags,
termFrequency,
frequencies: [],