summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/js/data/anki-note-data.js14
-rw-r--r--ext/js/display/display-generator.js4
-rw-r--r--ext/js/language/dictionary-data-util.js14
-rw-r--r--ext/js/language/translator.js2
4 files changed, 30 insertions, 4 deletions
diff --git a/ext/js/data/anki-note-data.js b/ext/js/data/anki-note-data.js
index 529bad18..a8a82a79 100644
--- a/ext/js/data/anki-note-data.js
+++ b/ext/js/data/anki-note-data.js
@@ -245,6 +245,7 @@ class AnkiNoteData {
}
for (const expression of definition2.expressions) {
this._defineFuriganaSegments(expression);
+ this._defineTermFrequency(expression);
}
}
}
@@ -257,6 +258,14 @@ class AnkiNoteData {
});
}
+ _defineTermFrequency(object) {
+ Object.defineProperty(object, 'termFrequency', {
+ configurable: true,
+ enumerable: true,
+ get: this._getTermFrequency.bind(this, object)
+ });
+ }
+
_getFuriganaSegments(object) {
if (this._furiganaSegmentsCache !== null) {
const cachedResult = this._furiganaSegmentsCache.get(object);
@@ -271,6 +280,11 @@ class AnkiNoteData {
return result;
}
+ _getTermFrequency(object) {
+ const {termTags} = object;
+ return DictionaryDataUtil.getTermFrequency(termTags);
+ }
+
_getAllDefinitions(definition) {
const definitions = [definition];
for (let i = 0; i < definitions.length; ++i) {
diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js
index c0945781..3977815b 100644
--- a/ext/js/display/display-generator.js
+++ b/ext/js/display/display-generator.js
@@ -230,7 +230,7 @@ class DisplayGenerator {
// Private
_createTermExpression(details) {
- const {termFrequency, expression, reading, termTags, pitches} = details;
+ const {expression, reading, termTags, pitches} = details;
const searchQueries = [];
if (expression) { searchQueries.push(expression); }
@@ -242,7 +242,7 @@ class DisplayGenerator {
const tagContainer = node.querySelector('.expression-tag-list');
node.dataset.readingIsSame = `${reading === expression}`;
- node.dataset.frequency = termFrequency;
+ node.dataset.frequency = DictionaryDataUtil.getTermFrequency(termTags);
const pitchAccentCategories = this._getPitchAccentCategories(pitches);
if (pitchAccentCategories !== null) {
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: []
};