Remove the dictionary tag from the definitionTags (#1324)

* Remove dictionary tag from term definitionTags and kanji tags

* Update test data

* Update templates

* Update tests

* Update information
This commit is contained in:
toasted-nutbread 2021-01-28 21:33:30 -05:00 committed by GitHub
parent e610a62ceb
commit a81787c55b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 92 additions and 980 deletions

View File

@ -169,6 +169,7 @@ Flashcard fields can be configured with the following steps:
`{furigana-plain}` | Term expressed as kanji with furigana displayed next to it in brackets (e.g. 日本語[にほんご]). `{furigana-plain}` | Term expressed as kanji with furigana displayed next to it in brackets (e.g. 日本語[にほんご]).
`{glossary}` | List of definitions for the term (output format depends on whether running in *grouped* mode). `{glossary}` | List of definitions for the term (output format depends on whether running in *grouped* mode).
`{glossary-brief}` | List of definitions for the term in a more compact format. `{glossary-brief}` | List of definitions for the term in a more compact format.
`{glossary-no-dictionary}` | List of definitions for the term, except the dictionary tag is omitted.
`{pitch-accents}` | List of pitch accent downstep notations for the term. `{pitch-accents}` | List of pitch accent downstep notations for the term.
`{pitch-accent-graphs}` | List of pitch accent graphs for the term. `{pitch-accent-graphs}` | List of pitch accent graphs for the term.
`{pitch-accent-positions}` | List of accent downstep positions for the term as a number. `{pitch-accent-positions}` | List of accent downstep positions for the term as a number.

View File

@ -52,6 +52,13 @@
{{~#set "any" true}}{{/set~}} {{~#set "any" true}}{{/set~}}
{{~/if~}} {{~/if~}}
{{~/each~}} {{~/each~}}
{{~#unless noDictionaryTag~}}
{{~#if (op "||" (op "!" @root.compactTags) (op "!==" dictionary (get "previousDictionary")))~}}
{{~#if (get "any")}}, {{else}}<i>({{/if~}}
{{dictionary}}
{{~#set "any" true}}{{/set~}}
{{~/if~}}
{{~/unless~}}
{{~#if (get "any")}})</i> {{/if~}} {{~#if (get "any")}})</i> {{/if~}}
{{~/scope~}} {{~/scope~}}
{{~#if only~}}({{#each only}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}} {{~#if only~}}({{#each only}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}}
@ -63,6 +70,7 @@
{{~else~}} {{~else~}}
<ul>{{#each glossary}}<li>{{#multiLine}}{{.}}{{/multiLine}}</li>{{/each}}</ul> <ul>{{#each glossary}}<li>{{#multiLine}}{{.}}{{/multiLine}}</li>{{/each}}</ul>
{{~/if~}} {{~/if~}}
{{~#set "previousDictionary" dictionary~}}{{~/set~}}
{{/inline}} {{/inline}}
{{>>>>>>>}} {{>>>>>>>}}
@ -99,12 +107,12 @@
<div style="text-align: left;"> <div style="text-align: left;">
{{~#scope~}} {{~#scope~}}
{{~#if (op "===" definition.type "term")~}} {{~#if (op "===" definition.type "term")~}}
{{~> glossary-single definition brief=brief ~}} {{~> glossary-single definition brief=brief noDictionaryTag=noDictionaryTag ~}}
{{~else if (op "||" (op "===" definition.type "termGrouped") (op "===" definition.type "termMerged"))~}} {{~else if (op "||" (op "===" definition.type "termGrouped") (op "===" definition.type "termMerged"))~}}
{{~#if (op ">" definition.definitions.length 1)~}} {{~#if (op ">" definition.definitions.length 1)~}}
<ol>{{~#each definition.definitions~}}<li>{{~> glossary-single . brief=../brief ~}}</li>{{~/each~}}</ol> <ol>{{~#each definition.definitions~}}<li>{{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}}</li>{{~/each~}}</ol>
{{~else~}} {{~else~}}
{{~#each definition.definitions~}}{{~> glossary-single . brief=../brief ~}}{{~/each~}} {{~#each definition.definitions~}}{{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}}{{~/each~}}
{{~/if~}} {{~/if~}}
{{~else if (op "===" definition.type "kanji")~}} {{~else if (op "===" definition.type "kanji")~}}
{{~#if (op ">" definition.glossary.length 1)~}} {{~#if (op ">" definition.glossary.length 1)~}}
@ -116,4 +124,8 @@
{{~/scope~}} {{~/scope~}}
</div> </div>
{{~/inline~}} {{~/inline~}}
{{#*inline "glossary-no-dictionary"}}
{{~> glossary noDictionaryTag=true ~}}
{{/inline}}
{{>>>>>>>}} {{>>>>>>>}}

View File

@ -9,6 +9,13 @@
{{~#set "any" true}}{{/set~}} {{~#set "any" true}}{{/set~}}
{{~/if~}} {{~/if~}}
{{~/each~}} {{~/each~}}
{{~#unless noDictionaryTag~}}
{{~#if (op "||" (op "!" @root.compactTags) (op "!==" dictionary (get "previousDictionary")))~}}
{{~#if (get "any")}}, {{else}}<i>({{/if~}}
{{dictionary}}
{{~#set "any" true}}{{/set~}}
{{~/if~}}
{{~/unless~}}
{{~#if (get "any")}})</i> {{/if~}} {{~#if (get "any")}})</i> {{/if~}}
{{~/scope~}} {{~/scope~}}
{{~#if only~}}({{#each only}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}} {{~#if only~}}({{#each only}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}}
@ -20,6 +27,7 @@
{{~else~}} {{~else~}}
<ul>{{#each glossary}}<li>{{#multiLine}}{{.}}{{/multiLine}}</li>{{/each}}</ul> <ul>{{#each glossary}}<li>{{#multiLine}}{{.}}{{/multiLine}}</li>{{/each}}</ul>
{{~/if~}} {{~/if~}}
{{~#set "previousDictionary" dictionary~}}{{~/set~}}
{{/inline}} {{/inline}}
{{#*inline "audio"}} {{#*inline "audio"}}
@ -93,12 +101,12 @@
<div style="text-align: left;"> <div style="text-align: left;">
{{~#scope~}} {{~#scope~}}
{{~#if (op "===" definition.type "term")~}} {{~#if (op "===" definition.type "term")~}}
{{~> glossary-single definition brief=brief ~}} {{~> glossary-single definition brief=brief noDictionaryTag=noDictionaryTag ~}}
{{~else if (op "||" (op "===" definition.type "termGrouped") (op "===" definition.type "termMerged"))~}} {{~else if (op "||" (op "===" definition.type "termGrouped") (op "===" definition.type "termMerged"))~}}
{{~#if (op ">" definition.definitions.length 1)~}} {{~#if (op ">" definition.definitions.length 1)~}}
<ol>{{~#each definition.definitions~}}<li>{{~> glossary-single . brief=../brief ~}}</li>{{~/each~}}</ol> <ol>{{~#each definition.definitions~}}<li>{{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}}</li>{{~/each~}}</ol>
{{~else~}} {{~else~}}
{{~#each definition.definitions~}}{{~> glossary-single . brief=../brief ~}}{{~/each~}} {{~#each definition.definitions~}}{{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}}{{~/each~}}
{{~/if~}} {{~/if~}}
{{~else if (op "===" definition.type "kanji")~}} {{~else if (op "===" definition.type "kanji")~}}
{{~#if (op ">" definition.glossary.length 1)~}} {{~#if (op ">" definition.glossary.length 1)~}}
@ -111,6 +119,10 @@
</div> </div>
{{~/inline~}} {{~/inline~}}
{{#*inline "glossary-no-dictionary"}}
{{~> glossary2 noDictionaryTag=true ~}}
{{/inline}}
{{#*inline "glossary-brief"}} {{#*inline "glossary-brief"}}
{{~> glossary brief=true ~}} {{~> glossary brief=true ~}}
{{/inline}} {{/inline}}

View File

@ -94,6 +94,7 @@ class AnkiController {
'furigana-plain', 'furigana-plain',
'glossary', 'glossary',
'glossary-brief', 'glossary-brief',
'glossary-no-dictionary',
'pitch-accents', 'pitch-accents',
'pitch-accent-graphs', 'pitch-accent-graphs',
'pitch-accent-positions', 'pitch-accent-positions',

View File

@ -133,7 +133,6 @@ class Translator {
for (const {character, onyomi, kunyomi, tags, glossary, stats, dictionary} of databaseDefinitions) { for (const {character, onyomi, kunyomi, tags, glossary, stats, dictionary} of databaseDefinitions) {
const expandedStats = await this._expandStats(stats, dictionary); const expandedStats = await this._expandStats(stats, dictionary);
const expandedTags = await this._expandTags(tags, dictionary); const expandedTags = await this._expandTags(tags, dictionary);
expandedTags.push(this._createDictionaryTag(dictionary));
this._sortTags(expandedTags); this._sortTags(expandedTags);
const definition = this._createKanjiDefinition(character, dictionary, onyomi, kunyomi, glossary, expandedTags, expandedStats); const definition = this._createKanjiDefinition(character, dictionary, onyomi, kunyomi, glossary, expandedTags, expandedStats);
@ -541,17 +540,14 @@ class Translator {
} }
_flagRedundantDefinitionTags(definitions) { _flagRedundantDefinitionTags(definitions) {
let lastDictionary = ''; let lastDictionary = null;
let lastPartOfSpeech = ''; let lastPartOfSpeech = '';
const removeCategoriesSet = new Set(); const removeCategoriesSet = new Set();
for (const {definitionTags} of definitions) { for (const {dictionary, definitionTags} of definitions) {
const dictionary = this._createMapKey(this._getTagNamesWithCategory(definitionTags, 'dictionary'));
const partOfSpeech = this._createMapKey(this._getTagNamesWithCategory(definitionTags, 'partOfSpeech')); const partOfSpeech = this._createMapKey(this._getTagNamesWithCategory(definitionTags, 'partOfSpeech'));
if (lastDictionary === dictionary) { if (lastDictionary !== dictionary) {
removeCategoriesSet.add('dictionary');
} else {
lastDictionary = dictionary; lastDictionary = dictionary;
lastPartOfSpeech = ''; lastPartOfSpeech = '';
} }
@ -1054,10 +1050,6 @@ class Translator {
return JSON.stringify(array); return JSON.stringify(array);
} }
_createDictionaryTag(name) {
return this._createTag(name, 'dictionary', '', 100, 0, name, false);
}
_createTag(name, category, notes, order, score, dictionary, redundant) { _createTag(name, category, notes, order, score, dictionary, redundant) {
return { return {
name, name,
@ -1101,7 +1093,6 @@ class Translator {
const dictionaryPriority = this._getDictionaryPriority(dictionary, enabledDictionaryMap); const dictionaryPriority = this._getDictionaryPriority(dictionary, enabledDictionaryMap);
const termTagsExpanded = await this._expandTags(termTags, dictionary); const termTagsExpanded = await this._expandTags(termTags, dictionary);
const definitionTagsExpanded = await this._expandTags(definitionTags, dictionary); const definitionTagsExpanded = await this._expandTags(definitionTags, dictionary);
definitionTagsExpanded.push(this._createDictionaryTag(dictionary));
this._sortTags(definitionTagsExpanded); this._sortTags(definitionTagsExpanded);
this._sortTags(termTagsExpanded); this._sortTags(termTagsExpanded);

View File

@ -2626,6 +2626,10 @@
<td><code class="anki-field-marker">{glossary-brief}</code></td> <td><code class="anki-field-marker">{glossary-brief}</code></td>
<td>List of definitions for the term in a more compact format.</td> <td>List of definitions for the term in a more compact format.</td>
</tr> </tr>
<tr>
<td><code class="anki-field-marker">{glossary-no-dictionary}</code></td>
<td>List of definitions for the term, except the dictionary tag is omitted.</td>
</tr>
<tr> <tr>
<td><code class="anki-field-marker">{pitch-accents}</code></td> <td><code class="anki-field-marker">{pitch-accents}</code></td>
<td>List of pitch accent downstep notations for the term.</td> <td>List of pitch accent downstep notations for the term.</td>

View File

@ -91,9 +91,28 @@ class DisplayGenerator {
this._appendMultiple(reasonsContainer, this._createTermReason.bind(this), reasons); this._appendMultiple(reasonsContainer, this._createTermReason.bind(this), reasons);
this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, false); this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, false);
this._appendMultiple(pitchesContainer, this._createPitches.bind(this), pitches); this._appendMultiple(pitchesContainer, this._createPitches.bind(this), pitches);
this._appendMultiple(definitionsContainer, this._createTermDefinitionItem.bind(this), definitions);
this._appendMultiple(termTagsContainer, this._createTermTag.bind(this), termTags, expressions.length); this._appendMultiple(termTagsContainer, this._createTermTag.bind(this), termTags, expressions.length);
// Add definitions
const dictionaryTag = this._createDictionaryTag(null);
for (let i = 0, ii = definitions.length; i < ii; ++i) {
const definition = definitions[i];
const {dictionary} = definition;
if (dictionaryTag.dictionary === dictionary) {
dictionaryTag.redundant = true;
} else {
dictionaryTag.redundant = false;
dictionaryTag.dictionary = dictionary;
dictionaryTag.name = dictionary;
}
const node2 = this._createTermDefinitionItem(definition, dictionaryTag);
node2.dataset.index = `${i}`;
definitionsContainer.appendChild(node2);
}
definitionsContainer.dataset.count = `${definitions.length}`;
return node; return node;
} }
@ -114,8 +133,10 @@ class DisplayGenerator {
glyphContainer.textContent = details.character; glyphContainer.textContent = details.character;
const groupedFrequencies = DictionaryDataUtil.groupKanjiFrequencies(details.frequencies); const groupedFrequencies = DictionaryDataUtil.groupKanjiFrequencies(details.frequencies);
const dictionaryTag = this._createDictionaryTag(details.dictionary);
this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, true); this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, true);
this._appendMultiple(tagContainer, this._createTag.bind(this), details.tags); this._appendMultiple(tagContainer, this._createTag.bind(this), [...details.tags, dictionaryTag]);
this._appendMultiple(glossaryContainer, this._createKanjiGlossaryItem.bind(this), details.glossary); this._appendMultiple(glossaryContainer, this._createKanjiGlossaryItem.bind(this), details.glossary);
this._appendMultiple(chineseReadingsContainer, this._createKanjiReading.bind(this), details.onyomi); this._appendMultiple(chineseReadingsContainer, this._createKanjiReading.bind(this), details.onyomi);
this._appendMultiple(japaneseReadingsContainer, this._createKanjiReading.bind(this), details.kunyomi); this._appendMultiple(japaneseReadingsContainer, this._createKanjiReading.bind(this), details.kunyomi);
@ -211,17 +232,17 @@ class DisplayGenerator {
return fragment; return fragment;
} }
_createTermDefinitionItem(details) { _createTermDefinitionItem(details, dictionaryTag) {
const node = this._templates.instantiate('term-definition-item'); const node = this._templates.instantiate('term-definition-item');
const tagListContainer = node.querySelector('.term-definition-tag-list'); const tagListContainer = node.querySelector('.term-definition-tag-list');
const onlyListContainer = node.querySelector('.term-definition-disambiguation-list'); const onlyListContainer = node.querySelector('.term-definition-disambiguation-list');
const glossaryContainer = node.querySelector('.term-glossary-list'); const glossaryContainer = node.querySelector('.term-glossary-list');
const dictionary = details.dictionary; const {dictionary, definitionTags} = details;
node.dataset.dictionary = dictionary; node.dataset.dictionary = dictionary;
this._appendMultiple(tagListContainer, this._createTag.bind(this), details.definitionTags); this._appendMultiple(tagListContainer, this._createTag.bind(this), [...definitionTags, dictionaryTag]);
this._appendMultiple(onlyListContainer, this._createTermDisambiguation.bind(this), details.only); this._appendMultiple(onlyListContainer, this._createTermDisambiguation.bind(this), details.only);
this._appendMultiple(glossaryContainer, this._createTermGlossaryItem.bind(this), details.glossary, dictionary); this._appendMultiple(glossaryContainer, this._createTermGlossaryItem.bind(this), details.glossary, dictionary);
@ -645,4 +666,16 @@ class DisplayGenerator {
container.appendChild(document.createTextNode(parts[i])); container.appendChild(document.createTextNode(parts[i]));
} }
} }
_createDictionaryTag(dictionary) {
return {
name: dictionary,
category: 'dictionary',
notes: '',
order: 100,
score: 0,
dictionary,
redundant: false
};
}
} }

File diff suppressed because it is too large Load Diff

View File

@ -833,6 +833,13 @@ ${update8}
{{~#set "any" true}}{{/set~}} {{~#set "any" true}}{{/set~}}
{{~/if~}} {{~/if~}}
{{~/each~}} {{~/each~}}
{{~#unless noDictionaryTag~}}
{{~#if (op "||" (op "!" @root.compactTags) (op "!==" dictionary (get "previousDictionary")))~}}
{{~#if (get "any")}}, {{else}}<i>({{/if~}}
{{dictionary}}
{{~#set "any" true}}{{/set~}}
{{~/if~}}
{{~/unless~}}
{{~#if (get "any")}})</i> {{/if~}} {{~#if (get "any")}})</i> {{/if~}}
{{~/scope~}} {{~/scope~}}
{{~#if only~}}({{#each only}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}} {{~#if only~}}({{#each only}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}}
@ -844,6 +851,7 @@ ${update8}
{{~else~}} {{~else~}}
<ul>{{#each glossary}}<li>{{#multiLine}}{{.}}{{/multiLine}}</li>{{/each}}</ul> <ul>{{#each glossary}}<li>{{#multiLine}}{{.}}{{/multiLine}}</li>{{/each}}</ul>
{{~/if~}} {{~/if~}}
{{~#set "previousDictionary" dictionary~}}{{~/set~}}
{{/inline}} {{/inline}}
{{#*inline "character"}} {{#*inline "character"}}
@ -854,12 +862,12 @@ ${update8}
<div style="text-align: left;"> <div style="text-align: left;">
{{~#scope~}} {{~#scope~}}
{{~#if (op "===" definition.type "term")~}} {{~#if (op "===" definition.type "term")~}}
{{~> glossary-single definition brief=brief ~}} {{~> glossary-single definition brief=brief noDictionaryTag=noDictionaryTag ~}}
{{~else if (op "||" (op "===" definition.type "termGrouped") (op "===" definition.type "termMerged"))~}} {{~else if (op "||" (op "===" definition.type "termGrouped") (op "===" definition.type "termMerged"))~}}
{{~#if (op ">" definition.definitions.length 1)~}} {{~#if (op ">" definition.definitions.length 1)~}}
<ol>{{~#each definition.definitions~}}<li>{{~> glossary-single . brief=../brief ~}}</li>{{~/each~}}</ol> <ol>{{~#each definition.definitions~}}<li>{{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}}</li>{{~/each~}}</ol>
{{~else~}} {{~else~}}
{{~#each definition.definitions~}}{{~> glossary-single . brief=../brief ~}}{{~/each~}} {{~#each definition.definitions~}}{{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}}{{~/each~}}
{{~/if~}} {{~/if~}}
{{~else if (op "===" definition.type "kanji")~}} {{~else if (op "===" definition.type "kanji")~}}
{{~#if (op ">" definition.glossary.length 1)~}} {{~#if (op ">" definition.glossary.length 1)~}}
@ -872,6 +880,10 @@ ${update8}
</div> </div>
{{~/inline~}} {{~/inline~}}
{{#*inline "glossary-no-dictionary"}}
{{~> glossary noDictionaryTag=true ~}}
{{/inline}}
{{#*inline "glossary-brief"}} {{#*inline "glossary-brief"}}
{{~> glossary brief=true ~}} {{~> glossary brief=true ~}}
{{/inline}} {{/inline}}