diff options
| author | lonkaars <loek@pipeframe.xyz> | 2023-07-09 18:00:33 +0200 |
|---|---|---|
| committer | lonkaars <loek@pipeframe.xyz> | 2023-07-09 18:00:33 +0200 |
| commit | 80b46d2f6152129f25f5734e4960cb7c15edfcf0 (patch) | |
| tree | 191c528e5ed18c6c85091b5dadb152231cb857aa /language | |
| parent | 1138ac8fc8764cf5cd987383a7a0332879be6cca (diff) | |
more deinflections + tests
Diffstat (limited to 'language')
| -rw-r--r-- | language/tags.ts | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/language/tags.ts b/language/tags.ts index 312a594..de1a3ea 100644 --- a/language/tags.ts +++ b/language/tags.ts @@ -131,7 +131,28 @@ export const Tag = { Ra: "infl:cond:ra", }, /** @constant makes a verb obligatory (e.g. 入ってはいけない) */ - Obliged: "infl:must", + Obligatory: "infl:must", + /** @constant verbs that someone wants to do / be done */ + Desirable: { + /** @constant 〜たい endings (e.g. 買いたい) */ + Itai: "infl:desire:itai", + /** @constant 〜おう endings (e.g. 寝よう) */ + Volitional: "infl:desire:volitional", + }, + /** @constant makes a verb an attempt */ + Attempt: { + /** @constant 〜みる to try something out (e.g. 飲んでみた) */ + Miru: "infl:attempt:miru", + /** @constant 〜とする attempts (e.g. 入ろうとしている) */ + ToSuru: "infl:attempt:tosuru", + }, + /** @constant temporary tags (removed by parseTags) */ + Temporary: { + /** @constant particle of obligatory conjugation (e.g. 行かない*と*だめ), or colloquial abbreviation */ + ObligatoryParticle: "infl:tmp:must:prt", + /** @constant resulting action part of obligatory conjugation (e.g. 行かないと*だめ*) */ + ObligatoryResult: "infl:tmp:must:res", + }, }, /** @constant uncategorized tags */ Auxiliary: { @@ -165,12 +186,17 @@ export function parseTags(input: string) { // skip past tense tag if used as step for -te and -tari inflection if (tag == Tag.Inflection.Tense.Past && filteredTags.anyOf([Tag.Inflection.Suffix.Te, Tag.Inflection.Suffix.Tari])) continue; - // skip -te suffix tag if it's a base for continuous tense - if (tag == Tag.Inflection.Suffix.Te && - filteredTags.anyOf([Tag.Inflection.Tense.Continuous])) continue; - // skip -te suffix tag if it's a base for obligatory inflection - if (tag == Tag.Inflection.Suffix.Te && - filteredTags.anyOf([Tag.Inflection.Obliged])) continue; + + // skip -te suffix tag if used for + if (tag == Tag.Inflection.Suffix.Te && filteredTags.anyOf([ + Tag.Inflection.Tense.Continuous, // base for continuous tense + Tag.Inflection.Obligatory, // base for obligatory inflection + Tag.Inflection.Attempt.Miru, // base for 〜みる attempt + ])) continue; + + // skip volitional tag if used for 〜とする attempt + if (tag == Tag.Inflection.Desirable.Volitional && + filteredTags.anyOf([Tag.Inflection.Attempt.ToSuru])) continue; // normalize multiple Inflection.Negative to single Inflection.Affirmative or Inflection.Negative if (tag == Tag.Inflection.Negative) { @@ -180,7 +206,21 @@ export function parseTags(input: string) { filteredTags.push(tag); } + + // negative + と without resulting action = implicit affirmative obligatory + if (filteredTags.includes(Tag.Inflection.Temporary.ObligatoryParticle) && + !filteredTags.includes(Tag.Inflection.Temporary.ObligatoryResult)) { + negationCount = 0; // -> make resulting tags affirmative + } + + // normalize affirmative/negative filteredTags.push(negationCount % 2 == 0 ? Tag.Inflection.Affirmative : Tag.Inflection.Negative); - return filteredTags.set().arr() as TokenTags; // make sure array doesn't contain duplicates + + // filter any remaining temporary tags + type tempTag = typeof Tag.Inflection.Temporary[keyof typeof Tag.Inflection.Temporary]; + filteredTags = filteredTags.filter(t => !Object.values(Tag.Inflection.Temporary).includes(t as tempTag)); + + // filter any duplicates + return filteredTags.set().arr() as TokenTags; } |