Warning: session_start(): open(/var/lib/php/sessions/sess_3o0ittd844vrr2ktugtcu51osi, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
sS data = [[
---- Rules
I ate pizza with a fork.
=> I used a fork to eat pizza.
I used a fork to eat pizza.
=> I used a fork.
I used a fork.
=> A fork is a tool.
I ate pizza with pepperoni.
=> {I ate pizza} and {the pizza had pepperoni on it}.
The pizza had pepperoni on it.
=> Pepperoni is edible.
I ate pizza with Bob.
=> {I ate pizza} and {Bob was with me}.
Bob was with me.
=> Bob is a person.
A and B.
=> A.
A and B.
=> B.
nicer wording for {is it true that {Mom is a person.}?} = {is Mom a person?}
nicer wording for {is it true that {Mom is edible.}?} = {is Mom edible?}
---- Input
I ate pizza with mom.
I ate pizza with anchovis.
I ate pizza with ducks.
I ate pizza with my hands.
]];
static Set incompatible = litciset("used/ate");
static int minScore = 50;
static LPair rules;
p-exp {
//set serverMechList_raw_fresh_verbose;
centerBigTTConsole();
S data = mapEachLine ai_groupSimplestNounPhrases(main.data);
SS sections = asCIMap(minusSignsSections(data));
LS rulesRaw = splitAtEmptyLines(sections.get("Rules"));
//pnl(rulesRaw);
rules = mapNonNulls splitAtDoubleArrow_pair(rulesRaw);
//pnlStruct(rules);
print();
LS inputs = tlft(sections.get("Input"));
for (S input : inputs) {
print(tok_dropCurlyBrackets(input) + "\n");
interpretRecursively(input, 3);
}
}
svoid interpretRecursively(S input, int level, bool newLines) {
if (level <= 0) ret;
L> interpretations = interpretations(input);
temp tempIndent();
for (Pair in : interpretations) {
printInterpretations(ll(in));
interpretRecursively(in.a, level-1, false);
if (newLines) print();
}
}
svoid printInterpretations(LPair interpretations) {
for (Pair p : interpretations)
print("Interpretation (score " + p.b + "%): " + ai_superSimpleVerbCorrector(tok_dropCurlyBrackets(p.a)));
}
static LS defaultParse(S s) {
ret codeTokens_lazy_uncurly(javaTokWithBrackets_cached(s));
}
static LPair interpretations(S input) {
new MultiSet ms;
LS tokI = defaultParse(input);
new L> interpretations;
for (PairS rule : rules) {
LS tokR = defaultParse(rule.a);
final SS map = ciMapWithoutKeysEqualToValues(zipTwoListsToCIMap_strict(tokR, tokI));
if (map == null) continue;
// Found matching rule
int score = l(tokR)-ai_mapPenaltyWithIncompatibleWordsList(map, incompatible, 1);
ms.add(rule, score+1);
//print(" " + reverseMapCI_joinDuplicatesWithPlus(map) + " | " + rule.a);
// Make consequence
S c = rule.b;
c = join(mapCodeTokens(javaTok(c), func(S s) -> S { getOrKeep_tryUncurlied(map, s) }));
// TODO: multiple grouping levels
c = join(mapCodeTokens(javaTokWithBrackets(c), func(S s) -> S { getOrKeep_tryUncurlied(map, s) }));
int percent = ratioToIntPercent(score, l(tokR));
if (percent >= minScore)
addPair(interpretations, c, percent);
}
ret sortByPairBDesc(interpretations);
}