aboutsummaryrefslogtreecommitdiff
path: root/api/word.ts
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-07-11 13:01:41 +0200
committerlonkaars <loek@pipeframe.xyz>2023-07-11 13:01:41 +0200
commite99ae80f7adc0f0e677381c3cc1549235d3877ab (patch)
tree57362ddfa0ee2704cf7042d72559c479283ea1df /api/word.ts
parent479836dbf3c7cc6e5940abe698ccc5e1d7b440c7 (diff)
small cleanup
Diffstat (limited to 'api/word.ts')
-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 "く";
}