ELP: two-layer activation pipeline (activate → suppress → reason → generate)

elp-input.el: replace broken engram_search_json with engram_activate_json
as Layer 1. Layer 2 suppress/filter keeps nodes with non-zero salience/
importance. Reason step extracts patient from top activated node content.
ELP grammar realizes the response via generate().

routes.el: add 'elp' event_type to handle_dharma_recv so the studio can
route ELP requests through dharma.
This commit is contained in:
Will Anderson
2026-05-03 11:31:04 -05:00
parent e299c92662
commit 2622bb04bd
94 changed files with 52848 additions and 0 deletions
+401
View File
@@ -0,0 +1,401 @@
#include <stdint.h>
#include <stdlib.h>
#include "el_runtime.h"
el_val_t peo_drop(el_val_t s, el_val_t n);
el_val_t peo_ends(el_val_t s, el_val_t suf);
el_val_t peo_slot(el_val_t person, el_val_t number);
el_val_t peo_present_suffix(el_val_t slot);
el_val_t peo_past_suffix(el_val_t slot);
el_val_t peo_ah_present(el_val_t slot);
el_val_t peo_ah_past(el_val_t slot);
el_val_t peo_kar_present(el_val_t slot);
el_val_t peo_kar_past(el_val_t slot);
el_val_t peo_xsaya_present(el_val_t slot);
el_val_t peo_tar_present(el_val_t slot);
el_val_t peo_da_present(el_val_t slot);
el_val_t peo_da_past(el_val_t slot);
el_val_t peo_map_canonical(el_val_t verb);
el_val_t peo_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number);
el_val_t peo_decline_astem(el_val_t noun, el_val_t gram_case, el_val_t number);
el_val_t peo_decline(el_val_t noun, el_val_t gram_case, el_val_t number);
el_val_t peo_noun_phrase(el_val_t noun, el_val_t gram_case, el_val_t number, el_val_t definite);
el_val_t peo_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 peo_ends(el_val_t s, el_val_t suf) {
return str_ends_with(s, suf);
return 0;
}
el_val_t peo_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 peo_present_suffix(el_val_t slot) {
if (slot == 0) {
return EL_STR("\xc4\x81miy");
}
if (slot == 1) {
return EL_STR("ahiy");
}
if (slot == 2) {
return EL_STR("atiy");
}
if (slot == 3) {
return EL_STR("\xc4\x81mahy");
}
if (slot == 4) {
return EL_STR("\xc4\x81t\xc4\x81");
}
return EL_STR("antiy");
return 0;
}
el_val_t peo_past_suffix(el_val_t slot) {
if (slot == 0) {
return EL_STR("am");
}
if (slot == 1) {
return EL_STR("\xc4\x81");
}
if (slot == 2) {
return EL_STR("a");
}
if (slot == 3) {
return EL_STR("\xc4\x81m\xc4\x81");
}
if (slot == 4) {
return EL_STR("\xc4\x81t\xc4\x81");
}
return EL_STR("\xc4\x81");
return 0;
}
el_val_t peo_ah_present(el_val_t slot) {
if (slot == 0) {
return EL_STR("amiy");
}
if (slot == 1) {
return EL_STR("ahiy");
}
if (slot == 2) {
return EL_STR("astiy");
}
if (slot == 3) {
return EL_STR("amahy");
}
if (slot == 4) {
return EL_STR("ast\xc4\x81");
}
return EL_STR("hatiy");
return 0;
}
el_val_t peo_ah_past(el_val_t slot) {
if (slot == 0) {
return EL_STR("\xc4\x81ham");
}
if (slot == 1) {
return EL_STR("\xc4\x81ha");
}
if (slot == 2) {
return EL_STR("\xc4\x81ha");
}
if (slot == 3) {
return EL_STR("\xc4\x81hama");
}
if (slot == 4) {
return EL_STR("\xc4\x81hata");
}
return EL_STR("\xc4\x81han");
return 0;
}
el_val_t peo_kar_present(el_val_t slot) {
if (slot == 0) {
return EL_STR("kun\xc4\x81miy");
}
if (slot == 1) {
return EL_STR("kun\xc4\x81hiy");
}
if (slot == 2) {
return EL_STR("kunautiy");
}
if (slot == 3) {
return EL_STR("kun\xc4\x81mahy");
}
if (slot == 4) {
return EL_STR("kun\xc4\x81t\xc4\x81");
}
return EL_STR("kunavantiy");
return 0;
}
el_val_t peo_kar_past(el_val_t slot) {
if (slot == 0) {
return EL_STR("akunavam");
}
if (slot == 1) {
return EL_STR("akunav\xc4\x81");
}
if (slot == 2) {
return EL_STR("akunava");
}
if (slot == 3) {
return EL_STR("akunav\xc4\x81m\xc4\x81");
}
if (slot == 4) {
return EL_STR("akunav\xc4\x81t\xc4\x81");
}
return EL_STR("akunavan");
return 0;
}
el_val_t peo_xsaya_present(el_val_t slot) {
if (slot == 0) {
return EL_STR("x\xc5\xa1\xc4\x81y\xc4\x81miy");
}
if (slot == 1) {
return EL_STR("x\xc5\xa1\xc4\x81y\xc4\x81hiy");
}
if (slot == 2) {
return EL_STR("x\xc5\xa1\xc4\x81yatiy");
}
if (slot == 3) {
return EL_STR("x\xc5\xa1\xc4\x81y\xc4\x81mahy");
}
if (slot == 4) {
return EL_STR("x\xc5\xa1\xc4\x81y\xc4\x81t\xc4\x81");
}
return EL_STR("x\xc5\xa1\xc4\x81yantiy");
return 0;
}
el_val_t peo_tar_present(el_val_t slot) {
if (slot == 2) {
return EL_STR("taratiy");
}
if (slot == 5) {
return EL_STR("tarantiy");
}
return el_str_concat(EL_STR("tar"), peo_present_suffix(slot));
return 0;
}
el_val_t peo_da_present(el_val_t slot) {
if (slot == 0) {
return EL_STR("d\xc4\x81miy");
}
if (slot == 1) {
return EL_STR("d\xc4\x81hiy");
}
if (slot == 2) {
return EL_STR("d\xc4\x81tiy");
}
if (slot == 3) {
return EL_STR("d\xc4\x81mahy");
}
if (slot == 4) {
return EL_STR("d\xc4\x81t\xc4\x81");
}
return EL_STR("dantiy");
return 0;
}
el_val_t peo_da_past(el_val_t slot) {
if (slot == 0) {
return EL_STR("ad\xc4\x81m");
}
if (slot == 1) {
return EL_STR("ad\xc4\x81\xc4\x81");
}
if (slot == 2) {
return EL_STR("ad\xc4\x81");
}
if (slot == 3) {
return EL_STR("ad\xc4\x81m\xc4\x81");
}
if (slot == 4) {
return EL_STR("ad\xc4\x81t\xc4\x81");
}
return EL_STR("ad\xc4\x81n");
return 0;
}
el_val_t peo_map_canonical(el_val_t verb) {
if (str_eq(verb, EL_STR("be"))) {
return EL_STR("ah");
}
if (str_eq(verb, EL_STR("do"))) {
return EL_STR("kar");
}
if (str_eq(verb, EL_STR("make"))) {
return EL_STR("kar");
}
if (str_eq(verb, EL_STR("rule"))) {
return EL_STR("x\xc5\xa1\xc4\x81ya");
}
if (str_eq(verb, EL_STR("cross"))) {
return EL_STR("tar");
}
if (str_eq(verb, EL_STR("give"))) {
return EL_STR("d\xc4\x81");
}
return verb;
return 0;
}
el_val_t peo_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number) {
el_val_t v = peo_map_canonical(verb);
el_val_t slot = peo_slot(person, number);
if (str_eq(v, EL_STR("ah"))) {
if (str_eq(tense, EL_STR("present"))) {
return peo_ah_present(slot);
}
if (str_eq(tense, EL_STR("past"))) {
return peo_ah_past(slot);
}
return v;
}
if (str_eq(v, EL_STR("kar"))) {
if (str_eq(tense, EL_STR("present"))) {
return peo_kar_present(slot);
}
if (str_eq(tense, EL_STR("past"))) {
return peo_kar_past(slot);
}
return v;
}
if (str_eq(v, EL_STR("x\xc5\xa1\xc4\x81ya"))) {
if (str_eq(tense, EL_STR("present"))) {
return peo_xsaya_present(slot);
}
if (str_eq(tense, EL_STR("past"))) {
return el_str_concat(EL_STR("x\xc5\xa1\xc4\x81ya"), peo_past_suffix(slot));
}
return v;
}
if (str_eq(v, EL_STR("tar"))) {
if (str_eq(tense, EL_STR("present"))) {
return peo_tar_present(slot);
}
if (str_eq(tense, EL_STR("past"))) {
return el_str_concat(EL_STR("tar"), peo_past_suffix(slot));
}
return v;
}
if (str_eq(v, EL_STR("d\xc4\x81"))) {
if (str_eq(tense, EL_STR("present"))) {
return peo_da_present(slot);
}
if (str_eq(tense, EL_STR("past"))) {
return peo_da_past(slot);
}
return v;
}
if (str_eq(tense, EL_STR("present"))) {
return el_str_concat(v, peo_present_suffix(slot));
}
if (str_eq(tense, EL_STR("past"))) {
return el_str_concat(v, peo_past_suffix(slot));
}
return v;
return 0;
}
el_val_t peo_decline_astem(el_val_t noun, el_val_t gram_case, el_val_t number) {
if (str_eq(noun, EL_STR("dahyu"))) {
if (str_eq(number, EL_STR("singular"))) {
if (str_eq(gram_case, EL_STR("nominative"))) {
return EL_STR("dahy\xc4\x81u\xc5\xa1");
}
if (str_eq(gram_case, EL_STR("accusative"))) {
return EL_STR("dahyum");
}
if (str_eq(gram_case, EL_STR("genitive"))) {
return EL_STR("dahy\xc4\x81u\xc5\xa1");
}
if (str_eq(gram_case, EL_STR("dative"))) {
return EL_STR("dahyav\xc4\x81");
}
return EL_STR("dahy\xc4\x81u\xc5\xa1");
}
if (str_eq(gram_case, EL_STR("nominative"))) {
return EL_STR("dahy\xc4\x81va");
}
if (str_eq(gram_case, EL_STR("accusative"))) {
return EL_STR("dahy\xc5\xabn");
}
if (str_eq(gram_case, EL_STR("genitive"))) {
return EL_STR("dahy\xc5\xabn\xc4\x81m");
}
if (str_eq(gram_case, EL_STR("dative"))) {
return EL_STR("dahyubiy\xc4\x81");
}
return EL_STR("dahy\xc4\x81va");
}
if (str_eq(number, EL_STR("singular"))) {
if (str_eq(gram_case, EL_STR("nominative"))) {
return el_str_concat(noun, EL_STR("\xc4\x81u\xc5\xa1"));
}
if (str_eq(gram_case, EL_STR("accusative"))) {
return el_str_concat(noun, EL_STR("am"));
}
if (str_eq(gram_case, EL_STR("genitive"))) {
return el_str_concat(noun, EL_STR("\xc4\x81u\xc5\xa1"));
}
if (str_eq(gram_case, EL_STR("dative"))) {
return el_str_concat(noun, EL_STR("av\xc4\x81"));
}
return el_str_concat(noun, EL_STR("\xc4\x81u\xc5\xa1"));
}
if (str_eq(gram_case, EL_STR("nominative"))) {
return el_str_concat(noun, EL_STR("\xc4\x81va"));
}
if (str_eq(gram_case, EL_STR("accusative"))) {
return el_str_concat(noun, EL_STR("\xc5\xabn"));
}
if (str_eq(gram_case, EL_STR("genitive"))) {
return el_str_concat(noun, EL_STR("\xc5\xabn\xc4\x81m"));
}
if (str_eq(gram_case, EL_STR("dative"))) {
return el_str_concat(noun, EL_STR("ubiy\xc4\x81"));
}
return el_str_concat(noun, EL_STR("\xc4\x81va"));
return 0;
}
el_val_t peo_decline(el_val_t noun, el_val_t gram_case, el_val_t number) {
return peo_decline_astem(noun, gram_case, number);
return 0;
}
el_val_t peo_noun_phrase(el_val_t noun, el_val_t gram_case, el_val_t number, el_val_t definite) {
return peo_decline(noun, gram_case, number);
return 0;
}