Examples of CNFConverter


Examples of aima.core.logic.fol.CNFConverter

    domain.addPredicate("A");
    domain.addPredicate("Probation");
    domain.addPredicate("Award");

    FOLParser parser = new FOLParser(domain);
    CNFConverter cnfConv = new CNFConverter(parser);

    // cheat(x,y) => f(x,y)
    Sentence def1 = parser.parse("(Cheat(x,y) => F(x,y))");
    CNF cnfDef1 = cnfConv.convertToCNF(def1);

    Assert.assertEquals("[~Cheat(x,y), F(x,y)]", cnfDef1.toString());

    // extra(x,y) | knows(x) => a(x,y)
    Sentence def2 = parser.parse("((Extra(x,y) OR Knows(x)) => A(x,y))");
    CNF cnfDef2 = cnfConv.convertToCNF(def2);

    Assert.assertEquals("[~Extra(x,y), A(x,y)],[~Knows(x), A(x,y)]",
        cnfDef2.toString());

    // f(x,y) & f(x,z) & diff(y,z) <=> probation(x)
    Sentence def3 = parser
        .parse("(((NOT(((F(x,y) AND F(x,z)) AND Diff(y,z)))) OR Probation(x)) AND (((F(x,y) AND F(x,z)) AND Diff(y,z)) OR NOT(Probation(x))))");
    CNF cnfDef3 = cnfConv.convertToCNF(def3);

    Assert.assertEquals(
        "[~Diff(y,z), ~F(x,y), ~F(x,z), Probation(x)],[~Probation(x), F(x,y)],[~Probation(x), F(x,z)],[~Probation(x), Diff(y,z)]",
        cnfDef3.toString());

    // a(x,y) & a(x,z) & diff(y,z) <=> award(x)
    Sentence def4 = parser
        .parse("(((NOT(((A(x,y) AND A(x,z)) AND Diff(y,z)))) OR Award(x)) AND (((A(x,y) AND A(x,z)) AND Diff(y,z)) OR NOT(Award(x))))");
    CNF cnfDef4 = cnfConv.convertToCNF(def4);

    Assert.assertEquals(
        "[~A(x,y), ~A(x,z), ~Diff(y,z), Award(x)],[~Award(x), A(x,y)],[~Award(x), A(x,z)],[~Award(x), Diff(y,z)]",
        cnfDef4.toString());

    // f(x,y) <=> ~a(x,y)
    Sentence def5 = parser
        .parse("( ( NOT(F(x,y)) OR NOT(A(x,y))) AND ( F(x,y) OR NOT(NOT(A(x,y))) ) )");
    CNF cnfDef5 = cnfConv.convertToCNF(def5);

    Assert.assertEquals("[~A(x,y), ~F(x,y)],[A(x,y), F(x,y)]",
        cnfDef5.toString());
  }
View Full Code Here

Examples of aima.core.logic.fol.CNFConverter

    domain.addPredicate("Q");
    domain.addPredicate("R");
    domain.addConstant("A");

    FOLParser parser = new FOLParser(domain);
    CNFConverter cnfConv = new CNFConverter(parser);

    // ~(((~p or ~q) => ~(p or q)) => r)
    Sentence sent = parser
        .parse("NOT(((((NOT(P(A)) OR NOT(Q(A)))) => NOT((P(A) OR Q(A)))) => R(A)))");
    CNF cnf = cnfConv.convertToCNF(sent);

    Assert.assertEquals(
        "[~P(A), P(A)],[~P(A), Q(A)],[~Q(A), P(A)],[~Q(A), Q(A)],[~R(A)]",
        cnf.toString());
  }
View Full Code Here

