Files
neuron/dist/morphology-pi.c
will.anderson 48ecd83421 fix: restore elb build — import paths, morphology deps, C master declarations header
- Fix wrong ELP import paths in soul.el, elp-input.el, studio.el
  (../foundation/elp/src → ../foundation/el/elp/src)
- Add missing import "morphology.el" to all 29 language morphology modules
- Recompile all affected dist/*.c with correct cross-module declarations
- Add dist/elp-c-decls.h: C-level master forward declarations for ELP package
  (enables elb --force-include to resolve undeclared cross-module calls)
2026-05-08 19:43:57 -05:00

775 lines
19 KiB
C

#include <stdint.h>
#include <stdlib.h>
#include "el_runtime.h"
el_val_t str_ends(el_val_t s, el_val_t suf);
el_val_t str_last_char(el_val_t s);
el_val_t str_last2(el_val_t s);
el_val_t str_last3(el_val_t s);
el_val_t str_drop_last(el_val_t s, el_val_t n);
el_val_t is_vowel(el_val_t c);
el_val_t morph_apply_suffix(el_val_t base, el_val_t suffix);
el_val_t en_irregular_plural(el_val_t word);
el_val_t en_irregular_singular(el_val_t word);
el_val_t en_irregular_verb(el_val_t base);
el_val_t en_verb_3sg(el_val_t base);
el_val_t en_should_double_final(el_val_t base);
el_val_t en_verb_past(el_val_t base);
el_val_t en_verb_gerund(el_val_t base);
el_val_t en_pluralize_regular(el_val_t singular);
el_val_t en_verb_form(el_val_t base, el_val_t tense, el_val_t person, el_val_t number);
el_val_t agree_determiner(el_val_t det, el_val_t noun);
el_val_t morph_pluralize(el_val_t noun, el_val_t profile);
el_val_t morph_map_canonical(el_val_t verb, el_val_t code);
el_val_t morph_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number, el_val_t profile);
el_val_t morph_inflect(el_val_t word, el_val_t features, el_val_t profile);
el_val_t pluralize(el_val_t singular);
el_val_t singularize(el_val_t plural);
el_val_t verb_form(el_val_t base, el_val_t tense, el_val_t person, el_val_t number);
el_val_t irregular_plural(el_val_t word);
el_val_t irregular_singular(el_val_t word);
el_val_t pi_str_ends(el_val_t s, el_val_t suf);
el_val_t pi_drop(el_val_t s, el_val_t n);
el_val_t pi_last_char(el_val_t s);
el_val_t pi_slot(el_val_t person, el_val_t number);
el_val_t pi_present_ending(el_val_t slot);
el_val_t pi_aorist_ending(el_val_t slot);
el_val_t pi_future_ending(el_val_t slot);
el_val_t pi_hoti_present(el_val_t slot);
el_val_t pi_atthi_present(el_val_t slot);
el_val_t pi_hoti_aorist(el_val_t slot);
el_val_t pi_hoti_future(el_val_t slot);
el_val_t pi_gacchati_present(el_val_t slot);
el_val_t pi_gacchati_aorist(el_val_t slot);
el_val_t pi_gacchati_future(el_val_t slot);
el_val_t pi_passati_present(el_val_t slot);
el_val_t pi_passati_aorist(el_val_t slot);
el_val_t pi_passati_future(el_val_t slot);
el_val_t pi_vadati_present(el_val_t slot);
el_val_t pi_vadati_aorist(el_val_t slot);
el_val_t pi_vadati_future(el_val_t slot);
el_val_t pi_karoti_present(el_val_t slot);
el_val_t pi_karoti_aorist(el_val_t slot);
el_val_t pi_karoti_future(el_val_t slot);
el_val_t pi_map_canonical(el_val_t verb);
el_val_t pi_regular_root(el_val_t verb);
el_val_t pi_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number);
el_val_t pi_decline_a_masc_sg(el_val_t stem, el_val_t gram_case);
el_val_t pi_decline_a_masc_pl(el_val_t stem, el_val_t gram_case);
el_val_t pi_decline_a_fem_sg(el_val_t stem, el_val_t gram_case);
el_val_t pi_decline_a_fem_pl(el_val_t stem, el_val_t gram_case);
el_val_t pi_detect_class(el_val_t noun);
el_val_t pi_decline(el_val_t noun, el_val_t gram_case, el_val_t number);
el_val_t pi_noun_phrase(el_val_t noun, el_val_t gram_case, el_val_t number, el_val_t definite);
el_val_t pi_str_ends(el_val_t s, el_val_t suf) {
return str_ends_with(s, suf);
return 0;
}
el_val_t pi_drop(el_val_t s, el_val_t n) {
el_val_t len = str_len(s);
if (n >= len) {
return EL_STR("");
}
return str_slice(s, 0, (len - n));
return 0;
}
el_val_t pi_last_char(el_val_t s) {
el_val_t n = str_len(s);
if (n == 0) {
return EL_STR("");
}
return str_slice(s, (n - 1), n);
return 0;
}
el_val_t pi_slot(el_val_t person, el_val_t number) {
if (str_eq(person, EL_STR("first"))) {
if (str_eq(number, EL_STR("singular"))) {
return 0;
}
return 3;
}
if (str_eq(person, EL_STR("second"))) {
if (str_eq(number, EL_STR("singular"))) {
return 1;
}
return 4;
}
if (str_eq(number, EL_STR("singular"))) {
return 2;
}
return 5;
return 0;
}
el_val_t pi_present_ending(el_val_t slot) {
if (slot == 0) {
return EL_STR("\xc4\x81mi");
}
if (slot == 1) {
return EL_STR("asi");
}
if (slot == 2) {
return EL_STR("ati");
}
if (slot == 3) {
return EL_STR("\xc4\x81ma");
}
if (slot == 4) {
return EL_STR("atha");
}
return EL_STR("anti");
return 0;
}
el_val_t pi_aorist_ending(el_val_t slot) {
if (slot == 0) {
return EL_STR("i\xe1\xb9\x83");
}
if (slot == 1) {
return EL_STR("i");
}
if (slot == 2) {
return EL_STR("i");
}
if (slot == 3) {
return EL_STR("imh\xc4\x81");
}
if (slot == 4) {
return EL_STR("ittha");
}
return EL_STR("i\xe1\xb9\x83su");
return 0;
}
el_val_t pi_future_ending(el_val_t slot) {
if (slot == 0) {
return EL_STR("iss\xc4\x81mi");
}
if (slot == 1) {
return EL_STR("issasi");
}
if (slot == 2) {
return EL_STR("issati");
}
if (slot == 3) {
return EL_STR("iss\xc4\x81ma");
}
if (slot == 4) {
return EL_STR("issatha");
}
return EL_STR("issanti");
return 0;
}
el_val_t pi_hoti_present(el_val_t slot) {
if (slot == 0) {
return EL_STR("homi");
}
if (slot == 1) {
return EL_STR("hosi");
}
if (slot == 2) {
return EL_STR("hoti");
}
if (slot == 3) {
return EL_STR("homa");
}
if (slot == 4) {
return EL_STR("hotha");
}
return EL_STR("honti");
return 0;
}
el_val_t pi_atthi_present(el_val_t slot) {
if (slot == 0) {
return EL_STR("amhi");
}
if (slot == 1) {
return EL_STR("asi");
}
if (slot == 2) {
return EL_STR("atthi");
}
if (slot == 3) {
return EL_STR("amha");
}
if (slot == 4) {
return EL_STR("attha");
}
return EL_STR("santi");
return 0;
}
el_val_t pi_hoti_aorist(el_val_t slot) {
if (slot == 0) {
return EL_STR("\xc4\x81si\xe1\xb9\x83");
}
if (slot == 1) {
return EL_STR("\xc4\x81si");
}
if (slot == 2) {
return EL_STR("\xc4\x81si");
}
if (slot == 3) {
return EL_STR("\xc4\x81simh\xc4\x81");
}
if (slot == 4) {
return EL_STR("\xc4\x81sittha");
}
return EL_STR("\xc4\x81si\xe1\xb9\x83su");
return 0;
}
el_val_t pi_hoti_future(el_val_t slot) {
if (slot == 0) {
return EL_STR("hoss\xc4\x81mi");
}
if (slot == 1) {
return EL_STR("hossasi");
}
if (slot == 2) {
return EL_STR("hossati");
}
if (slot == 3) {
return EL_STR("hoss\xc4\x81ma");
}
if (slot == 4) {
return EL_STR("hossatha");
}
return EL_STR("hossanti");
return 0;
}
el_val_t pi_gacchati_present(el_val_t slot) {
if (slot == 0) {
return EL_STR("gacch\xc4\x81mi");
}
if (slot == 1) {
return EL_STR("gacchasi");
}
if (slot == 2) {
return EL_STR("gacchati");
}
if (slot == 3) {
return EL_STR("gacch\xc4\x81ma");
}
if (slot == 4) {
return EL_STR("gacchatha");
}
return EL_STR("gacchanti");
return 0;
}
el_val_t pi_gacchati_aorist(el_val_t slot) {
if (slot == 0) {
return EL_STR("agam\xc4\x81si\xe1\xb9\x83");
}
if (slot == 1) {
return EL_STR("agam\xc4\x81si");
}
if (slot == 2) {
return EL_STR("agam\xc4\x81si");
}
if (slot == 3) {
return EL_STR("agam\xc4\x81simh\xc4\x81");
}
if (slot == 4) {
return EL_STR("agam\xc4\x81sittha");
}
return EL_STR("agama\xe1\xb9\x83su");
return 0;
}
el_val_t pi_gacchati_future(el_val_t slot) {
if (slot == 0) {
return EL_STR("gamiss\xc4\x81mi");
}
if (slot == 1) {
return EL_STR("gamissasi");
}
if (slot == 2) {
return EL_STR("gamissati");
}
if (slot == 3) {
return EL_STR("gamiss\xc4\x81ma");
}
if (slot == 4) {
return EL_STR("gamissatha");
}
return EL_STR("gamissanti");
return 0;
}
el_val_t pi_passati_present(el_val_t slot) {
if (slot == 0) {
return EL_STR("pass\xc4\x81mi");
}
if (slot == 1) {
return EL_STR("passasi");
}
if (slot == 2) {
return EL_STR("passati");
}
if (slot == 3) {
return EL_STR("pass\xc4\x81ma");
}
if (slot == 4) {
return EL_STR("passatha");
}
return EL_STR("passanti");
return 0;
}
el_val_t pi_passati_aorist(el_val_t slot) {
if (slot == 0) {
return EL_STR("addas\xc4\x81si\xe1\xb9\x83");
}
if (slot == 1) {
return EL_STR("addas\xc4\x81si");
}
if (slot == 2) {
return EL_STR("addas\xc4\x81si");
}
if (slot == 3) {
return EL_STR("addas\xc4\x81simh\xc4\x81");
}
if (slot == 4) {
return EL_STR("addas\xc4\x81sittha");
}
return EL_STR("addas\xc4\x81si\xe1\xb9\x83su");
return 0;
}
el_val_t pi_passati_future(el_val_t slot) {
if (slot == 0) {
return EL_STR("dakkhiss\xc4\x81mi");
}
if (slot == 1) {
return EL_STR("dakkhissasi");
}
if (slot == 2) {
return EL_STR("dakkhissati");
}
if (slot == 3) {
return EL_STR("dakkhiss\xc4\x81ma");
}
if (slot == 4) {
return EL_STR("dakkhissatha");
}
return EL_STR("dakkhissanti");
return 0;
}
el_val_t pi_vadati_present(el_val_t slot) {
if (slot == 0) {
return EL_STR("vad\xc4\x81mi");
}
if (slot == 1) {
return EL_STR("vadasi");
}
if (slot == 2) {
return EL_STR("vadati");
}
if (slot == 3) {
return EL_STR("vad\xc4\x81ma");
}
if (slot == 4) {
return EL_STR("vadatha");
}
return EL_STR("vadanti");
return 0;
}
el_val_t pi_vadati_aorist(el_val_t slot) {
if (slot == 0) {
return EL_STR("avad\xc4\x81si\xe1\xb9\x83");
}
if (slot == 1) {
return EL_STR("avad\xc4\x81si");
}
if (slot == 2) {
return EL_STR("avad\xc4\x81si");
}
if (slot == 3) {
return EL_STR("avad\xc4\x81simh\xc4\x81");
}
if (slot == 4) {
return EL_STR("avad\xc4\x81sittha");
}
return EL_STR("avad\xc4\x81si\xe1\xb9\x83su");
return 0;
}
el_val_t pi_vadati_future(el_val_t slot) {
if (slot == 0) {
return EL_STR("vadiss\xc4\x81mi");
}
if (slot == 1) {
return EL_STR("vadissasi");
}
if (slot == 2) {
return EL_STR("vadissati");
}
if (slot == 3) {
return EL_STR("vadiss\xc4\x81ma");
}
if (slot == 4) {
return EL_STR("vadissatha");
}
return EL_STR("vadissanti");
return 0;
}
el_val_t pi_karoti_present(el_val_t slot) {
if (slot == 0) {
return EL_STR("karomi");
}
if (slot == 1) {
return EL_STR("karosi");
}
if (slot == 2) {
return EL_STR("karoti");
}
if (slot == 3) {
return EL_STR("karoma");
}
if (slot == 4) {
return EL_STR("karotha");
}
return EL_STR("karonti");
return 0;
}
el_val_t pi_karoti_aorist(el_val_t slot) {
if (slot == 0) {
return EL_STR("ak\xc4\x81si\xe1\xb9\x83");
}
if (slot == 1) {
return EL_STR("ak\xc4\x81si");
}
if (slot == 2) {
return EL_STR("ak\xc4\x81si");
}
if (slot == 3) {
return EL_STR("ak\xc4\x81simh\xc4\x81");
}
if (slot == 4) {
return EL_STR("ak\xc4\x81sittha");
}
return EL_STR("ak\xc4\x81si\xe1\xb9\x83su");
return 0;
}
el_val_t pi_karoti_future(el_val_t slot) {
if (slot == 0) {
return EL_STR("kariss\xc4\x81mi");
}
if (slot == 1) {
return EL_STR("karissasi");
}
if (slot == 2) {
return EL_STR("karissati");
}
if (slot == 3) {
return EL_STR("kariss\xc4\x81ma");
}
if (slot == 4) {
return EL_STR("karissatha");
}
return EL_STR("karissanti");
return 0;
}
el_val_t pi_map_canonical(el_val_t verb) {
if (str_eq(verb, EL_STR("be"))) {
return EL_STR("hoti");
}
if (str_eq(verb, EL_STR("go"))) {
return EL_STR("gacchati");
}
if (str_eq(verb, EL_STR("see"))) {
return EL_STR("passati");
}
if (str_eq(verb, EL_STR("say"))) {
return EL_STR("vadati");
}
if (str_eq(verb, EL_STR("do"))) {
return EL_STR("karoti");
}
if (str_eq(verb, EL_STR("make"))) {
return EL_STR("karoti");
}
return verb;
return 0;
}
el_val_t pi_regular_root(el_val_t verb) {
if (pi_str_ends(verb, EL_STR("ati"))) {
return pi_drop(verb, 3);
}
if (pi_str_ends(verb, EL_STR("eti"))) {
return pi_drop(verb, 3);
}
return verb;
return 0;
}
el_val_t pi_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number) {
el_val_t v = pi_map_canonical(verb);
el_val_t slot = pi_slot(person, number);
if (str_eq(v, EL_STR("hoti"))) {
if (str_eq(tense, EL_STR("present"))) {
return pi_hoti_present(slot);
}
if (str_eq(tense, EL_STR("past"))) {
return pi_hoti_aorist(slot);
}
if (str_eq(tense, EL_STR("future"))) {
return pi_hoti_future(slot);
}
return v;
}
if (str_eq(v, EL_STR("atthi"))) {
if (str_eq(tense, EL_STR("present"))) {
return pi_atthi_present(slot);
}
if (str_eq(tense, EL_STR("past"))) {
return pi_hoti_aorist(slot);
}
if (str_eq(tense, EL_STR("future"))) {
return pi_hoti_future(slot);
}
return v;
}
if (str_eq(v, EL_STR("gacchati"))) {
if (str_eq(tense, EL_STR("present"))) {
return pi_gacchati_present(slot);
}
if (str_eq(tense, EL_STR("past"))) {
return pi_gacchati_aorist(slot);
}
if (str_eq(tense, EL_STR("future"))) {
return pi_gacchati_future(slot);
}
return v;
}
if (str_eq(v, EL_STR("passati"))) {
if (str_eq(tense, EL_STR("present"))) {
return pi_passati_present(slot);
}
if (str_eq(tense, EL_STR("past"))) {
return pi_passati_aorist(slot);
}
if (str_eq(tense, EL_STR("future"))) {
return pi_passati_future(slot);
}
return v;
}
if (str_eq(v, EL_STR("vadati"))) {
if (str_eq(tense, EL_STR("present"))) {
return pi_vadati_present(slot);
}
if (str_eq(tense, EL_STR("past"))) {
return pi_vadati_aorist(slot);
}
if (str_eq(tense, EL_STR("future"))) {
return pi_vadati_future(slot);
}
return v;
}
if (str_eq(v, EL_STR("karoti"))) {
if (str_eq(tense, EL_STR("present"))) {
return pi_karoti_present(slot);
}
if (str_eq(tense, EL_STR("past"))) {
return pi_karoti_aorist(slot);
}
if (str_eq(tense, EL_STR("future"))) {
return pi_karoti_future(slot);
}
return v;
}
el_val_t root = pi_regular_root(v);
if (str_eq(tense, EL_STR("present"))) {
return el_str_concat(root, pi_present_ending(slot));
}
if (str_eq(tense, EL_STR("past"))) {
return el_str_concat(root, pi_aorist_ending(slot));
}
if (str_eq(tense, EL_STR("future"))) {
return el_str_concat(root, pi_future_ending(slot));
}
return v;
return 0;
}
el_val_t pi_decline_a_masc_sg(el_val_t stem, el_val_t gram_case) {
if (str_eq(gram_case, EL_STR("nominative"))) {
return el_str_concat(stem, EL_STR("o"));
}
if (str_eq(gram_case, EL_STR("accusative"))) {
return el_str_concat(stem, EL_STR("\xe1\xb9\x83"));
}
if (str_eq(gram_case, EL_STR("instrumental"))) {
return el_str_concat(stem, EL_STR("ena"));
}
if (str_eq(gram_case, EL_STR("dative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81ya"));
}
if (str_eq(gram_case, EL_STR("ablative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81"));
}
if (str_eq(gram_case, EL_STR("genitive"))) {
return el_str_concat(stem, EL_STR("ssa"));
}
if (str_eq(gram_case, EL_STR("locative"))) {
return el_str_concat(stem, EL_STR("smi\xe1\xb9\x83"));
}
if (str_eq(gram_case, EL_STR("vocative"))) {
return stem;
}
return el_str_concat(stem, EL_STR("o"));
return 0;
}
el_val_t pi_decline_a_masc_pl(el_val_t stem, el_val_t gram_case) {
if (str_eq(gram_case, EL_STR("nominative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81"));
}
if (str_eq(gram_case, EL_STR("accusative"))) {
return el_str_concat(stem, EL_STR("e"));
}
if (str_eq(gram_case, EL_STR("instrumental"))) {
return el_str_concat(stem, EL_STR("ehi"));
}
if (str_eq(gram_case, EL_STR("dative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81na\xe1\xb9\x83"));
}
if (str_eq(gram_case, EL_STR("ablative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81na\xe1\xb9\x83"));
}
if (str_eq(gram_case, EL_STR("genitive"))) {
return el_str_concat(stem, EL_STR("\xc4\x81na\xe1\xb9\x83"));
}
if (str_eq(gram_case, EL_STR("locative"))) {
return el_str_concat(stem, EL_STR("esu"));
}
if (str_eq(gram_case, EL_STR("vocative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81"));
}
return el_str_concat(stem, EL_STR("\xc4\x81"));
return 0;
}
el_val_t pi_decline_a_fem_sg(el_val_t stem, el_val_t gram_case) {
if (str_eq(gram_case, EL_STR("nominative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81"));
}
if (str_eq(gram_case, EL_STR("accusative"))) {
return el_str_concat(stem, EL_STR("a\xe1\xb9\x83"));
}
if (str_eq(gram_case, EL_STR("instrumental"))) {
return el_str_concat(stem, EL_STR("\xc4\x81ya"));
}
if (str_eq(gram_case, EL_STR("dative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81ya"));
}
if (str_eq(gram_case, EL_STR("ablative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81ya"));
}
if (str_eq(gram_case, EL_STR("genitive"))) {
return el_str_concat(stem, EL_STR("\xc4\x81ya"));
}
if (str_eq(gram_case, EL_STR("locative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81ya\xe1\xb9\x83"));
}
if (str_eq(gram_case, EL_STR("vocative"))) {
return el_str_concat(stem, EL_STR("e"));
}
return el_str_concat(stem, EL_STR("\xc4\x81"));
return 0;
}
el_val_t pi_decline_a_fem_pl(el_val_t stem, el_val_t gram_case) {
if (str_eq(gram_case, EL_STR("nominative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81"));
}
if (str_eq(gram_case, EL_STR("accusative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81"));
}
if (str_eq(gram_case, EL_STR("instrumental"))) {
return el_str_concat(stem, EL_STR("\xc4\x81hi"));
}
if (str_eq(gram_case, EL_STR("dative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81na\xe1\xb9\x83"));
}
if (str_eq(gram_case, EL_STR("ablative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81na\xe1\xb9\x83"));
}
if (str_eq(gram_case, EL_STR("genitive"))) {
return el_str_concat(stem, EL_STR("\xc4\x81na\xe1\xb9\x83"));
}
if (str_eq(gram_case, EL_STR("locative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81su"));
}
if (str_eq(gram_case, EL_STR("vocative"))) {
return el_str_concat(stem, EL_STR("\xc4\x81"));
}
return el_str_concat(stem, EL_STR("\xc4\x81"));
return 0;
}
el_val_t pi_detect_class(el_val_t noun) {
if (pi_str_ends(noun, EL_STR("o"))) {
return EL_STR("a_masc");
}
if (pi_str_ends(noun, EL_STR("\xc4\x81"))) {
return EL_STR("a_fem");
}
if (pi_str_ends(noun, EL_STR("a"))) {
return EL_STR("a_masc");
}
return EL_STR("a_masc");
return 0;
}
el_val_t pi_decline(el_val_t noun, el_val_t gram_case, el_val_t number) {
el_val_t nclass = pi_detect_class(noun);
if (str_eq(nclass, EL_STR("a_masc"))) {
el_val_t stem = noun;
if (pi_str_ends(noun, EL_STR("o"))) {
stem = pi_drop(noun, 1);
}
if (pi_str_ends(noun, EL_STR("a"))) {
stem = pi_drop(noun, 1);
}
if (str_eq(number, EL_STR("singular"))) {
return pi_decline_a_masc_sg(stem, gram_case);
}
return pi_decline_a_masc_pl(stem, gram_case);
}
if (str_eq(nclass, EL_STR("a_fem"))) {
el_val_t stem = noun;
if (pi_str_ends(noun, EL_STR("\xc4\x81"))) {
stem = pi_drop(noun, 1);
}
if (str_eq(number, EL_STR("singular"))) {
return pi_decline_a_fem_sg(stem, gram_case);
}
return pi_decline_a_fem_pl(stem, gram_case);
}
return noun;
return 0;
}
el_val_t pi_noun_phrase(el_val_t noun, el_val_t gram_case, el_val_t number, el_val_t definite) {
return pi_decline(noun, gram_case, number);
return 0;
}