summaryrefslogtreecommitdiff
path: root/ext/js/display/display-generator.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-26 19:50:54 -0400
committerGitHub <noreply@github.com>2021-03-26 19:50:54 -0400
commit90f7d5ba07340413aa7e43c3a0cc038690b32db3 (patch)
treeb3c57f9240de2e3a86cbc8dba5fe93d71e4067ae /ext/js/display/display-generator.js
parent482dd8c8d8339d29c9e7a202cbf4c54bf7cf291d (diff)
Add part of speech info (#1561)
* Add part of speech info to headwords * Expose parts of speech to Anki template rendering * Expose parts of speech * Update pitch accent categories * Update docs * Add part-of-speech * Update options and tests * Update markers * Update test data
Diffstat (limited to 'ext/js/display/display-generator.js')
-rw-r--r--ext/js/display/display-generator.js26
1 files changed, 23 insertions, 3 deletions
diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js
index 19e88b8a..724bec9c 100644
--- a/ext/js/display/display-generator.js
+++ b/ext/js/display/display-generator.js
@@ -250,10 +250,14 @@ class DisplayGenerator {
node.dataset.readingIsSame = `${reading === expression}`;
node.dataset.frequency = DictionaryDataUtil.getTermFrequency(termTags);
- const pitchAccentCategories = this._getPitchAccentCategories(reading, pronunciations, headwordIndex);
+ const {wordClasses} = headword;
+ const pitchAccentCategories = this._getPitchAccentCategories(reading, pronunciations, wordClasses, headwordIndex);
if (pitchAccentCategories !== null) {
node.dataset.pitchAccentCategories = pitchAccentCategories;
}
+ if (wordClasses.length > 0) {
+ node.dataset.wordClasses = wordClasses.join(' ');
+ }
this._setTextContent(node.querySelector('.expression-reading'), reading);
@@ -762,13 +766,14 @@ class DisplayGenerator {
}
}
- _getPitchAccentCategories(reading, pronunciations, headwordIndex) {
+ _getPitchAccentCategories(reading, pronunciations, wordClasses, headwordIndex) {
if (pronunciations.length === 0) { return null; }
+ const isVerbOrAdjective = this._isVerbOrAdjective(wordClasses);
const categories = new Set();
for (const pronunciation of pronunciations) {
if (pronunciation.headwordIndex !== headwordIndex) { continue; }
for (const {position} of pronunciation.pitches) {
- const category = this._japaneseUtil.getPitchCategory(reading, position, false);
+ const category = this._japaneseUtil.getPitchCategory(reading, position, isVerbOrAdjective);
if (category !== null) {
categories.add(category);
}
@@ -776,4 +781,19 @@ class DisplayGenerator {
}
return categories.size > 0 ? [...categories].join(' ') : null;
}
+
+ _isVerbOrAdjective(wordClasses) {
+ for (const wordClass of wordClasses) {
+ switch (wordClass) {
+ case 'v1':
+ case 'v5':
+ case 'vs':
+ case 'vk':
+ case 'vz':
+ case 'adj-i':
+ return true;
+ }
+ }
+ return false;
+ }
}