Examples of aima.core.logic.fol.CNFConverter

    domain.addConstant("N");
    domain.addConstant("ONE");
    domain.addConstant("ZERO");

    FOLParser parser = new FOLParser(domain);
    CNFConverter cnfConv = new CNFConverter(parser);

    // Base Case:
    Sentence sent = parser
        .parse("NOT(FORALL x (FORALL y (Equal(Plus(Plus(x,y),ZERO), Plus(x,Plus(y,ZERO))))))");
    CNF cnf = cnfConv.convertToCNF(sent);
    Assert.assertEquals(
        "[~Equal(Plus(Plus(SC0,SC1),ZERO),Plus(SC0,Plus(SC1,ZERO)))]",
        cnf.toString());

    // Instance of Induction Axion Scmema
    sent = parser
        .parse("(("
            + "Equal(Plus(Plus(A,B),ZERO), Plus(A,Plus(B,ZERO)))"
            + " AND "
            + "(FORALL x (FORALL y (FORALL z("
            + "Equal(Plus(Plus(x,y),z), Plus(x,Plus(y,z)))"
            + " => "
            + "Equal(Plus(Plus(x,y),Plus(z,ONE)), Plus(x,Plus(y,Plus(z,ONE))))"
            + "))))" + ")" + " => "
            + "FORALL x (FORALL y (FORALL z("
            + "Equal(Plus(Plus(x,y),z), Plus(x,Plus(y,z)))"
            + "))))");
    cnf = cnfConv.convertToCNF(sent);
    Assert.assertEquals(
        "[~Equal(Plus(Plus(A,B),ZERO),Plus(A,Plus(B,ZERO))), Equal(Plus(Plus(q0,q1),q2),Plus(q0,Plus(q1,q2))), Equal(Plus(Plus(SC2,SC3),SC4),Plus(SC2,Plus(SC3,SC4)))],[~Equal(Plus(Plus(A,B),ZERO),Plus(A,Plus(B,ZERO))), ~Equal(Plus(Plus(SC2,SC3),Plus(SC4,ONE)),Plus(SC2,Plus(SC3,Plus(SC4,ONE)))), Equal(Plus(Plus(q0,q1),q2),Plus(q0,Plus(q1,q2)))]",
        cnf.toString());

    // Goal
    sent = parser
        .parse("NOT(FORALL x (FORALL y (FORALL z (Equal(Plus(Plus(x,y),z), Plus(x,Plus(y,z)))))))");
    cnf = cnfConv.convertToCNF(sent);
    Assert.assertEquals(
        "[~Equal(Plus(Plus(SC5,SC6),SC7),Plus(SC5,Plus(SC6,SC7)))]",
        cnf.toString());
  }
View Full Code Here

Examples of aima.core.logic.fol.CNFConverter

    domain.addFunction("Plus");
    domain.addConstant("ONE");
    domain.addConstant("ZERO");

    FOLParser parser = new FOLParser(domain);
    CNFConverter cnfConv = new CNFConverter(parser);

    // x=y
    Sentence sent = parser.parse("x = y");
    CNF cnf = cnfConv.convertToCNF(sent);

    Assert.assertEquals("[x = y]", cnf.toString());

    // x!=y
    sent = parser.parse("NOT(x = y)");
    cnf = cnfConv.convertToCNF(sent);

    Assert.assertEquals("[~x = y]", cnf.toString());

    // A=B
    sent = parser.parse("A = B");
    cnf = cnfConv.convertToCNF(sent);

    Assert.assertEquals("[A = B]", cnf.toString());

    // A!=B
    sent = parser.parse("NOT(A = B)");
    cnf = cnfConv.convertToCNF(sent);

    Assert.assertEquals("[~A = B]", cnf.toString());

    // ~(((~A=B or ~D=C) => ~(A=B or D=C)) => A=D)
    sent = parser
        .parse("NOT(((((NOT(A = B) OR NOT(D = C))) => NOT((A = B OR D = C))) => A = D))");
    cnf = cnfConv.convertToCNF(sent);

    Assert.assertEquals(
        "[~A = B, A = B],[~A = B, D = C],[~D = C, A = B],[~D = C, D = C],[~A = D]",
        cnf.toString());

    //
    // Induction Axiom Schema using Term Equality

    // Base Case:
    sent = parser
        .parse("NOT(FORALL x (FORALL y (Plus(Plus(x,y),ZERO) = Plus(x,Plus(y,ZERO)))))");
    cnf = cnfConv.convertToCNF(sent);
    Assert.assertEquals(
        "[~Plus(Plus(SC0,SC1),ZERO) = Plus(SC0,Plus(SC1,ZERO))]",
        cnf.toString());

    // Instance of Induction Axion Scmema
    sent = parser.parse("(("
        + "Plus(Plus(A,B),ZERO) = Plus(A,Plus(B,ZERO))" + " AND "
        + "(FORALL x (FORALL y (FORALL z("
        + "Plus(Plus(x,y),z) = Plus(x,Plus(y,z))" + " => "
        + "Plus(Plus(x,y),Plus(z,ONE)) = Plus(x,Plus(y,Plus(z,ONE)))"
        + "))))" + ")" + " => " + "FORALL x (FORALL y (FORALL z("
        + "Plus(Plus(x,y),z) = Plus(x,Plus(y,z))" + "))))");
    cnf = cnfConv.convertToCNF(sent);
    Assert.assertEquals(
        "[~Plus(Plus(A,B),ZERO) = Plus(A,Plus(B,ZERO)), Plus(Plus(q0,q1),q2) = Plus(q0,Plus(q1,q2)), Plus(Plus(SC2,SC3),SC4) = Plus(SC2,Plus(SC3,SC4))],[~Plus(Plus(A,B),ZERO) = Plus(A,Plus(B,ZERO)), ~Plus(Plus(SC2,SC3),Plus(SC4,ONE)) = Plus(SC2,Plus(SC3,Plus(SC4,ONE))), Plus(Plus(q0,q1),q2) = Plus(q0,Plus(q1,q2))]",
        cnf.toString());

    // Goal
    sent = parser
        .parse("NOT(FORALL x (FORALL y (FORALL z (Plus(Plus(x,y),z) = Plus(x,Plus(y,z))))))");
    cnf = cnfConv.convertToCNF(sent);
    Assert.assertEquals(
        "[~Plus(Plus(SC5,SC6),SC7) = Plus(SC5,Plus(SC6,SC7))]",
        cnf.toString());
  }
