Package aima.core.logic.fol.parsing.ast

Examples of aima.core.logic.fol.parsing.ast.Sentence


    return new QuantifiedSentence(quantifier, variables, sentence);
  }

  private Sentence parseParanthizedSentence() {
    match("(");
    Sentence sen = parseSentence();
    while (binaryConnector(lookAhead(1))) {
      String connector = lookAhead(1).getText();
      consume();
      Sentence other = parseSentence();
      sen = new ConnectedSentence(connector, sen, other);
    }
    match(")");
    return sen; /* new ParanthizedSentence */

 
View Full Code Here


    return sentence;
  }

  public Object visitConnectedSentence(ConnectedSentence sentence, Object arg) {
    ArgData ad = (ArgData) arg;
    Sentence first = sentence.getFirst();
    Sentence second = sentence.getSecond();

    first.accept(this, arg);
    if (Connectors.isAND(sentence.getConnector())) {
      ad.clauses.add(new Clause());
    }
    second.accept(this, arg);

    return sentence;
  }
View Full Code Here

      renameSubstitution.put(var, v);
      reverseSubstitution.put(v, var);
    }

    Sentence standardized = substVisitor.subst(renameSubstitution,
        aSentence);

    return new StandardizeApartResult(aSentence, standardized,
        renameSubstitution, reverseSubstitution);
  }
View Full Code Here

  @Test
  public void testExamplePg295AIMA2e() {
    FOLDomain domain = DomainFactory.weaponsDomain();
    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);
View Full Code Here

  @Test
  public void testExamplePg296AIMA2e() {
    FOLDomain domain = DomainFactory.lovesAnimalDomain();
    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);
View Full Code Here

  public void testExamplesPg299AIMA2e() {
    FOLDomain domain = DomainFactory.lovesAnimalDomain();
    FOLParser parser = new FOLParser(domain);

    // 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);
View Full Code Here

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

    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);
View Full Code Here

    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

    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)]",
View Full Code Here

    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());
View Full Code Here

TOP

Related Classes of aima.core.logic.fol.parsing.ast.Sentence

Copyright © 2018 www.massapicom. 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.