summaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-11 23:20:36 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-11 23:20:36 -0400
commitceb12ac41551aca11bc195e5fad9984a28a5e291 (patch)
tree65516f7a30c7e37af5b9f81dd37c601ea04878a5 /ext/bg/js/translator.js
parent82f83970001682018f1f5b595ffdcd13123fed91 (diff)
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 e4441384..b6f8b8e5 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -469,7 +469,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':
@@ -562,6 +564,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;