aboutsummaryrefslogtreecommitdiff
path: root/language
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-07-09 00:50:58 +0200
committerlonkaars <loek@pipeframe.xyz>2023-07-09 00:50:58 +0200
commit1138ac8fc8764cf5cd987383a7a0332879be6cca (patch)
tree63aa25275e866d986c2b532f1f050c4f2cf99ac1 /language
parentd36cefb50ddf67daa08a221d2de4d3eaae9e2492 (diff)
rename conditionals and deconjugate obligatory inflections
Diffstat (limited to 'language')
-rw-r--r--language/tags.ts35
1 files changed, 33 insertions, 2 deletions
diff --git a/language/tags.ts b/language/tags.ts
index a9fc5ca..312a594 100644
--- a/language/tags.ts
+++ b/language/tags.ts
@@ -67,6 +67,15 @@ export const Tag = {
* e.g. 来ない -> 来る [infl:negative]
*/
Inflection: {
+ /**
+ * @constant affirmative conjugations
+ *
+ * This conjugation should not be added by any deconjugation rules, but is
+ * calculated based on the amount of negations. Even counts of negative
+ * inflections (including 0) add this tag, while odd counts don't add this
+ * tag.
+ */
+ Affirmative: "infl:affirmative",
/** @constant negative conjugations */
Negative: "infl:negative",
/** @constant time-related conjugations */
@@ -89,8 +98,6 @@ export const Tag = {
Te: "infl:suffix:te",
/** @constant -tari ending (e.g. 遊んだり) */
Tari: "infl:suffix:tari",
- /** @constant -ba ending for conditionals (e.g. 泳げれば)*/
- Ba: "infl:suffix:ba",
},
/** @constant internal deinflection rules */
Reason: {
@@ -116,6 +123,15 @@ export const Tag = {
Causative: "infl:causative",
/** @constant imperative form (e.g. 聞け) */
Command: "infl:command",
+ /** @constant conditional forms */
+ Conditional: {
+ /** @constant -ba ending (e.g. 泳げれば) */
+ Ba: "infl:cond:ba",
+ /** @constant -ra ending (e.g. 取ったら) */
+ Ra: "infl:cond:ra",
+ },
+ /** @constant makes a verb obligatory (e.g. 入ってはいけない) */
+ Obliged: "infl:must",
},
/** @constant uncategorized tags */
Auxiliary: {
@@ -140,16 +156,31 @@ export type TokenTags = Array<TokenTag>;
export function parseTags(input: string) {
var tags = input.replaceAll(/ +/g, " ").trim().split(" ") as TokenTag[];
var filteredTags: TokenTag[] = [];
+ var negationCount = 0;
for (var tag of tags) {
+ // conjugations that are used as "stepping stones" for others should be
+ // filtered in this loop. checking if a combination of tags is valid should
+ // be done in ./parser.ts
+
// 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;
+
+ // normalize multiple Inflection.Negative to single Inflection.Affirmative or Inflection.Negative
+ if (tag == Tag.Inflection.Negative) {
+ negationCount++;
+ continue;
+ }
filteredTags.push(tag);
}
+ filteredTags.push(negationCount % 2 == 0 ? Tag.Inflection.Affirmative : Tag.Inflection.Negative);
return filteredTags.set().arr() as TokenTags; // make sure array doesn't contain duplicates
}