Examples of CNFConverter


Examples of aima.core.logic.fol.CNFConverter

    //
    this.substVisitor = new SubstVisitor();
    this.variableCollector = new VariableCollector();
    this.standardizeApart = new StandardizeApart(variableCollector,
        substVisitor);
    this.cnfConverter = new CNFConverter(parser);
  }
View Full Code Here

Examples of aima.core.logic.fol.CNFConverter

        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.assertEquals(1, cnf.getNumberOfClauses());

    Clause simplified = simplifier.simplify(cnf.getConjunctionOfClauses()
        .get(0));
View Full Code Here

Examples of aima.core.logic.fol.CNFConverter

    domain.addFunction("F");
    domain.addFunction("SF0");

    FOLParser parser = new FOLParser(domain);

    CNFConverter cnfConverter = new CNFConverter(parser);
    Sentence s1 = parser.parse("((x1 = y1 AND y1 = z1) => x1 = z1)");
    Sentence s2 = parser.parse("((x2 = y2 AND F(y2) = z2) => F(x2) = z2)");
    CNF cnf1 = cnfConverter.convertToCNF(s1);
    CNF cnf2 = cnfConverter.convertToCNF(s2);

    Clause c1 = cnf1.getConjunctionOfClauses().get(0);
    Clause c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertFalse(c1.equals(c2));

    s1 = parser.parse("((x1 = y1 AND y1 = z1) => x1 = z1)");
    s2 = parser.parse("((x2 = y2 AND y2 = z2) => x2 = z2)");
    cnf1 = cnfConverter.convertToCNF(s1);
    cnf2 = cnfConverter.convertToCNF(s2);

    c1 = cnf1.getConjunctionOfClauses().get(0);
    c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertTrue(c1.equals(c2));

    s1 = parser.parse("((x1 = y1 AND y1 = z1) => x1 = z1)");
    s2 = parser.parse("((y2 = z2 AND x2 = y2) => x2 = z2)");
    cnf1 = cnfConverter.convertToCNF(s1);
    cnf2 = cnfConverter.convertToCNF(s2);

    c1 = cnf1.getConjunctionOfClauses().get(0);
    c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertTrue(c1.equals(c2));

    s1 = parser.parse("(((x1 = y1 AND y1 = z1) AND z1 = r1) => x1 = r1)");
    s2 = parser.parse("(((x2 = y2 AND y2 = z2) AND z2 = r2) => x2 = r2)");
    cnf1 = cnfConverter.convertToCNF(s1);
    cnf2 = cnfConverter.convertToCNF(s2);

    c1 = cnf1.getConjunctionOfClauses().get(0);
    c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertTrue(c1.equals(c2));

    s1 = parser.parse("(((x1 = y1 AND y1 = z1) AND z1 = r1) => x1 = r1)");
    s2 = parser.parse("(((z2 = r2 AND y2 = z2) AND x2 = y2) => x2 = r2)");
    cnf1 = cnfConverter.convertToCNF(s1);
    cnf2 = cnfConverter.convertToCNF(s2);

    c1 = cnf1.getConjunctionOfClauses().get(0);
    c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertTrue(c1.equals(c2));

    s1 = parser.parse("(((x1 = y1 AND y1 = z1) AND z1 = r1) => x1 = r1)");
    s2 = parser.parse("(((x2 = y2 AND y2 = z2) AND z2 = y2) => x2 = r2)");
    cnf1 = cnfConverter.convertToCNF(s1);
    cnf2 = cnfConverter.convertToCNF(s2);

    c1 = cnf1.getConjunctionOfClauses().get(0);
    c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertFalse(c1.equals(c2));

    s1 = parser
        .parse("(((((x1 = y1 AND y1 = z1) AND z1 = r1) AND r1 = q1) AND q1 = s1) => x1 = r1)");
    s2 = parser
        .parse("(((((x2 = y2 AND y2 = z2) AND z2 = r2) AND r2 = q2) AND q2 = s2) => x2 = r2)");
    cnf1 = cnfConverter.convertToCNF(s1);
    cnf2 = cnfConverter.convertToCNF(s2);

    c1 = cnf1.getConjunctionOfClauses().get(0);
    c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertTrue(c1.equals(c2));

    s1 = parser
        .parse("((((NOT(Animal(c1920)) OR NOT(Animal(c1921))) OR NOT(Kills(c1922,c1920))) OR NOT(Kills(c1919,c1921))) OR NOT(Kills(SF0(c1922),SF0(c1919))))");
    s2 = parser
        .parse("((((NOT(Animal(c1929)) OR NOT(Animal(c1928))) OR NOT(Kills(c1927,c1929))) OR NOT(Kills(c1930,c1928))) OR NOT(Kills(SF0(c1930),SF0(c1927))))");
    cnf1 = cnfConverter.convertToCNF(s1);
    cnf2 = cnfConverter.convertToCNF(s2);

    c1 = cnf1.getConjunctionOfClauses().get(0);
    c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertTrue(c1.equals(c2));
