aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-18 14:14:30 -0400
committerGitHub <noreply@github.com>2020-04-18 14:14:30 -0400
commit9297eb45aef3bad50fe9cf5e453aa97288609601 (patch)
tree85c916841e1b4409f83b12376fafd5a31d5e6e4d /ext/bg/js/translator.js
parent106172e2c1261f2d685802280af580c70ac4580b (diff)
parentceb12ac41551aca11bc195e5fad9984a28a5e291 (diff)
Merge pull request #450 from toasted-nutbread/frequency-readings
Add support for filtering frequency metadata based on readings
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r--ext/bg/js/translator.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index aaa1a0ec..8708e4d8 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -482,7 +482,9 @@ class Translator {
switch (mode) {
case 'freq':
for (const term of termsUnique[index]) {
- term.frequencies.push({expression, frequency: data, dictionary});
+ const frequencyData = this.getFrequencyData(expression, data, dictionary, term);
+ if (frequencyData === null) { continue; }
+ term.frequencies.push(frequencyData);
}
break;
case 'pitch':
@@ -575,6 +577,18 @@ class Translator {
return tagMetaList;
}
+ getFrequencyData(expression, data, dictionary, term) {
+ if (data !== null && typeof data === 'object') {
+ const {frequency, reading} = data;
+
+ const termReading = term.reading || expression;
+ if (reading !== termReading) { return null; }
+
+ return {expression, frequency, dictionary};
+ }
+ return {expression, frequency: data, dictionary};
+ }
+
async getPitchData(expression, data, dictionary, term) {
const reading = data.reading;
const termReading = term.reading || expression;