diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-01-09 16:02:03 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-09 16:02:03 -0500 |
commit | 5b58a9aeef66194bc51fe25f66aebf95f673089a (patch) | |
tree | adf2381475c6f9ad1b502e49e403a7e361184321 /ext/mixed/js/dictionary-data-util.js | |
parent | 06d23f59d83ef89ebda89db547195ecf2a1c6ebf (diff) |
Update term tags display and fix a layout issue (#1208)
* Fix layout issue with term expression display
* Update display of term tags
* Update tag notification to include disambiguation information
Diffstat (limited to 'ext/mixed/js/dictionary-data-util.js')
-rw-r--r-- | ext/mixed/js/dictionary-data-util.js | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/ext/mixed/js/dictionary-data-util.js b/ext/mixed/js/dictionary-data-util.js index 1e82ef63..70a51e89 100644 --- a/ext/mixed/js/dictionary-data-util.js +++ b/ext/mixed/js/dictionary-data-util.js @@ -16,6 +16,37 @@ */ class DictionaryDataUtil { + static groupTermTags(definition) { + const {expressions} = definition; + const expressionsLength = expressions.length; + const uniqueCheck = (expressionsLength > 1); + const resultsMap = new Map(); + const results = []; + for (let i = 0; i < expressionsLength; ++i) { + const {termTags, expression, reading} = expressions[i]; + for (const tag of termTags) { + if (uniqueCheck) { + const {name, category, notes, dictionary} = tag; + const key = this._createMapKey([name, category, notes, dictionary]); + const index = resultsMap.get(key); + if (typeof index !== 'undefined') { + const existingItem = results[index]; + existingItem.expressions.push({index: i, expression, reading}); + continue; + } + resultsMap.set(key, results.length); + } + + const item = { + tag, + expressions: [{index: i, expression, reading}] + }; + results.push(item); + } + } + return results; + } + static groupTermFrequencies(frequencies) { const map1 = new Map(); for (const {dictionary, expression, reading, hasReading, frequency} of frequencies) { @@ -26,7 +57,7 @@ class DictionaryDataUtil { } const readingKey = hasReading ? reading : null; - const key = JSON.stringify([expression, readingKey], null, 0); + const key = this._createMapKey([expression, readingKey]); let frequencyData = map2.get(key); if (typeof frequencyData === 'undefined') { frequencyData = {expression, reading: readingKey, frequencies: new Set()}; @@ -179,4 +210,8 @@ class DictionaryDataUtil { } return result; } + + static _createMapKey(array) { + return JSON.stringify(array); + } } |