View Full Code Here

Examples of aima.core.logic.fol.CNFConverter

    FOLParser parser = new FOLParser(domain);

    Sentence origSentence = parser
        .parse("FORALL x (FORALL y (Animal(y) => Loves(x, y)) => EXISTS y Loves(y, x))");

    CNFConverter cnfConv = new CNFConverter(parser);

    CNF cnf = cnfConv.convertToCNF(origSentence);

    System.out.println("Convert '" + origSentence + "' to CNF.");
    System.out.println("CNF=" + cnf.toString());
    System.out.println("");
  }
View Full Code Here

Examples of aima.core.logic.fol.CNFConverter

    //
    this.substVisitor = new SubstVisitor();
    this.variableCollector = new VariableCollector();
    this.standardizeApart = new StandardizeApart(variableCollector,
        substVisitor);
    this.cnfConverter = new CNFConverter(parser);
  }
View Full Code Here

Examples of aima.core.logic.fol.CNFConverter

    String sh = "FORALL v (will_wait(v) <=> (" + c1 + " OR (" + c2
        + " OR (" + c3 + " OR (" + c4 + ")))))";

    Sentence s = parser.parse(sh);

    CNFConverter cnfConv = new CNFConverter(parser);

    CNF cnf = cnfConv.convertToCNF(s);

    // Contains 9 duplicates
    Assert.assertEquals(40, cnf.getNumberOfClauses());

    Set<Clause> clauses = new HashSet<Clause>(cnf.getConjunctionOfClauses());

    // duplicates removed
    Assert.assertEquals(31, clauses.size());

    clauses.removeAll(SubsumptionElimination.findSubsumedClauses(clauses));

    // subsumed clauses removed
    Assert.assertEquals(8, clauses.size());

    // Ensure only the 8 correct/expected clauses remain
    Clause cl1 = cnfConv
        .convertToCNF(
            parser.parse("(NOT(will_wait(v)) OR (patrons(v,Full) OR patrons(v,Some)))"))
        .getConjunctionOfClauses().get(0);
    Clause cl2 = cnfConv
        .convertToCNF(
            parser.parse("(NOT(will_wait(v)) OR (hungry(v) OR patrons(v,Some)))"))
        .getConjunctionOfClauses().get(0);
    Clause cl3 = cnfConv
        .convertToCNF(
            parser.parse("(NOT(will_wait(v)) OR (patrons(v,Some) OR (type(v,Burger) OR (type(v,French) OR type(v,Thai)))))"))
        .getConjunctionOfClauses().get(0);
    Clause cl4 = cnfConv
        .convertToCNF(
            parser.parse("(NOT(will_wait(v)) OR (fri_sat(v) OR (patrons(v,Some) OR (type(v,Burger) OR type(v,French)))))"))
        .getConjunctionOfClauses().get(0);
    Clause cl5 = cnfConv
        .convertToCNF(
            parser.parse("(NOT(patrons(v,Some)) OR will_wait(v))"))
        .getConjunctionOfClauses().get(0);
    Clause cl6 = cnfConv
        .convertToCNF(
            parser.parse("(NOT(hungry(v)) OR (NOT(patrons(v,Full)) OR (NOT(type(v,French)) OR will_wait(v))))"))
        .getConjunctionOfClauses().get(0);
    Clause cl7 = cnfConv
        .convertToCNF(
            parser.parse("(NOT(fri_sat(v)) OR (NOT(hungry(v)) OR (NOT(patrons(v,Full)) OR (NOT(type(v,Thai)) OR will_wait(v)))))"))
        .getConjunctionOfClauses().get(0);
    Clause cl8 = cnfConv
        .convertToCNF(
            parser.parse("(NOT(hungry(v)) OR (NOT(patrons(v,Full)) OR (NOT(type(v,Burger)) OR will_wait(v))))"))
        .getConjunctionOfClauses().get(0);

    Assert.assertTrue(clauses.contains(cl1));
View Full Code Here

Examples of aima.core.logic.fol.CNFConverter

    FOLParser parser = new FOLParser(domain);

    Sentence origSentence = parser
        .parse("FORALL x ((((American(x) AND Weapon(y)) AND Sells(x, y, z)) AND Hostile(z)) => Criminal(x))");

    CNFConverter cnfConv = new CNFConverter(parser);

    CNF cnf = cnfConv.convertToCNF(origSentence);

    Assert.assertEquals(
        "[~American(x), ~Hostile(z), ~Sells(x,y,z), ~Weapon(y), Criminal(x)]",
        cnf.toString());
  }
View Full Code Here

Examples of aima.core.logic.fol.CNFConverter

    FOLParser parser = new FOLParser(domain);

    Sentence origSentence = parser
        .parse("FORALL x (FORALL y (Animal(y) => Loves(x, y)) => EXISTS y Loves(y, x))");

    CNFConverter cnfConv = new CNFConverter(parser);

    CNF cnf = cnfConv.convertToCNF(origSentence);

    Assert.assertEquals(
        "[Animal(SF0(x)), Loves(SF1(x),x)],[~Loves(x,SF0(x)), Loves(SF1(x),x)]",
        cnf.toString());
  }
