aboutsummaryrefslogtreecommitdiff
path: root/api/word.ts
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-07-03 12:46:22 +0200
committerlonkaars <loek@pipeframe.xyz>2023-07-03 12:46:22 +0200
commit5c9bebac4078ee053c5048e4de2a3ed5afed4e24 (patch)
tree6afc0bf8e0d8db373bb080567c6db56b78b4440a /api/word.ts
parentfa68eb21bf1d0460303cae3a0233e2d6cefd00ca (diff)
fix furigana for known working sentence
Diffstat (limited to 'api/word.ts')
-rw-r--r--api/word.ts21
1 files changed, 14 insertions, 7 deletions
diff --git a/api/word.ts b/api/word.ts
index 3421f9f..13c7197 100644
--- a/api/word.ts
+++ b/api/word.ts
@@ -4,6 +4,7 @@ import { ParseToken } from "../language/types.ts";
import Japanese 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 */
@@ -15,16 +16,22 @@ export default class Word extends APIBase {
super();
if (typeof input === "string") {
input = input as string;
- this.text = new Japanese(input, input);
- this.base = this.text;
+ this.base = new Japanese(input, input);
+ this.text = this.base;
} else {
input = input as ParseToken;
- var common = Math.max(input.writing.cmpLen(input.source),
- input.reading.cmpLen(input.source));
- var conjugation = input.source.substring(common);
this.base = new Japanese(input.writing, input.reading);
- this.text = new Japanese(input.writing.substring(0, common) + conjugation,
- input.reading.substring(0, common) + conjugation);
+ if (input.tags.anyOf(Object.values(Tag.Class.Verb))) {
+ var writingCommon = input.writing.cmpLen(input.source);
+ var readingCommon = input.reading.cmpLen(input.source);
+ var stemLength = Math.max(writingCommon, readingCommon);
+ var base = input[writingCommon > readingCommon ? "writing" : "reading"].substring(stemLength);
+ var conjugation = input.source.substring(stemLength);
+ this.text = new Japanese(input.writing.replaceLast(base, conjugation),
+ input.reading.replaceLast(base, conjugation));
+ } else {
+ this.text = this.base;
+ }
}
}