aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/word.ts72
1 files changed, 41 insertions, 31 deletions
diff --git a/api/word.ts b/api/word.ts
index 4c09cff..2e07c98 100644
--- a/api/word.ts
+++ b/api/word.ts
@@ -1,47 +1,57 @@
import Glossary from "./glossary.ts";
import APIBase from "./base.ts";
import Japanese, { JapaneseFormatter } from "./japanese.ts";
-
import "../util/string.ts";
+import "../util/object.ts";
import { Tag, TagGroup, TokenTags } from "../search/tags.ts";
import { SearchWord } from "../search/types.ts";
+import { recursiveValues } from "../util/object.ts";
// irregular stems taken from <https://en.wikipedia.org/wiki/Japanese_irregular_verbs#suru_and_kuru>
function irregularSuruStem(tags: TokenTags): string {
- if (tags.anyOf([
- Tag.Inflection.Polite.Masu,
- Tag.Inflection.Suffix.Te,
- Tag.Inflection.Tense.Past,
- Tag.Inflection.Desirable.Itai, // part of Wikipedia's -ta form
- Tag.Inflection.Negative,
- Tag.Inflection.Desirable.Volitional,
- Tag.Inflection.Command,
- ])) return "し";
- if (tags.anyOf([
- Tag.Inflection.Passive,
- Tag.Inflection.Causative,
- ])) return "さ";
- if (tags.anyOf([
- Tag.Inflection.Potential,
- ])) return "でき";
+ for (let i = 0, tag = tags[i]; i < tags.length; i++, tag = tags[i]) {
+ if (!recursiveValues(Tag.Inflection).includes(tag)) continue;
+ if (recursiveValues(Tag.Inflection.Reason).includes(tag)) continue;
+ if ([
+ Tag.Inflection.Polite.Masu,
+ Tag.Inflection.Suffix.Te,
+ Tag.Inflection.Tense.Past,
+ Tag.Inflection.Desirable.Itai, // part of Wikipedia's -ta form
+ Tag.Inflection.Negative,
+ Tag.Inflection.Desirable.Volitional,
+ Tag.Inflection.Command,
+ ].includes(tag as any)) return "し";
+ if ([
+ Tag.Inflection.Passive,
+ Tag.Inflection.Causative,
+ ].includes(tag as any)) return "さ";
+ // wikipedia has できる as the potential form for する, but できる here
+ // means it's already foobar'd
+ break;
+ }
return "す";
}
function irregularKuruStem(tags: TokenTags): string {
- if (tags.anyOf([
- Tag.Inflection.Polite.Masu,
- Tag.Inflection.Suffix.Te,
- Tag.Inflection.Tense.Past,
- Tag.Inflection.Desirable.Itai, // part of Wikipedia's -ta form
- ])) return "き";
- if (tags.anyOf([
- Tag.Inflection.Negative,
- Tag.Inflection.Desirable.Volitional,
- Tag.Inflection.Passive,
- Tag.Inflection.Causative,
- Tag.Inflection.Potential,
- Tag.Inflection.Command,
- ])) return "こ";
+ for (let i = 0, tag = tags[i]; i < tags.length; i++, tag = tags[i]) {
+ if (!recursiveValues(Tag.Inflection).includes(tag)) continue;
+ if (recursiveValues(Tag.Inflection.Reason).includes(tag)) continue;
+ if ([
+ Tag.Inflection.Polite.Masu,
+ Tag.Inflection.Suffix.Te,
+ Tag.Inflection.Tense.Past,
+ Tag.Inflection.Desirable.Itai, // part of Wikipedia's -ta form
+ ].includes(tag as any)) return "き";
+ if ([
+ Tag.Inflection.Negative,
+ Tag.Inflection.Desirable.Volitional,
+ Tag.Inflection.Passive,
+ Tag.Inflection.Causative,
+ Tag.Inflection.Potential,
+ Tag.Inflection.Command,
+ ].includes(tag as any)) return "こ";
+ break;
+ }
return "く";
}