svoid applyNLLogicFacts_v2(S input, VF1 postMessage) { new NLLogicChecker_v2 c; c.matcher = new NLStringMatcher_dollarVars; c.facts.addAll(mL("Random facts")); c.input = input; for (PairS idAndRule : combineWithGlobalIDs(splitAtEmptyLines(mL_raw("NL Logic Examples")))) pcall { S rule = idAndRule.b; NLLogicChecker_v2.Matching m = new NLLogicChecker_v2.Matching(); if (c.checkRule(nlLogic_parseRule(rule), m)) { print("Matched " + quote(input) + " with rule " + quote(rule)); printStruct(m.matches); new SS matches; // matches made in evaluating RHS of rule for (Exp out : m.output) for (Exp e : nlLogic_unrollAnd(out)) if (e cast Func) { if (eq(e.name, "output") && e.arg instanceof Sentence) callF(postMessage, replaceVars(nlLogic_text(e.arg), matches)); } else if (e cast Eq) { Exp r = e.right; S var = nlLogic_text(e.left); if (r cast Func) if (isStandardFunction(r.name) && r.arg instanceof Sentence && noJavaTokens(nlLogic_text(r.arg))) matches.put(var, str(callAndMake(r.name))); } } } }