public asSentence ( ) : |
||
return |
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)"); 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); } }