コード例 #1
0
        public bool PlfcEntails(KnowledgeBase kb, Symbol q)
        {
            IList <HornClause> hornClauses = this.AsHornClauses(kb.Sentences);

            while (agenda.Count != 0)
            {
                Symbol p = agenda.Pop();
                while (!this.GetInferred(p))
                {
                    this.inferred[p] = true;

                    foreach (HornClause hornClause in
                             hornClauses.Where(hornClause => hornClause.PremisesContainsSymbol(p)))
                    {
                        this.DecrementCount(hornClause);
                        if (!this.CountIsZero(hornClause))
                        {
                            continue;
                        }
                        if (hornClause.Head.Equals(q))
                        {
                            return(true);
                        }
                        this.agenda.Push(hornClause.Head);
                    }
                }
            }
            return(false);
        }
コード例 #2
0
        //TODO: create a better name
        public bool PlResolution(string kbs, string alphaString)
        {
            KnowledgeBase kb = new KnowledgeBase();

            kb.Tell(kbs);
            Sentence alpha = (Sentence) new PEParser().Parse(alphaString);

            return(this.PlResolution(kb, alpha));
        }
コード例 #3
0
        //TODO: Update this method with better name
        public bool TtEntails(KnowledgeBase kb, String alpha)
        {
            Sentence        kbSentence    = kb.AsSentence();
            Sentence        querySentence = (Sentence) new PEParser().Parse(alpha);
            SymbolCollector collector     = new SymbolCollector();
            ISet <Symbol>   kbSymbols     = collector.GetSymbolsIn(kbSentence);
            ISet <Symbol>   querySymbols  = collector.GetSymbolsIn(querySentence);
            IList <Symbol>  symbolList    = kbSymbols.Union(querySymbols).ToList();

            return(ttCheckAll(kbSentence, querySentence, symbolList, new Model()));
        }
コード例 #4
0
        public Sentence AsSentence()
        {
            ISet <Symbol> Asyms  = GetAssignedSymbols();
            KnowledgeBase tempKB = new KnowledgeBase();

            if (Asyms == null)
            {
                Console.WriteLine("ERR: AsSentence() Asyms is null!!!");
            }
            else
            {
                Console.WriteLine("DBG: Asyms.Count={0}", Asyms.Count);
            }
            foreach (Symbol k in Asyms)
            {
                try
                {
                    if (IsTrue(k))
                    {
                        tempKB.Tell("(" + k.Value + ")");
                    }
                    else
                    {
                        tempKB.Tell("(NOT " + k.Value + ")");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("ERR: AsSentence() ", e.Message, e.StackTrace);
                }
            }
            if (tempKB.Size() == 0)
            {
                Console.WriteLine("ERR: AsSentence() tempKB.Size==0");
            }
            return(tempKB.AsSentence());
        }
コード例 #5
0
        public bool PlResolution(KnowledgeBase kb, Sentence alpha)
        {
            Sentence kBAndNotAlpha = new BinarySentence("AND", kb.AsSentence(),
                                                        new UnarySentence(alpha));
            IList <Sentence> clauses = new CNFClauseGatherer()
                                       .GetClausesFrom(new CNFTransformer().Transform(kBAndNotAlpha)).ToList();

            clauses = this.FilterOutClausesWithTwoComplementaryLiterals(clauses);
            var newClauses = new List <Sentence>();

            while (true)
            {
                IList <IList <Sentence> > pairs = this.GetCombinationPairs(clauses.ToList());

                for (int i = 0; i < pairs.Count; i++)
                {
                    IList <Sentence> pair = pairs[i];
                    // System.out.println("pair number" + i+" of "+pairs.Count);
                    IList <Sentence> resolvents = this.PLResolve(pair[0], pair[1]);
                    resolvents = this.FilterOutClausesWithTwoComplementaryLiterals(resolvents);

                    if (resolvents.Contains(new Symbol("EMPTY_CLAUSE")))
                    {
                        return(true);
                    }
                    newClauses = newClauses.Union(resolvents).ToList();
                    // System.out.println("clauseslist size = " +clauses.Count);
                }
                if (newClauses.Intersect(clauses).Count() == newClauses.Count)
                {// subset test
                    return(false);
                }
                clauses = newClauses.Union(clauses).ToList();
                clauses = this.FilterOutClausesWithTwoComplementaryLiterals(clauses);
            }
        }
コード例 #6
0
 public bool PlResolution(KnowledgeBase kb, string alpha)
 {
     return(this.PlResolution(kb, (Sentence) new PEParser().Parse(alpha)));
 }
コード例 #7
0
 //TODO: update with better name
 public bool PlfcEntails(KnowledgeBase kb, string s)
 {
     return(this.PlfcEntails(kb, new Symbol(s)));
 }