Warning: session_start(): open(/var/lib/php/sessions/sess_ooo2l7vav66i43vo9gpc4006i9, 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
abstract sclass CtxExpr {
abstract bool get(S s);
}
CtxExpr > CtxNeg {
CtxExpr e;
*() {}
*(CtxExpr *e) {}
bool get(S s) { ret !e.get(s); }
}
CtxExpr > CtxAnd {
CtxExpr a, b;
*() {}
*(CtxExpr *a, CtxExpr *b) {}
bool get(S s) { ret a.get(s) && b.get(s); }
}
CtxExpr > CtxOr {
CtxExpr a, b;
*() {}
*(CtxExpr *a, CtxExpr *b) {}
bool get(S s) { ret a.get(s) || b.get(s); }
}
concept Rule {
CtxRule1 source;
CtxExpr expr;
}
static new TreeMap regexpMacros;
static new TreeSet patterns;
p {
silentGC();
L rules = ctxFindRules(#1200000);
regexpMacros.putAll(ctxLoadRegexpMacros(#1200000));
//pnl(regexpMacros);
print("Found " + n(rules, "rules") + ", " + n(regexpMacros, "macros"));
for (CtxRule1 rule : rules) {
Explain e = explain(rule.text(), ctxParsingRules(), "rule");
if (e == null)
print("Bad rule: " + rule.text());
else {
cnew(Rule, source := rule, expr := ctxParseExpression(e.sub(1)));
}
}
evalRulesOnString("wie geht es dir");
save("patterns");
botSleep();
}
sS answer(S s) {
ret evalRulesOnString(s);
}
static S evalRulesOnString(S s) {
for (Rule rule) try {
if (rule.expr != null && rule.expr.get(s)) {
//print("Fire! " + rule.source.file);
print("Fire! " + rule.source.text());
}
} catch e {
printExplainTree(rule.explain);
rethrow(e);
}
ret "";
}
static CtxExpr ctxParseExpression(Explain exp) {
if (exp.is("bracket"))
ret ctxParseExpression(exp.sub(0));
if (exp.is("and"))
ret new CtxAnd(ctxParseExpression(exp.sub(0)),
ctxParseExpression(exp.sub(1)));
if (exp.is("or"))
ret new CtxOr(ctxParseExpression(exp.sub(0)),
ctxParseExpression(exp.sub(1)));
if (exp.is("neg"))
ret new CtxNeg(ctxParseExpression(exp.sub(0));
if (exp.is("quoted"))
ret new CtxRegexp(unquoteCtx(exp.tok().get(1)));
if (exp.singleEqualChild())
ret ctxParseExpression(exp.sub(0));
throw todo(exp.className());
}
sbool evalPattern(S pat, S input) {
if (empty(pat)) false; // XXX
pat = ctxExpandMacros(pat, regexpMacros);
//print("Pattern: " + pat);
print("Pattern length: " + l(pat));
patterns.add(pat);
ret regexpCtx(pat, input).find();
}