예제 #1
0
 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);
 }
예제 #2
0
        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;
        }
예제 #3
0
        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);
        }
예제 #4
0
        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));
        }
예제 #5
0
 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());
 }
예제 #6
0
        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()));
        }
예제 #7
0
        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"));
        }
예제 #8
0
	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();
		}
	}
예제 #9
0
        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);
            }

        }
예제 #10
0
        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);
            }
        }
예제 #11
0
 public bool plResolution(KnowledgeBase kb, String alpha)
 {
     return(plResolution(kb, (Sentence) new PEParser().parse(alpha)));
 }
예제 #12
0
 public void setUp()
 {
     kb = new KnowledgeBase();
 }
예제 #13
0
        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)"));
        }
예제 #14
0
 public void setUp()
 {
     tte = new TTEntails();
     kb = new KnowledgeBase();
 }
예제 #15
0
 public void testDoesNotKnow()
 {
     KnowledgeBase kb = new KnowledgeBase();
     kb.tell("A");
     Assert.IsFalse(kb.askWithTTEntails("B"));
     Assert.IsFalse(kb.askWithTTEntails("(NOT B)"));
 }
예제 #16
0
 public bool plResolution(KnowledgeBase kb, String alpha)
 {
     return plResolution(kb, (Sentence)new PEParser().parse(alpha));
 }
예제 #17
0
 public bool plfcEntails(KnowledgeBase kb, String s)
 {
     return plfcEntails(kb, new Symbol(s));
 }
예제 #18
0
 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)");
 }
예제 #19
0
 public bool plfcEntails(KnowledgeBase kb, String s)
 {
     return(plfcEntails(kb, new Symbol(s)));
 }