From 643dbfb12a66b98b2fabe82416322f0218474567 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 7 Mar 2021 20:38:40 -0500 Subject: Refactor term frequency data (#1503) * Add getTermFrequency * Update DisplayGenerator to use getTermFrequency * Remove termFrequency from Translator data * Backwards compatibility * Update tests --- ext/js/language/dictionary-data-util.js | 14 ++++++++++++++ ext/js/language/translator.js | 2 -- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'ext/js/language') diff --git a/ext/js/language/dictionary-data-util.js b/ext/js/language/dictionary-data-util.js index b3a354a7..dff9d212 100644 --- a/ext/js/language/dictionary-data-util.js +++ b/ext/js/language/dictionary-data-util.js @@ -143,6 +143,20 @@ class DictionaryDataUtil { return results2; } + static getTermFrequency(termTags) { + let totalScore = 0; + for (const {score} of termTags) { + totalScore += score; + } + if (totalScore > 0) { + return 'popular'; + } else if (totalScore < 0) { + return 'rare'; + } else { + return 'normal'; + } + } + // Private static _createFrequencyGroupsFromMap(map) { diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js index 5aa8ee9c..e8aba5b1 100644 --- a/ext/js/language/translator.js +++ b/ext/js/language/translator.js @@ -1271,13 +1271,11 @@ class Translator { } _createTermDetails(sourceTerm, expression, reading, termTags) { - const termFrequency = this._scoreToTermFrequency(this._getTermTagsScoreSum(termTags)); return { sourceTerm, expression, reading, termTags, - termFrequency, frequencies: [], pitches: [] }; -- cgit v1.2.3