diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-07-03 13:49:42 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-07-03 13:49:42 +0200 |
commit | 14c31de2f166d9e6d874984cdee5a2876c1ddec5 (patch) | |
tree | 876497de9e2c3b170d564ee343d887d138033897 /api | |
parent | 5c9bebac4078ee053c5048e4de2a3ed5afed4e24 (diff) |
keep kana-only words as kana-only in readings
Diffstat (limited to 'api')
-rw-r--r-- | api/sentence.ts | 2 | ||||
-rw-r--r-- | api/word.ts | 20 |
2 files changed, 18 insertions, 4 deletions
diff --git a/api/sentence.ts b/api/sentence.ts index 6d9fc6d..d0cc434 100644 --- a/api/sentence.ts +++ b/api/sentence.ts @@ -50,7 +50,7 @@ export default class Sentence extends APIBase { furigana(format: JapaneseFormatter = "HTML"): string { return this.words.reduce((out, word) => { - return out + word.text.furigana(format); + return out + word.furigana(format); }, ""); } } diff --git a/api/word.ts b/api/word.ts index 13c7197..4d77d97 100644 --- a/api/word.ts +++ b/api/word.ts @@ -1,24 +1,31 @@ import Glossary from "./glossary.ts"; import APIBase from "./base.ts"; import { ParseToken } from "../language/types.ts"; -import Japanese from "./japanese.ts"; +import Japanese, { JapaneseFormatter } from "./japanese.ts"; import "../util/string.ts"; import { Tag } from "../language/tags.ts"; export default class Word extends APIBase { /** @prop dictionary form of verb if this word is a verb */ - public base: Japanese; + protected base: Japanese; /** @prop word as written in parent sentence */ - public text: Japanese; + protected text: Japanese; + /** @prop this.furigana should output kanji with reading */ + protected outputKanji: boolean = true; + /** @prop this word represents an unrecognized sentence part between recognized terms */ + protected filler: boolean; constructor(input: string | ParseToken) { super(); if (typeof input === "string") { + this.filler = true; input = input as string; this.base = new Japanese(input, input); this.text = this.base; + this.outputKanji = false; } else { + this.filler = false; input = input as ParseToken; this.base = new Japanese(input.writing, input.reading); if (input.tags.anyOf(Object.values(Tag.Class.Verb))) { @@ -32,10 +39,17 @@ export default class Word extends APIBase { } else { this.text = this.base; } + this.outputKanji = !input.source.kanaOnly(); // only output kanji if input also uses kanji } } + furigana(format: JapaneseFormatter) { + if (!this.outputKanji) return this.text.reading; + else return this.text.furigana(format); + } + async glossary() { + // TODO: output nothing if this.filler == true return new Glossary().withParent(await this.api); } } |