From 90f7d5ba07340413aa7e43c3a0cc038690b32db3 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 26 Mar 2021 19:50:54 -0400 Subject: 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 --- ext/js/display/display-generator.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'ext/js/display/display-generator.js') 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; + } } -- cgit v1.2.3