aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-12-30 15:12:08 -0500
committerGitHub <noreply@github.com>2020-12-30 15:12:08 -0500
commit4650f0b5426c07e1aca3bec2a07607556a1e1f34 (patch)
treefa940311c4f4cdd15e274eac7a44f21722cb7589 /ext/bg/js/translator.js
parent0f3b9ec7fc2b1c7ba1780d7186dc425c3975c099 (diff)
Translator frequency data improvements (#1184)
* Specify if a frequency has a specific reading * Make frequency data creation more standardized * Update test data
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r--ext/bg/js/translator.js18
1 files changed, 13 insertions, 5 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index df43993f..27870cf5 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -706,7 +706,7 @@ class Translator {
switch (mode) {
case 'freq':
{
- const frequencyData = this._getFrequencyData(expression, reading, dictionary, data);
+ const frequencyData = this._getTermFrequencyData(expression, reading, dictionary, data);
if (frequencyData === null) { continue; }
for (const {frequencies} of targets) { frequencies.push(frequencyData); }
}
@@ -733,7 +733,10 @@ class Translator {
for (const {character, mode, data, dictionary, index} of metas) {
switch (mode) {
case 'freq':
- definitions[index].frequencies.push({character, frequency: data, dictionary});
+ {
+ const frequencyData = this._getKanjiFrequencyData(character, dictionary, data);
+ definitions[index].frequencies.push(frequencyData);
+ }
break;
}
}
@@ -805,13 +808,18 @@ class Translator {
return tagMetaList;
}
- _getFrequencyData(expression, reading, dictionary, data) {
+ _getTermFrequencyData(expression, reading, dictionary, data) {
let frequency = data;
- if (data !== null && typeof data === 'object') {
+ const hasReading = (data !== null && typeof data === 'object');
+ if (hasReading) {
if (data.reading !== reading) { return null; }
frequency = data.frequency;
}
- return {expression, reading, dictionary, frequency};
+ return {dictionary, expression, reading, hasReading, frequency};
+ }
+
+ _getKanjiFrequencyData(character, dictionary, data) {
+ return {dictionary, character, frequency: data};
}
async _getPitchData(expression, reading, dictionary, data) {