Skip to content

Commit

Permalink
Fix 来る deinflection
Browse files Browse the repository at this point in the history
  • Loading branch information
btrkeks committed May 26, 2024
1 parent e0b5d09 commit 54f3b70
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/deinflector.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ wtype *wtypes = NULL;
#define IF_EQUALS_ADD(type, str, wordtoadd) \
do { \
if (s8equals(word, S(str))) { \
add_deinflection(s8dup(S(str)), type); \
add_deinflection(s8dup(S(wordtoadd)), type); \
} \
} while (0)

Expand Down Expand Up @@ -292,9 +292,9 @@ static void check_past(s8 word) {
/* exceptions */
IF_ENDSWITH_REPLACE(VERB, "した", "する");
IF_EQUALS_ADD(VERB, "きた", "来る");
IF_EQUALS_ADD(VERB, "来た", "来る");
IF_EQUALS_ADD(VERB, "いった", "行く");
IF_ENDSWITH_REPLACE(VERB, "来た", "来る");
IF_ENDSWITH_REPLACE(VERB, "行った", "行く");
IF_EQUALS_ADD(VERB, "いった", "行く");
/* ----------- */

IF_ENDSWITH_REPLACE(VERB, "した", "す");
Expand All @@ -306,6 +306,9 @@ static void check_past(s8 word) {
}

static void check_masu(s8 word) {
IF_ENDSWITH_REPLACE(VERB, "来ます", "来る");
IF_EQUALS_ADD(VERB, "きます", "来る");

IF_ENDSWITH_CONVERT_ITOU("ます");
IF_ENDSWITH_CONVERT_ITOU("ません");
IF_ENDSWITH_CONVERT_ITOU("ませんでした");
Expand All @@ -322,6 +325,9 @@ static void check_shimau(s8 word) {
}

static void check_passive_causative(s8 word) {
IF_ENDSWITH_REPLACE(VERB, "来させる", "来る");
IF_EQUALS_ADD(VERB, "こさせる", "来る");

IF_ICHIDAN_REPLACE("られる", "る");
IF_ICHIDAN_REPLACE("させる", "る");
IF_ENDSWITH_CONVERT_ATOU("れる");
Expand All @@ -348,6 +354,9 @@ static void check_volitional(s8 word) {
}

static void check_negation(s8 word) {
IF_ENDSWITH_REPLACE(VERB, "来ない", "来る");
IF_ENDSWITH_REPLACE(VERB, "こない", "来る");

IF_EQUALS_ADD(VERB, "ない", "有る");
IF_ENDSWITH_CONVERT_ATOU("ない");
IF_ENDSWITH_CONVERT_ATOU("ん");
Expand Down Expand Up @@ -394,6 +403,9 @@ static void check_concurrent(s8 word) {
}

static void check_imperative(s8 word) {
IF_ENDSWITH_REPLACE(VERB, "来い", "来る");
IF_EQUALS_ADD(VERB, "こい", "来る");

IF_ICHIDAN_REPLACE("ろ", "る");
IF_ENDSWITH_REPLACE(VERB, "れ", "る");
IF_ENDSWITH_REPLACE(VERB, "せ", "す");
Expand Down
15 changes: 15 additions & 0 deletions tests/deinflector_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ static bool buffer_contains(s8 *buffer, s8 word) {
} \
} while (0)


Ensure(Deinflector, deinflects_kuru_kanji) {
DEINFLECT("来る", "来ない", "来ます", "来ません", "来た", "来なかった", "来ました",
"来て", "来なくて", "来られない", "来られる", "来られない", "来させる", "来させない",
"来させられる", "来させられない", "来い");
}

Ensure(Deinflector, deinflects_kuru_hira) {
DEINFLECT("来る", "こない", "きます", "きません", "きた", "こなかった", "きました",
"きて", "こなくて", "こられる", "こられない", "こられない", "こさせる", "こさせない",
"こさせられる", "こさせられない", "こい");
}

Ensure(Deinflector, deinflects_ichidan) {
DEINFLECT("信じる", "信じない", "信じます", "信じません", "信じた", "信じなかった",
"信じました", "信じませんでした", "信じて", "信じなくて", "信じられる",
Expand Down Expand Up @@ -186,6 +199,8 @@ Ensure(Deinflector, deinflects_small) {
TestSuite *deinflector_tests(void) {
TestSuite *suite = create_test_suite();
add_test_with_context(suite, Deinflector, converts_kata_to_hira);
add_test_with_context(suite, Deinflector, deinflects_kuru_kanji);
add_test_with_context(suite, Deinflector, deinflects_kuru_hira);
add_test_with_context(suite, Deinflector, deinflects_ichidan);
add_test_with_context(suite, Deinflector, deinflects_godan_ru);
add_test_with_context(suite, Deinflector, deinflects_godan_mu);
Expand Down

0 comments on commit 54f3b70

Please sign in to comment.