diff options
author | StefanVukovic99 <stefanvukovic44@gmail.com> | 2024-01-20 02:25:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-20 01:25:23 +0000 |
commit | 2b87c919bcd879c7f356308bc522b95f33e35f3b (patch) | |
tree | 1301aa8bf3d9b91ad96bbe9372a66dceba190346 /ext/js/display | |
parent | 48f1d012ad5045319d4e492dfbefa39da92817b2 (diff) |
Dictionary deinflections (#503)
* wip
* wip
* fix v3
* wip
* fix tests
* fix maxitems
* hide deinflection definitions
* fix anki template
* undo unnecessary change
* delete console.log
* refactor
* add set false to handlebars
* lint
* fix tests
* fix comments
* fix
* use Map in areArraysEqualIgnoreOrder
* move inflection source icons to css
* lint
* improve naming
* fix tests
* add test
* typescript
* use for of
* wip
* comments
* anki template upgrade
* update descriptions
Diffstat (limited to 'ext/js/display')
-rw-r--r-- | ext/js/display/display-generator.js | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js index 3a2a5621..521cbb41 100644 --- a/ext/js/display/display-generator.js +++ b/ext/js/display/display-generator.js @@ -67,13 +67,13 @@ export class DisplayGenerator { const node = this._instantiate('term-entry'); const headwordsContainer = this._querySelector(node, '.headword-list'); - const inflectionsContainer = this._querySelector(node, '.inflection-list'); + const inflectionRuleChainsContainer = this._querySelector(node, '.inflection-rule-chains'); const groupedPronunciationsContainer = this._querySelector(node, '.pronunciation-group-list'); const frequencyGroupListContainer = this._querySelector(node, '.frequency-group-list'); const definitionsContainer = this._querySelector(node, '.definition-list'); const headwordTagsContainer = this._querySelector(node, '.headword-list-tag-list'); - const {headwords, type, inflections, definitions, frequencies, pronunciations} = dictionaryEntry; + const {headwords, type, inflectionRuleChainCandidates, definitions, frequencies, pronunciations} = dictionaryEntry; const groupedPronunciations = DictionaryDataUtil.getGroupedPronunciations(dictionaryEntry); const pronunciationCount = groupedPronunciations.reduce((i, v) => i + v.pronunciations.length, 0); const groupedFrequencies = DictionaryDataUtil.groupTermFrequencies(dictionaryEntry); @@ -112,7 +112,7 @@ export class DisplayGenerator { } headwordsContainer.dataset.count = `${headwords.length}`; - this._appendMultiple(inflectionsContainer, this._createTermInflection.bind(this), inflections); + this._appendMultiple(inflectionRuleChainsContainer, this._createInflectionRuleChain.bind(this), inflectionRuleChainCandidates); this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, false); this._appendMultiple(groupedPronunciationsContainer, this._createGroupedPronunciation.bind(this), groupedPronunciations); this._appendMultiple(headwordTagsContainer, this._createTermTag.bind(this), termTags, headwords.length); @@ -357,6 +357,44 @@ export class DisplayGenerator { } /** + * @param {import('dictionary').InflectionRuleChainCandidate} inflectionRuleChain + * @returns {?HTMLElement} + */ + _createInflectionRuleChain(inflectionRuleChain) { + const {source, inflectionRules} = inflectionRuleChain; + if (!Array.isArray(inflectionRules) || inflectionRules.length === 0) { return null; } + const fragment = this._instantiate('inflection-rule-chain'); + + const sourceIcon = this._getInflectionSourceIcon(source); + + fragment.appendChild(sourceIcon); + + this._appendMultiple(fragment, this._createTermInflection.bind(this), inflectionRules); + return fragment; + } + + /** + * @param {import('dictionary').InflectionSource} source + * @returns {HTMLElement} + */ + _getInflectionSourceIcon(source) { + const icon = document.createElement('span'); + icon.classList.add('inflection-source-icon'); + icon.dataset.inflectionSource = source; + switch (source) { + case 'dictionary': + icon.title = 'Dictionary Deinflection'; + return icon; + case 'algorithm': + icon.title = 'Algorithm Deinflection'; + return icon; + case 'both': + icon.title = 'Dictionary and Algorithm Deinflection'; + return icon; + } + } + + /** * @param {string} inflection * @returns {DocumentFragment} */ @@ -396,7 +434,7 @@ export class DisplayGenerator { } /** - * @param {import('dictionary-data').TermGlossary} entry + * @param {import('dictionary-data').TermGlossaryContent} entry * @param {string} dictionary * @returns {?HTMLElement} */ |