Warning: session_start(): open(/var/lib/php/sessions/sess_phms9c2ie8cfv4o96qfbufemtj, 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 NLLogicChecker_v2 {
S input;
new L facts;
StringMatcher matcher = new NLStringMatcher_noVars;
sclass Matching {
new LinkedHashMap matches; // var -> match
new L output;
}
bool checkRule(IfThen rule, Matching m) {
if (rule == null) false;
if (!checkExpression(rule.in, m)) false;
m.output.add(apply(rule.out, m));
true;
}
Exp apply(Exp e, Matching m) {
if (e == null) null;
if (e cast And)
ret And(apply(e.a, m), apply(e.b, m));
if (e cast Func) {
S s = join(((Sentence) e.arg).tok);
ret Func(e.name, Sentence(javaTok(matcher.apply(s, m.matches))));
}
ret e;
}
bool checkExpression(Exp e, Matching m) {
if (e cast And)
ret checkExpression(e.a, m) && checkExpression(e.b, m);
if (e cast Func) {
if (eq(e.name, "input"))
ret matcher.match(join(((Sentence) e.arg).tok), input, m.matches);
else if (eq(e.name, "fact")) {
S pat = join(((Sentence) e.arg).tok);
for (S fact : facts)
if (matcher.match(pat, fact, m.matches))
true;
}
}
false;
}
}