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

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


  public void testSubstWithUniversalQuantifierAndZeroVariablesMatched() {
    Sentence beforeSubst = parser.parse("FORALL x King(x))");
    Sentence expectedAfterSubst = parser.parse("FORALL x King(x)");

    Map<Variable, Term> p = new LinkedHashMap<Variable, Term>();
    p.put(new Variable("y"), new Constant("John"));

    Sentence afterSubst = sv.subst(p, beforeSubst);
    Assert.assertEquals(expectedAfterSubst, afterSubst);
    Assert.assertEquals(parser.parse("FORALL x King(x))"), beforeSubst);
  }
View Full Code Here


  public void testSubstWithUniversalQuantifierAndOneOfTwoVariablesMatched() {
    Sentence beforeSubst = parser.parse("FORALL x,y King(x,y))");
    Sentence expectedAfterSubst = parser.parse("FORALL x King(x,John)");

    Map<Variable, Term> p = new LinkedHashMap<Variable, Term>();
    p.put(new Variable("y"), new Constant("John"));

    Sentence afterSubst = sv.subst(p, beforeSubst);
    Assert.assertEquals(expectedAfterSubst, afterSubst);
    Assert.assertEquals(parser.parse("FORALL x,y King(x,y))"), beforeSubst);
  }
View Full Code Here

  public void testSubstWithExistentialQuantifierAndSngleVariable() {
    Sentence beforeSubst = parser.parse("EXISTS x King(x))");
    Sentence expectedAfterSubst = parser.parse("King(John)");

    Map<Variable, Term> p = new LinkedHashMap<Variable, Term>();
    p.put(new Variable("x"), new Constant("John"));

    Sentence afterSubst = sv.subst(p, beforeSubst);

    Assert.assertEquals(expectedAfterSubst, afterSubst);
    Assert.assertEquals(parser.parse("EXISTS x King(x)"), beforeSubst);
View Full Code Here

  public void testSubstWithNOTSentenceAndSngleVariable() {
    Sentence beforeSubst = parser.parse("NOT King(x))");
    Sentence expectedAfterSubst = parser.parse("NOT King(John)");

    Map<Variable, Term> p = new LinkedHashMap<Variable, Term>();
    p.put(new Variable("x"), new Constant("John"));

    Sentence afterSubst = sv.subst(p, beforeSubst);
    Assert.assertEquals(expectedAfterSubst, afterSubst);
    Assert.assertEquals(parser.parse("NOT King(x))"), beforeSubst);
  }
View Full Code Here

        .parse("EXISTS x ( King(x) AND BrotherOf(x) = EnemyOf(y) )");
    Sentence expectedAfterSubst = parser
        .parse("( King(John) AND BrotherOf(John) = EnemyOf(Saladin) )");

    Map<Variable, Term> p = new LinkedHashMap<Variable, Term>();
    p.put(new Variable("x"), new Constant("John"));
    p.put(new Variable("y"), new Constant("Saladin"));

    Sentence afterSubst = sv.subst(p, beforeSubst);
    Assert.assertEquals(expectedAfterSubst, afterSubst);
    Assert.assertEquals(parser
        .parse("EXISTS x ( King(x) AND BrotherOf(x) = EnemyOf(y) )"),
View Full Code Here

  public void testParanthisedSingleVariable() {
    Sentence beforeSubst = parser.parse("((( King(x))))");
    Sentence expectedAfterSubst = parser.parse("King(John) ");

    Map<Variable, Term> p = new LinkedHashMap<Variable, Term>();
    p.put(new Variable("x"), new Constant("John"));

    Sentence afterSubst = sv.subst(p, beforeSubst);
    Assert.assertEquals(expectedAfterSubst, afterSubst);
    Assert.assertEquals(parser.parse("((( King(x))))"), beforeSubst);
  }
View Full Code Here

  protected void testDefiniteClauseKBKingsQueryRichardEvilFalse(
      InferenceProcedure infp) {
    FOLKnowledgeBase kkb = FOLKnowledgeBaseFactory
        .createKingsKnowledgeBase(infp);
    List<Term> terms = new ArrayList<Term>();
    terms.add(new Constant("Richard"));
    Predicate query = new Predicate("Evil", terms);
    InferenceResult answer = kkb.ask(query);
    Assert.assertTrue(null != answer);
    Assert.assertTrue(answer.isPossiblyFalse());
    Assert.assertFalse(answer.isTrue());
View Full Code Here

  protected void testDefiniteClauseKBKingsQueryJohnEvilSucceeds(
      InferenceProcedure infp) {
    FOLKnowledgeBase kkb = FOLKnowledgeBaseFactory
        .createKingsKnowledgeBase(infp);
    List<Term> terms = new ArrayList<Term>();
    terms.add(new Constant("John"));
    Predicate query = new Predicate("Evil", terms);
    InferenceResult answer = kkb.ask(query);

    Assert.assertTrue(null != answer);
    Assert.assertFalse(answer.isPossiblyFalse());
View Full Code Here

    Assert.assertFalse(answer.isUnknownDueToTimeout());
    Assert.assertFalse(answer.isPartialResultDueToTimeout());
    Assert.assertTrue(1 == answer.getProofs().size());
    Assert.assertTrue(1 == answer.getProofs().get(0).getAnswerBindings()
        .size());
    Assert.assertEquals(new Constant("John"), answer.getProofs().get(0)
        .getAnswerBindings().get(new Variable("x")));
  }
View Full Code Here

    Assert.assertTrue(1 == answer.getProofs().get(1).getAnswerBindings()
        .size());

    boolean gotJohn, gotRichard;
    gotJohn = gotRichard = false;
    Constant cJohn = new Constant("John");
    Constant cRichard = new Constant("Richard");
    for (Proof p : answer.getProofs()) {
      Map<Variable, Term> ans = p.getAnswerBindings();
      Assert.assertEquals(1, ans.size());
      if (cJohn.equals(ans.get(new Variable("x")))) {
        gotJohn = true;
      }
      if (cRichard.equals(ans.get(new Variable("x")))) {
        gotRichard = true;
      }
    }
    Assert.assertTrue(gotJohn);
    Assert.assertTrue(gotRichard);
View Full Code Here

TOP

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

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.