// NewEngine takes facts which mix Java objects and sentence parts ("fragments") // e.g. ll(obj1, Fragment("leads to"), obj2) // short syntax: formatFrag("* leads to *", obj1, obj2) // rules contain the same kind of construct on lhs and rhs with // dollar variables (e.g. "$x", not as a Fragment) sclass NewEngine implements Steppable { replace LogicRule with BasicLogicRule. transient new Map facts; // facts to trail transient AllOnAllWithOperation rulesAndFacts = new(lambda2 applyLogicRuleToFact); new DeepZipTools tools; bool verbose = true, printNonMatches; public bool step() { ret rulesAndFacts.step(); } void addLogicRule(LogicRule rule) { rule = curryLHS_BasicLogicRule(rule); if (verbose) print("New rule: " + rule); rulesAndFacts.newA(rule); } void addFact(O fact) { addFact(fact, "external"); } void addFact(O fact, O trail) { if (trail == null) trail = "unknown"; if (facts.put(fact, trail) != null) ret; if (verbose) print("New fact: " + fact); rulesAndFacts.newB(fact); } void addFormattedFact(S starPattern, O... args) { addFact(formatWithFragments(starPattern, args)); } L factsInOrderOfDefinition() { ret rulesAndFacts.cloneBList(); } void run { stepAll(this); print("done. " + nFacts(rulesAndFacts.bList) + ", " + nRules(rulesAndFacts.aList)); } void think { run(); } void applyLogicRuleToFact(LogicRule rule, O fact) { new LogicRuleApplier ap; ap.rule = rule; ap.fact = fact; ap.verbose = verbose; ap.printNonMatches = printNonMatches; ap.addRewrittenRHS = lambda2 addRewrittenRHS; ap.tools = tools; ap.run(); } void addRewrittenRHS(O o, O trail) { if (o cast LogicRule) { o.trail = trail; addLogicRule(o); } else if o is And(O a, O b) { addRewrittenRHS(a, o); addRewrittenRHS(b, o); } else if (o != null) addFact(o, trail); } }