diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-01-09 10:41:17 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-09 10:41:17 -0500 |
commit | 06d23f59d83ef89ebda89db547195ecf2a1c6ebf (patch) | |
tree | 0b0088003dbc0b27fd1aad4fa86b67d0c47f2217 /ext/mixed/js/dictionary-data-util.js | |
parent | b20622b2c84ce3ca1781c7bf8e10fed0af1e5001 (diff) |
Improve frequency display (#1209)
* Disable old frequencies
* Update layout
* Implement new frequency display
* Update count info
Diffstat (limited to 'ext/mixed/js/dictionary-data-util.js')
-rw-r--r-- | ext/mixed/js/dictionary-data-util.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/ext/mixed/js/dictionary-data-util.js b/ext/mixed/js/dictionary-data-util.js index 8d8772fe..1e82ef63 100644 --- a/ext/mixed/js/dictionary-data-util.js +++ b/ext/mixed/js/dictionary-data-util.js @@ -16,6 +16,48 @@ */ class DictionaryDataUtil { + static groupTermFrequencies(frequencies) { + const map1 = new Map(); + for (const {dictionary, expression, reading, hasReading, frequency} of frequencies) { + let map2 = map1.get(dictionary); + if (typeof map2 === 'undefined') { + map2 = new Map(); + map1.set(dictionary, map2); + } + + const readingKey = hasReading ? reading : null; + const key = JSON.stringify([expression, readingKey], null, 0); + let frequencyData = map2.get(key); + if (typeof frequencyData === 'undefined') { + frequencyData = {expression, reading: readingKey, frequencies: new Set()}; + map2.set(key, frequencyData); + } + + frequencyData.frequencies.add(frequency); + } + return this._createFrequencyGroupsFromMap(map1); + } + + static groupKanjiFrequencies(frequencies) { + const map1 = new Map(); + for (const {dictionary, character, frequency} of frequencies) { + let map2 = map1.get(dictionary); + if (typeof map2 === 'undefined') { + map2 = new Map(); + map1.set(dictionary, map2); + } + + let frequencyData = map2.get(character); + if (typeof frequencyData === 'undefined') { + frequencyData = {character, frequencies: new Set()}; + map2.set(character, frequencyData); + } + + frequencyData.frequencies.add(frequency); + } + return this._createFrequencyGroupsFromMap(map1); + } + static getPitchAccentInfos(definition) { if (definition.type === 'kanji') { return []; } @@ -73,6 +115,19 @@ class DictionaryDataUtil { // Private + static _createFrequencyGroupsFromMap(map) { + const results = []; + for (const [dictionary, map2] of map.entries()) { + const frequencyDataArray = []; + for (const frequencyData of map2.values()) { + frequencyData.frequencies = [...frequencyData.frequencies]; + frequencyDataArray.push(frequencyData); + } + results.push({dictionary, frequencyData: frequencyDataArray}); + } + return results; + } + static _findExistingPitchAccentInfo(reading, position, tags, pitchAccentInfoList) { for (const pitchInfo of pitchAccentInfoList) { if ( |