public bool Ask(KnowledgeBase kb, string predicate) { switch (Procedure) { case PLInferenceProcedure.TTEntails: return(kb.askWithTTEntails(predicate)); case PLInferenceProcedure.PLFCEntails: return(new PLFCEntails().plfcEntails(kb, new PropositionSymbol(predicate))); case PLInferenceProcedure.Resolve: return(new PLResolution().plResolution(kb, (Sentence)parser.parse(predicate))); case PLInferenceProcedure.DPLLEntails: return(new DPLLSatisfiable().isEntailed(kb, (Sentence)parser.parse(predicate))); case PLInferenceProcedure.DPLLSatisfiable: return(new DPLLSatisfiable().dpllSatisfiable((Sentence)parser.parse(predicate))); case PLInferenceProcedure.WalkSatPredicate: return(new WalkSAT().walkSAT(ConvertToConjunctionOfClauses.convert((Sentence)parser.parse(predicate)).getClauses(), WalkSatProbability, WalkSatMaxFlips) != null); case PLInferenceProcedure.WalkSatKb: return(new WalkSAT().walkSAT(kb.asCNF(), WalkSatProbability, WalkSatMaxFlips) != null); default: throw new ArgumentOutOfRangeException(); } }
public void testCollectSymbolsFromComplexSentence() { Sentence sentence = (Sentence)parser.parse("(~B11 | P12 | P21) & (B11 | ~P12) & (B11 | ~P21)"); ISet <PropositionSymbol> s = SymbolCollector.getSymbolsFrom(sentence); Assert.AreEqual(3, s.Size()); Sentence b11 = parser.parse("B11"); Sentence p21 = parser.parse("P21"); Sentence p12 = parser.parse("P12"); Assert.IsTrue(s.Contains(b11 as PropositionSymbol)); Assert.IsTrue(s.Contains(p21 as PropositionSymbol)); Assert.IsTrue(s.Contains(p12 as PropositionSymbol)); }
public void testAIMAExample() { KnowledgeBase kb = new KnowledgeBase(); kb.tell("P => Q"); kb.tell("L & M => P"); kb.tell("B & L => M"); kb.tell("A & P => L"); kb.tell("A & B => L"); kb.tell("A"); kb.tell("B"); PropositionSymbol q = (PropositionSymbol)parser.parse("Q"); Assert.AreEqual(true, plfce.plfcEntails(kb, q)); }
public void testWalkSat() { WalkSAT walkSAT = new WalkSAT(); Model m = walkSAT.walkSAT(ConvertToConjunctionOfClauses.convert(parser.parse("A & B")) .getClauses(), 0.5, 1000); if (m == null) { System.Console.WriteLine("failure"); } else { m.print(); } }
public void testComplexSentence() { string p = "P"; string q = "Q"; m = m.union(new PropositionSymbol(p), true); m = m.union(new PropositionSymbol(q), false); Sentence sent = (Sentence)parser.parse("((P | Q) & (P => Q))"); Assert.IsFalse(m.isTrue(sent)); Assert.IsTrue(m.isFalse(sent)); Sentence sent2 = (Sentence)parser.parse("((P | Q) & (Q))"); Assert.IsFalse(m.isTrue(sent2)); Assert.IsTrue(m.isFalse(sent2)); }
/** * Returns the answer to the specified question using the TT-Entails * algorithm. * * @param queryString * a question to ASK the knowledge base * * @return the answer to the specified question using the TT-Entails * algorithm. */ public bool askWithTTEntails(string queryString) { PLParser parser = new PLParser(); Sentence alpha = parser.parse(queryString); return(new TTEntails().ttEntails(this, alpha)); }
static void displayResolutionResults(KnowledgeBase kb, string query) { PLParser parser = new PLParser(); System.Console.WriteLine("Running plResolution of query " + query + " on knowledgeBase gives " + plr.plResolution(kb, parser.parse(query))); }
public static void displayDPLLSatisfiableStatus(string query) { PLParser parser = new PLParser(); if (dpll.dpllSatisfiable(parser.parse(query))) { System.Console.WriteLine(query + " is (DPLL) satisfiable"); } else { System.Console.WriteLine(query + " is NOT (DPLL) satisfiable"); } }
public void setUp() { parser = new PLParser(); trueSentence = (Sentence)parser.parse("true"); falseSentence = (Sentence)parser.parse("false"); andSentence = (Sentence)parser.parse("(P & Q)"); orSentence = (Sentence)parser.parse("(P | Q)"); impliedSentence = (Sentence)parser.parse("(P => Q)"); biConditionalSentence = (Sentence)parser.parse("(P <=> Q)"); m = new Model(); }
public void testAtomicSentenceTrueParse() { sentence = parser.parse("true"); expected = prettyPrintF("True"); Assert.IsTrue(sentence.isPropositionSymbol()); Assert.AreEqual(expected, sentence.ToString()); sentence = parser.parse("(true)"); expected = prettyPrintF("True"); Assert.IsTrue(sentence.isPropositionSymbol()); Assert.AreEqual(expected, sentence.ToString()); sentence = parser.parse("((true))"); expected = prettyPrintF("True"); Assert.IsTrue(sentence.isPropositionSymbol()); Assert.AreEqual(expected, sentence.ToString()); }
/** * Adds the specified sentence to the knowledge base. * * @param aSentence * a fact to be added to the knowledge base. */ public void tell(string aSentence) { tell((Sentence)parser.parse(aSentence)); }
public void testDPLLReturnsTrueWhenAllClausesTrueInModel() { Model model = new Model(); model = model.union(new PropositionSymbol("A"), true).union( new PropositionSymbol("B"), true); Sentence sentence = parser.parse("A & B & (A | B)"); ISet <Clause> clauses = ConvertToConjunctionOfClauses.convert(sentence) .getClauses(); ICollection <PropositionSymbol> symbols = CollectionFactory.CreateQueue <PropositionSymbol>( SymbolCollector.getSymbolsFrom(sentence)); bool satisfiable = dpll.dpll(clauses, symbols, model); Assert.AreEqual(true, satisfiable); }
public void testSymbolTransform() { Sentence symbol = parser.parse("A"); ConjunctionOfClauses transformed = ConvertToConjunctionOfClauses.convert(symbol); Assert.AreEqual("{{A}}", transformed.ToString()); }
public void testPLResolveWithOneLiteralMatching() { Clause one = Util.first(ConvertToConjunctionOfClauses.convert(parser.parse("A | B")).getClauses()); Clause two = Util.first(ConvertToConjunctionOfClauses.convert(parser.parse("~B | C")).getClauses()); Clause expected = Util.first(ConvertToConjunctionOfClauses.convert(parser.parse("A | C")).getClauses()); ISet <Clause> resolvents = resolution.plResolve(one, two); Assert.AreEqual(1, resolvents.Size()); Assert.IsTrue(resolvents.Contains(expected)); }
public void testSymbolTransform() { Sentence symbol = parser.parse("A"); Sentence transformed = ConvertToCNF.convert(symbol); Assert.AreEqual("A", transformed.ToString()); }