public bool plResolution(String kbs, String alphaString) { KnowledgeBase kb = new KnowledgeBase(); kb.tell(kbs); Sentence alpha = (Sentence)new PEParser().parse(alphaString); return plResolution(kb, alpha); }
public bool plfcEntails(KnowledgeBase kb, Symbol q) { List<HornClause> hornClauses = asHornClauses(kb.getSentences()); while (agenda.Count != 0) { Symbol p = agenda.Pop(); while (!inferred(p)) { _inferred.Add(p, true); for (int i = 0; i < hornClauses.Count; i++) { HornClause hornClause = hornClauses[i]; if (hornClause.premisesContainsSymbol(p)) { decrementCount(hornClause); if (countisZero(hornClause)) { if (hornClause.head().Equals(q)) { return true; } else { agenda.Push(hornClause.head()); } } } } } } return false; }
public bool plfcEntails(KnowledgeBase kb, Symbol q) { List <HornClause> hornClauses = asHornClauses(kb.getSentences()); while (agenda.Count != 0) { Symbol p = agenda.Pop(); while (!inferred(p)) { _inferred.Add(p, true); for (int i = 0; i < hornClauses.Count; i++) { HornClause hornClause = hornClauses[i]; if (hornClause.premisesContainsSymbol(p)) { decrementCount(hornClause); if (countisZero(hornClause)) { if (hornClause.head().Equals(q)) { return(true); } else { agenda.Push(hornClause.head()); } } } } } } return(false); }
public bool plResolution(String kbs, String alphaString) { KnowledgeBase kb = new KnowledgeBase(); kb.tell(kbs); Sentence alpha = (Sentence) new PEParser().parse(alphaString); return(plResolution(kb, alpha)); }
public bool ttEntails(KnowledgeBase kb, String alpha) { Sentence kbSentence = kb.asSentence(); Sentence querySentence = (Sentence)new PEParser().parse(alpha); SymbolCollector collector = new SymbolCollector(); List<Symbol> kbSymbols = collector.getSymbolsIn(kbSentence); List<Symbol> querySymbols = collector.getSymbolsIn(querySentence); List<Symbol> symbols = SetOps.union(kbSymbols, querySymbols); List<Symbol> symbolList = symbols; return ttCheckAll(kbSentence, querySentence, symbolList, new Model()); }
public bool ttEntails(KnowledgeBase kb, String alpha) { Sentence kbSentence = kb.asSentence(); Sentence querySentence = (Sentence) new PEParser().parse(alpha); SymbolCollector collector = new SymbolCollector(); List <Symbol> kbSymbols = collector.getSymbolsIn(kbSentence); List <Symbol> querySymbols = collector.getSymbolsIn(querySentence); List <Symbol> symbols = SetOps.union(kbSymbols, querySymbols); List <Symbol> symbolList = symbols; return(ttCheckAll(kbSentence, querySentence, symbolList, new Model())); }
public void testAIMAExample() { KnowledgeBase kb = new KnowledgeBase(); kb.tell(" (P => Q)"); kb.tell("((L AND M) => P)"); kb.tell("((B AND L) => M)"); kb.tell("( (A AND P) => L)"); kb.tell("((A AND B) => L)"); kb.tell("(A)"); kb.tell("(B)"); Assert.AreEqual(true, plfce.plfcEntails(kb, "Q")); }
public void testAIMAExample() { KnowledgeBase kb = new KnowledgeBase(); kb.tell(" (P => Q)"); kb.tell("((L AND M) => P)"); kb.tell("((B AND L) => M)"); kb.tell("( (A AND P) => L)"); kb.tell("((A AND B) => L)"); kb.tell("(A)"); kb.tell("(B)"); WalkSAT walkSAT = new WalkSAT(); Model m = walkSAT.findModelFor(kb.asSentence().ToString(), 1000, 0.5); if (m == null) { System.Console.WriteLine("failure"); } else { m.print(); } }
public bool plResolution(KnowledgeBase kb, Sentence alpha) { Sentence kBAndNotAlpha = new BinarySentence("AND", kb.asSentence(), new UnarySentence(alpha)); List<Sentence> clauses = new CNFClauseGatherer() .getClausesFrom(new CNFTransformer().transform(kBAndNotAlpha)); clauses = filterOutClausesWithTwoComplementaryLiterals(clauses); List<Sentence> newClauses = new List<Sentence>(); while (true) { List<List<Sentence>> pairs = getCombinationPairs(clauses); for (int i = 0; i < pairs.Count; i++) { List<Sentence> pair = pairs[i]; // System.Console.WriteLine("pair number" + i+" of "+pairs.Count); List<Sentence> resolvents = plResolve(pair[0], pair[1]); resolvents = filterOutClausesWithTwoComplementaryLiterals(resolvents); if (resolvents.Contains(new Symbol("EMPTY_CLAUSE"))) { return true; } newClauses = SetOps.union(newClauses, resolvents); // System.Console.WriteLine("clauseslist size = " +clauses.Count); } if (SetOps.intersection(newClauses, clauses).Count == newClauses .Count) {// subset test return false; } clauses = SetOps.union(newClauses, clauses); clauses = filterOutClausesWithTwoComplementaryLiterals(clauses); } }
public bool plResolution(KnowledgeBase kb, Sentence alpha) { Sentence kBAndNotAlpha = new BinarySentence("AND", kb.asSentence(), new UnarySentence(alpha)); List <Sentence> clauses = new CNFClauseGatherer() .getClausesFrom(new CNFTransformer().transform(kBAndNotAlpha)); clauses = filterOutClausesWithTwoComplementaryLiterals(clauses); List <Sentence> newClauses = new List <Sentence>(); while (true) { List <List <Sentence> > pairs = getCombinationPairs(clauses); for (int i = 0; i < pairs.Count; i++) { List <Sentence> pair = pairs[i]; // System.Console.WriteLine("pair number" + i+" of "+pairs.Count); List <Sentence> resolvents = plResolve(pair[0], pair[1]); resolvents = filterOutClausesWithTwoComplementaryLiterals(resolvents); if (resolvents.Contains(new Symbol("EMPTY_CLAUSE"))) { return(true); } newClauses = SetOps.union(newClauses, resolvents); // System.Console.WriteLine("clauseslist size = " +clauses.Count); } if (SetOps.intersection(newClauses, clauses).Count == newClauses .Count) {// subset test return(false); } clauses = SetOps.union(newClauses, clauses); clauses = filterOutClausesWithTwoComplementaryLiterals(clauses); } }
public bool plResolution(KnowledgeBase kb, String alpha) { return(plResolution(kb, (Sentence) new PEParser().parse(alpha))); }
public void setUp() { kb = new KnowledgeBase(); }
public void testTTEntailsSucceedsWithChadCarffsBugReport() { KnowledgeBase kb = new KnowledgeBase(); kb.tell("(B12 <=> (P11 OR (P13 OR (P22 OR P02))))"); kb.tell("(B21 <=> (P20 OR (P22 OR (P31 OR P11))))"); kb.tell("(B01 <=> (P00 OR (P02 OR P11)))"); kb.tell("(B10 <=> (P11 OR (P20 OR P00)))"); kb.tell("(NOT B21)"); kb.tell("(NOT B12)"); kb.tell("(B10)"); kb.tell("(B01)"); Assert.IsTrue(kb.askWithTTEntails("(P00)")); Assert.IsFalse(kb.askWithTTEntails("(NOT P00)")); }
public void setUp() { tte = new TTEntails(); kb = new KnowledgeBase(); }
public void testDoesNotKnow() { KnowledgeBase kb = new KnowledgeBase(); kb.tell("A"); Assert.IsFalse(kb.askWithTTEntails("B")); Assert.IsFalse(kb.askWithTTEntails("(NOT B)")); }
public bool plResolution(KnowledgeBase kb, String alpha) { return plResolution(kb, (Sentence)new PEParser().parse(alpha)); }
public bool plfcEntails(KnowledgeBase kb, String s) { return plfcEntails(kb, new Symbol(s)); }
public void testMultipleClauseResolution() { // test (and fix) suggested by Huy Dinh. Thanks Huy! PLResolution plr = new PLResolution(); KnowledgeBase kb = new KnowledgeBase(); String fact = "((B11 <=> (P12 OR P21)) AND (NOT B11))"; kb.tell(fact); plr.plResolution(kb, "(B)"); }
public bool plfcEntails(KnowledgeBase kb, String s) { return(plfcEntails(kb, new Symbol(s))); }