asSentence() public method

public asSentence ( ) : Sentence
return AIMA.Core.Logic.Propositional.Parsing.Ast.Sentence
示例#1
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());
 }
示例#2
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()));
        }
示例#3
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();
		}
	}
示例#4
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);
            }
        }
示例#5
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);
            }

        }