View Full Code Here

Examples of aima.core.logic.fol.CNFConverter

    // FOL A.
    Sentence origSentence = parser
        .parse("FORALL x (FORALL y (Animal(y) => Loves(x, y)) => EXISTS y Loves(y, x))");

    CNFConverter cnfConv = new CNFConverter(parser);

    CNF cnf = cnfConv.convertToCNF(origSentence);

    // CNF A1. and A2.
    Assert.assertEquals(
        "[Animal(SF0(x)), Loves(SF1(x),x)],[~Loves(x,SF0(x)), Loves(SF1(x),x)]",
        cnf.toString());

    // FOL B.
    origSentence = parser
        .parse("FORALL x (EXISTS y (Animal(y) AND Kills(x, y)) => FORALL z NOT(Loves(z, x)))");

    cnf = cnfConv.convertToCNF(origSentence);

    // CNF B.
    Assert.assertEquals("[~Animal(y), ~Kills(x,y), ~Loves(z,x)]",
        cnf.toString());

    // FOL C.
    origSentence = parser.parse("FORALL x (Animal(x) => Loves(Jack, x))");

    cnf = cnfConv.convertToCNF(origSentence);

    // CNF C.
    Assert.assertEquals("[~Animal(x), Loves(Jack,x)]", cnf.toString());

    // FOL D.
    origSentence = parser
        .parse("(Kills(Jack, Tuna) OR Kills(Curiosity, Tuna))");

    cnf = cnfConv.convertToCNF(origSentence);

    // CNF D.
    Assert.assertEquals("[Kills(Curiosity,Tuna), Kills(Jack,Tuna)]",
        cnf.toString());

    // FOL E.
    origSentence = parser.parse("Cat(Tuna)");

    cnf = cnfConv.convertToCNF(origSentence);

    // CNF E.
    Assert.assertEquals("[Cat(Tuna)]", cnf.toString());

    // FOL F.
    origSentence = parser.parse("FORALL x (Cat(x) => Animal(x))");

    cnf = cnfConv.convertToCNF(origSentence);

    // CNF F.
    Assert.assertEquals("[~Cat(x), Animal(x)]", cnf.toString());

    // FOL G.
    origSentence = parser.parse("NOT(Kills(Curiosity, Tuna))");

    cnf = cnfConv.convertToCNF(origSentence);

    // CNF G.
    Assert.assertEquals("[~Kills(Curiosity,Tuna)]", cnf.toString());
  }
View Full Code Here

Examples of aima.core.logic.fol.CNFConverter

    FOLParser parser = new FOLParser(domain);

    Sentence origSentence = parser
        .parse("EXISTS w (FORALL x ( (EXISTS z (Q(w, z))) => (EXISTS y (NOT(P(x, y)) AND R(y))) ) )");

    CNFConverter cnfConv = new CNFConverter(parser);

    CNF cnf = cnfConv.convertToCNF(origSentence);

    Assert.assertEquals("[~P(x,SF0(x)), ~Q(SC0,z)],[~Q(SC0,z), R(SF0(x))]",
        cnf.toString());

    // Ax.Ay.(p(x,y) => Ez.(q(x,y,z)))
    origSentence = parser
        .parse("FORALL x1 (FORALL y1 (P(x1, y1) => EXISTS z1 (Q(x1, y1, z1))))");

    cnf = cnfConv.convertToCNF(origSentence);

    Assert.assertEquals("[~P(x1,y1), Q(x1,y1,SF1(x1,y1))]", cnf.toString());

    // Ex.Ay.Az.(r(y,z) <=> q(x,y,z))
    origSentence = parser
        .parse("EXISTS x2 (FORALL y2 (FORALL z2 (R(y2, z2) <=> Q(x2, y2, z2))))");

    cnf = cnfConv.convertToCNF(origSentence);

    Assert.assertEquals(
        "[~R(y2,z2), Q(SC1,y2,z2)],[~Q(SC1,y2,z2), R(y2,z2)]",
        cnf.toString());

    // Ax.Ey.(~p(x,y) => Az.(q(x,y,z)))
    origSentence = parser
        .parse("FORALL x3 (EXISTS y3 (NOT(P(x3, y3)) => FORALL z3 (Q(x3, y3, z3))))");

    cnf = cnfConv.convertToCNF(origSentence);

    Assert.assertEquals("[P(x3,SF2(x3)), Q(x3,SF2(x3),z3)]", cnf.toString());

    // Ew.Ex.Ey.Ez.(r(x,y) & q(x,w,z))
    origSentence = parser
        .parse("NOT(EXISTS w4 (EXISTS x4 (EXISTS y4 ( EXISTS z4 (R(x4, y4) AND Q(x4, w4, z4))))))");

    cnf = cnfConv.convertToCNF(origSentence);

    Assert.assertEquals("[~Q(x4,w4,z4), ~R(x4,y4)]", cnf.toString());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.