Warning: session_start(): open(/var/lib/php/sessions/sess_5bk980slog9373dkv0mhuub8h2, 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
sclass Gazelle_MiniEngine1 {
int minScore = 50; // minimal percentage score for rule matching
bool printMappings, printGroupedData, printRejectedVars; // what to debug-print
F1 formatForUser = func(S s) -> S { ai_superSimpleVerbCorrector(tok_dropCurlyBrackets(s)) };
F1 parse = func(S s) -> LS { codeTokens_lazy_uncurly(javaTokWithBrackets_cached(s)) };
LPair rules;
Map> ruleVariables = new Map;
S formatForUser(S s) { ret callF(formatForUser, s); }
LS parse(S s) { ret callF(parse, s); }
// returns solutions
MultiMap run(S _data) {
S data = mapEachLine ai_groupSimplestNounPhrases(_data);
if (printGroupedData) print(data);
SS sections = asCIMap(minusSignsSections(data));
rules = ai_findDoubleArrowRulesAsPairs(sections.get("Rules"));
for (PairS rule : rules)
ruleVariables.put(rule, ai_wordsInBothSidesOfPair_uncurly(rule));
printAsciiHeading("REASONING");
new MultiMap solutions;
for (S input : tlft(sections.get("Input"))) {
print("\nInput: " + tok_dropCurlyBrackets(input));
temp tempIndent();
for (Pair in : interpretations(input)) {
print("\nInterpretation: " + formatForUser(in.a));
Set out = litciset();
interpretRecursively(in.a, 5, out);
if (!matchAny("fail", out))
solutions.put(input, in.a);
}
}
printAsciiHeading("RESULTS");
print(formatDoubleArrowPairs_horizontallyAligned(mapPairBoth(formatForUser, multiMapToPairs(solutions))));
ret solutions;
}
void interpretRecursively(S input, int level, Set out) {
if (level <= 0) ret;
LS interpretations = pairsA(interpretations(ai_groupSimplestNounPhrases(input)));
temp tempIndent();
for (S in : addAllAndReturnNew(out, interpretations)) {
print(" => " + formatForUser(in));
for (S s : lithashset(in, ai_superSimpleVerbCorrector(in)))
interpretRecursively(s, level-1, out);
}
}
LPair interpretations(S input) {
LS tokI = parse(input);
new LPair interpretations;
for (PairS rule : rules) {
LS tokR = parse(rule.a);
final SS map = ciMapWithoutKeysEqualToValues(zipTwoListsToCIMap_strict(tokR, tokI));
if (map == null) continue;
// Found matching rule
int score = l(tokR)-l(map);
L nonVars = withoutDollarVars(listMinusSet(keys(map), ruleVariables.get(rule)));
if (printRejectedVars && nempty(nonVars)) print("Rejected vars: " + nonVars);
if (nempty(nonVars)) score = 0;
if (printMappings) 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) }));
c = join(mapCodeTokens(javaTokWithBrackets(c), func(S s) -> S { getOrKeep_tryUncurlied(map, s) }));
//c = javaTokWithBrackets_recursiveTransform(func(S s) -> S { getOrKeep(map, s) }, c);
addPairIfBAtLeast(interpretations, c, ratioToIntPercent(score, l(tokR)), minScore);
}
ret interpretations;
}
}