AIMA.Core.Logic.FOL.CNFConverter.convertToCNF C# (CSharp) Метод

convertToCNF() публичный Метод

public convertToCNF ( Sentence aSentence ) : CNF
aSentence Sentence
Результат AIMA.Core.Logic.FOL.KB.Data.CNF
        public CNF convertToCNF(Sentence aSentence)
        {
            // I)mplications Out:
            Sentence implicationsOut = (Sentence)aSentence.accept(
                    new ImplicationsOut(), null);

            // N)egations In:
            Sentence negationsIn = (Sentence)implicationsOut.accept(
                    new NegationsIn(), null);

            // S)tandardize variables:
            // For sentences like:
            // (FORALL x P(x)) V (EXISTS x Q(x)),
            // which use the same variable name twice, change the name of one of the
            // variables.
            Sentence saQuantifiers = (Sentence)negationsIn.accept(
                    new StandardizeQuantiferVariables(substVisitor),
                    new List<Variable>());

            // Remove explicit quantifiers, by skolemizing existentials
            // and dropping universals:
            // E)xistentials Out
            // A)lls Out:
            Sentence andsAndOrs = (Sentence)saQuantifiers.accept(
                    new RemoveQuantifiers(parser), new List<Variable>());

            // D)istribution
            // V over ^:
            Sentence orDistributedOverAnd = (Sentence)andsAndOrs.accept(
                    new DistributeOrOverAnd(), null);

            // O)perators Out
            return (new CNFConstructor()).construct(orDistributedOverAnd);
        }
    }

Usage Example

        public void testDefaultClauseSimplifier()
        {
            FOLDomain domain = new FOLDomain();
            domain.addConstant("ZERO");
            domain.addConstant("ONE");
            domain.addPredicate("P");
            domain.addFunction("Plus");
            domain.addFunction("Power");

            FOLParser parser = new FOLParser(domain);

            List<TermEquality> rewrites = new List<TermEquality>();
            rewrites.Add((TermEquality)parser.parse("Plus(x, ZERO) = x"));
            rewrites.Add((TermEquality)parser.parse("Plus(ZERO, x) = x"));
            rewrites.Add((TermEquality)parser.parse("Power(x, ONE) = x"));
            rewrites.Add((TermEquality)parser.parse("Power(x, ZERO) = ONE"));
            DefaultClauseSimplifier simplifier = new DefaultClauseSimplifier(
                    rewrites);

            Sentence s1 = parser
                    .parse("((P(Plus(y,ZERO),Plus(ZERO,y)) OR P(Power(y, ONE),Power(y,ZERO))) OR P(Power(y,ZERO),Plus(y,ZERO)))");

            CNFConverter cnfConverter = new CNFConverter(parser);

            CNF cnf = cnfConverter.convertToCNF(s1);

            Assert.AreEqual(1, cnf.getNumberOfClauses());

            Clause simplified = simplifier.simplify(cnf.getConjunctionOfClauses()
                    [0]);

            Assert.AreEqual("[P(y,y), P(y,ONE), P(ONE,y)]", simplified
                    .ToString());
        }
All Usage Examples Of AIMA.Core.Logic.FOL.CNFConverter::convertToCNF