From 445f87ebdb01badd5fd62a44bb165e23351e10c6 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 28 Feb 2021 13:26:34 -0500 Subject: Get categorization of pitch accents (#1462) --- ext/js/language/japanese-util.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'ext/js/language') diff --git a/ext/js/language/japanese-util.js b/ext/js/language/japanese-util.js index e47cdf55..4d317396 100644 --- a/ext/js/language/japanese-util.js +++ b/ext/js/language/japanese-util.js @@ -232,6 +232,22 @@ const JapaneseUtil = (() => { } } + getPitchCategory(text, pitchAccentPosition, isVerbOrAdjective) { + if (pitchAccentPosition === 0) { + return 'heiban'; + } + if (isVerbOrAdjective) { + return pitchAccentPosition > 0 ? 'kifuku' : null; + } + if (pitchAccentPosition === 1) { + return 'atamadaka'; + } + if (pitchAccentPosition > 1) { + return pitchAccentPosition >= this.getKanaMoraCount(text) ? 'odaka' : 'nakadaka'; + } + return null; + } + getKanaMorae(text) { const morae = []; let i; @@ -245,6 +261,16 @@ const JapaneseUtil = (() => { return morae; } + getKanaMoraCount(text) { + let moraCount = 0; + for (const c of text) { + if (!(SMALL_KANA_SET.has(c) && moraCount > 0)) { + ++moraCount; + } + } + return moraCount; + } + // Conversion functions convertToKana(text) { -- cgit v1.2.3