aboutsummaryrefslogtreecommitdiff
path: root/api/sentence.ts
diff options
context:
space:
mode:
Diffstat (limited to 'api/sentence.ts')
-rw-r--r--api/sentence.ts14
1 files changed, 10 insertions, 4 deletions
diff --git a/api/sentence.ts b/api/sentence.ts
index 276a6c5..6d9fc6d 100644
--- a/api/sentence.ts
+++ b/api/sentence.ts
@@ -1,10 +1,10 @@
import { ParseResult } from "../language/types.ts";
import APIBase from "./base.ts";
-import SentenceWord from "./sentence-word.ts";
+import Japanese, { JapaneseFormatter } from "./japanese.ts";
import Word from "./word.ts";
export default class Sentence extends APIBase {
- public words: Array<SentenceWord> = [];
+ public words: Array<Word> = [];
protected query?: ParseResult;
protected original: string = "";
@@ -33,7 +33,7 @@ export default class Sentence extends APIBase {
let token = 0;
let i = 0;
while (i < this.original.length) {
- this.words.push(new SentenceWord(this.query!.tokens[token]).withParent(await this.api));
+ this.words.push(new Word(this.query!.tokens[token]).withParent(await this.api));
i += this.query!.tokens[token].source.length;
if (i == this.original.length) break;
@@ -43,8 +43,14 @@ export default class Sentence extends APIBase {
if (this.query!.tokens[token]?.start == i) continue;
var remainder = this.original.substring(i, this.query!.tokens[token]?.start);
- this.words.push(new SentenceWord(remainder).withParent(await this.api));
+ this.words.push(new Word(remainder).withParent(await this.api));
i += remainder.length;
}
}
+
+ furigana(format: JapaneseFormatter = "HTML"): string {
+ return this.words.reduce((out, word) => {
+ return out + word.text.furigana(format);
+ }, "");
+ }
}