aboutsummaryrefslogtreecommitdiff
path: root/ext/js/language
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-02-28 13:26:34 -0500
committerGitHub <noreply@github.com>2021-02-28 13:26:34 -0500
commit445f87ebdb01badd5fd62a44bb165e23351e10c6 (patch)
tree80309d706630fc28a7ea5a26dbe4e53b6523d58a /ext/js/language
parentfce2c51709852eea9dc14efe937537383e9c418d (diff)
Get categorization of pitch accents (#1462)
Diffstat (limited to 'ext/js/language')
-rw-r--r--ext/js/language/japanese-util.js26
1 files changed, 26 insertions, 0 deletions
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) {