View Full Code Here

Examples of hampi.grammars.apps.CNFConverter

    Grammar g = new Parser(grammarFile).parse();
    assertTrue(!g.isCNF());

    List<Grammar> steps = new ArrayList<Grammar>();
    final String startSymbol = "FunctionDeclaration";
    Grammar gCNF = new CNFConverter().convertToCNF(g, startSymbol, steps);

    CYKParser p = new CYKParser(gCNF);
    String s = "function <IDENTIFIER_NAME> ( ) { break ; }";
    List<ParseTree> parse = p.parse(s.split(" "), startSymbol);
    assertTrue("cannot parse: " + s, !parse.isEmpty());
View Full Code Here

Examples of hampi.grammars.apps.CNFConverter

    Grammar g = new Parser(grammarFile).parse();
    assertTrue(!g.isCNF());

    List<Grammar> steps = new ArrayList<Grammar>();
    final String startSymbol = "FunctionDeclaration";
    Grammar gCNF = new CNFConverter().convertToCNF(g, startSymbol, steps);

    CYKParser p = new CYKParser(gCNF);
    String s = "function <IDENTIFIER_NAME> ( ) { break ; }";
    List<ParseTree> parse = p.parse(s.split(" "), startSymbol);
    assertTrue("cannot parse: " + s, !parse.isEmpty());
View Full Code Here

Examples of hampi.grammars.apps.CNFConverter

    Grammar g = new Parser(grammarFile).parse();
    assertTrue(!g.isCNF());

    List<Grammar> steps = new ArrayList<Grammar>();
    final String startSymbol = "FunctionDeclaration";
    Grammar gCNF = new CNFConverter().convertToCNF(g, startSymbol, steps);

    CYKParser p = new CYKParser(gCNF);
    String s = "break ; ";
    List<ParseTree> parse = p.parse(s.split(" "), startSymbol);
    assertTrue("cannot parse: " + s, !parse.isEmpty());
View Full Code Here

Examples of hampi.grammars.apps.CNFConverter

    Grammar g = new Parser(grammarFile).parse();
    assertTrue(!g.isCNF());

    List<Grammar> steps = new ArrayList<Grammar>();
    final String startSymbol = "FunctionDeclaration";
    Grammar gCNF = new CNFConverter().convertToCNF(g, startSymbol, steps);

    CYKParser p = new CYKParser(gCNF);
    String s = "function <IDENTIFIER_NAME> ( ) { -- <HEX_INTEGER_LITERAL> >= - <STRING_LITERAL> typeof true , false }";
    List<ParseTree> parse = p.parse(s.split(" "), startSymbol);
    for (ParseTree parseTree : parse){
View Full Code Here

Examples of hampi.grammars.apps.CNFConverter

    Grammar g = new Parser(grammarFile).parse();
    assertTrue(!g.isCNF());

    List<Grammar> steps = new ArrayList<Grammar>();
    final String startSymbol = "Statement";
    Grammar gCNF = new CNFConverter().convertToCNF(g, startSymbol, steps);

    CYKParser p = new CYKParser(gCNF);
    String s = "-- <HEX_INTEGER_LITERAL> >= - <STRING_LITERAL>";
    List<ParseTree> parse = p.parse(s.split(" "), startSymbol);
    for (ParseTree parseTree : parse){
View Full Code Here

Examples of hampi.grammars.apps.CNFConverter

    Grammar g = new Parser(grammarFile).parse();
    assertTrue(!g.isCNF());

    List<Grammar> steps = new ArrayList<Grammar>();
    final String startSymbol = "Expression";
    Grammar gCNF = new CNFConverter().convertToCNF(g, startSymbol, steps);

    CYKParser p = new CYKParser(gCNF);
    String s = "typeof true , false";
    List<ParseTree> parse = p.parse(s.split(" "), startSymbol);
    for (ParseTree parseTree : parse){
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.