summaryrefslogtreecommitdiff
path: root/ext/js/language/sandbox/dictionary-data-util.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-10-14 21:26:53 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-10-14 21:31:03 -0400
commit858fe7ae11850eaafb3e024289faf0c78e083abf (patch)
tree701390a05b3163199c06d7cf2482d13c6f61b1a2 /ext/js/language/sandbox/dictionary-data-util.js
parentf6c346136297c10389897b183db4f05c07d204fa (diff)
String frequency support (#1989)
* Restore support for string frequency values * Add support for {value, displayValue} frequencies * Update test data * Improve number parsing of string frequencies * Improve reading detection * Expose a displayValue property for frequency information * Update docs * Expose displayValue to Anki note data * Fix translator * Update display generation * Update test data * Update counts
Diffstat (limited to 'ext/js/language/sandbox/dictionary-data-util.js')
-rw-r--r--ext/js/language/sandbox/dictionary-data-util.js14
1 files changed, 7 insertions, 7 deletions
diff --git a/ext/js/language/sandbox/dictionary-data-util.js b/ext/js/language/sandbox/dictionary-data-util.js
index 68b15c48..83d94b9b 100644
--- a/ext/js/language/sandbox/dictionary-data-util.js
+++ b/ext/js/language/sandbox/dictionary-data-util.js
@@ -48,7 +48,7 @@ class DictionaryDataUtil {
const {headwords, frequencies} = dictionaryEntry;
const map1 = new Map();
- for (const {headwordIndex, dictionary, hasReading, frequency} of frequencies) {
+ for (const {headwordIndex, dictionary, hasReading, frequency, displayValue} of frequencies) {
const {term, reading} = headwords[headwordIndex];
let map2 = map1.get(dictionary);
@@ -61,18 +61,18 @@ class DictionaryDataUtil {
const key = this._createMapKey([term, readingKey]);
let frequencyData = map2.get(key);
if (typeof frequencyData === 'undefined') {
- frequencyData = {term, reading: readingKey, values: new Set()};
+ frequencyData = {term, reading: readingKey, values: new Map()};
map2.set(key, frequencyData);
}
- frequencyData.values.add(frequency);
+ frequencyData.values.set(this._createMapKey([frequency, displayValue]), {frequency, displayValue});
}
return this._createFrequencyGroupsFromMap(map1);
}
static groupKanjiFrequencies(frequencies) {
const map1 = new Map();
- for (const {dictionary, character, frequency} of frequencies) {
+ for (const {dictionary, character, frequency, displayValue} of frequencies) {
let map2 = map1.get(dictionary);
if (typeof map2 === 'undefined') {
map2 = new Map();
@@ -81,11 +81,11 @@ class DictionaryDataUtil {
let frequencyData = map2.get(character);
if (typeof frequencyData === 'undefined') {
- frequencyData = {character, values: new Set()};
+ frequencyData = {character, values: new Map()};
map2.set(character, frequencyData);
}
- frequencyData.values.add(frequency);
+ frequencyData.values.set(this._createMapKey([frequency, displayValue]), {frequency, displayValue});
}
return this._createFrequencyGroupsFromMap(map1);
}
@@ -222,7 +222,7 @@ class DictionaryDataUtil {
for (const [dictionary, map2] of map.entries()) {
const frequencies = [];
for (const frequencyData of map2.values()) {
- frequencyData.values = [...frequencyData.values];
+ frequencyData.values = [...frequencyData.values.values()];
frequencies.push(frequencyData);
}
results.push({dictionary, frequencies});