Warning: session_start(): open(/var/lib/php/sessions/sess_0r9knavl1ueuh3ubmjlv8l9l1l, 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 RuleEngine1 {
int minScore = 50; // minimal percentage score for rule matching
LPair rules;
bool printMappings, printGroupedData, printRejectedVars;
Map> ruleVariables = new Map;
void addRules(S _rules) {
//_rules = mapEachLine ai_groupSimplestNounPhrases(_rules);
if (printGroupedData) print(_rules);
rules = ai_findDoubleArrowRulesAsPairs(_rules);
for (PairS rule : rules)
ruleVariables.put(rule, ai_wordsInBothSidesOfPair_uncurly(rule));
}
void processInput(S 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);
}
}
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);
}
}
LS defaultParse(S s) {
ret codeTokens_lazy_uncurly(javaTokWithBrackets_cached(s));
}
LPair interpretations(S input) {
LS tokI = defaultParse(input);
//print("Raw parse: " + tokI);
new LPair 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)-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);
if (score < minScore) continue;
// 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);
addPair(interpretations, c, ratioToIntPercent(score, l(tokR)));
}
ret interpretations;
}
S formatForUser(S s) {
ret ai_superSimpleVerbCorrector(tok_dropCurlyBrackets(s));
}
}