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

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


  @Test
  public void testQuantifiedSentenceWithTwoVariables() {
    Sentence qs = parser
        .parse("EXISTS x,y  (King(x) AND BrotherOf(x) = y)");
    List<Variable> vars = new ArrayList<Variable>();
    vars.add(new Variable("x"));
    vars.add(new Variable("y"));
    ConnectedSentence cse = new ConnectedSentence("AND",
        getKingPredicate(new Variable("x")), new TermEquality(
            getBrotherOfFunction(new Variable("x")), new Variable(
                "y")));
    Assert.assertEquals(qs, new QuantifiedSentence("EXISTS", vars, cse));
  }
View Full Code Here


  @Test
  public void testQuantifiedSentenceWithPathologicalParanthising() {
    Sentence qs = parser
        .parse("(( (EXISTS x,y  (King(x) AND (BrotherOf(x) = y)) ) ))");
    List<Variable> vars = new ArrayList<Variable>();
    vars.add(new Variable("x"));
    vars.add(new Variable("y"));
    ConnectedSentence cse = new ConnectedSentence("AND",
        getKingPredicate(new Variable("x")), new TermEquality(
            getBrotherOfFunction(new Variable("x")), new Variable(
                "y")));
    Assert.assertEquals(qs, new QuantifiedSentence("EXISTS", vars, cse));
  }
View Full Code Here

  @Test
  public void testHashCode() {
    Term cons1 = new Constant("C1");
    Term cons2 = new Constant("C2");
    Term var1 = new Variable("v1");
    List<Term> pts1 = new ArrayList<Term>();
    List<Term> pts2 = new ArrayList<Term>();
    pts1.add(cons1);
    pts1.add(cons2);
    pts1.add(var1);
View Full Code Here

  @Test
  public void testSimpleEquals() {
    Term cons1 = new Constant("C1");
    Term cons2 = new Constant("C2");
    Term var1 = new Variable("v1");
    List<Term> pts1 = new ArrayList<Term>();
    List<Term> pts2 = new ArrayList<Term>();
    pts1.add(cons1);
    pts1.add(cons2);
    pts1.add(var1);
View Full Code Here

    c = c.getNonTrivialFactors().iterator().next();
    Literal p = c.getPositiveLiterals().get(0);
    Assert.assertEquals("P", p.getAtomicSentence().getSymbolicName());
    Function f = (Function) p.getAtomicSentence().getArgs().get(0);
    Assert.assertEquals("F", f.getFunctionName());
    Variable v = (Variable) f.getTerms().get(0);
    f = (Function) p.getAtomicSentence().getArgs().get(1);
    Assert.assertEquals("F", f.getFunctionName());
    Assert.assertEquals(v, f.getTerms().get(0));

    //
View Full Code Here

    theta = new Hashtable<Variable, Term>();
  }

  @Test
  public void testFailureIfThetaisNull() {
    Variable var = new Variable("x");
    Sentence sentence = parser.parse("Knows(x)");
    theta = null;
    Map<Variable, Term> result = unifier.unify(var, sentence, theta);
    Assert.assertNull(result);
  }
View Full Code Here

    Assert.assertNull(result);
  }

  @Test
  public void testUnificationFailure() {
    Variable var = new Variable("x");
    Sentence sentence = parser.parse("Knows(y)");
    theta = null;
    Map<Variable, Term> result = unifier.unify(var, sentence, theta);
    Assert.assertNull(result);
  }
View Full Code Here

    Assert.assertNull(result);
  }

  @Test
  public void testThetaPassedBackIfXEqualsYBothVariables() {
    Variable var1 = new Variable("x");
    Variable var2 = new Variable("x");

    theta.put(new Variable("dummy"), new Variable("dummy"));
    Map<Variable, Term> result = unifier.unify(var1, var2, theta);
    Assert.assertEquals(theta, result);
    Assert.assertEquals(1, theta.keySet().size());
    Assert.assertTrue(theta.containsKey(new Variable("dummy")));
  }
View Full Code Here

    Assert.assertTrue(theta.containsKey(new Variable("dummy")));
  }

  @Test
  public void testVariableEqualsConstant() {
    Variable var1 = new Variable("x");
    Constant constant = new Constant("John");

    Map<Variable, Term> result = unifier.unify(var1, constant, theta);
    Assert.assertEquals(theta, result);
    Assert.assertEquals(1, theta.keySet().size());
View Full Code Here

    Assert.assertEquals(constant, theta.get(var1));
  }

  @Test
  public void testSimpleVariableUnification() {
    Variable var1 = new Variable("x");
    List<Term> terms1 = new ArrayList<Term>();
    terms1.add(var1);
    Predicate p1 = new Predicate("King", terms1); // King(x)

    List<Term> terms2 = new ArrayList<Term>();
    terms2.add(new Constant("John"));
    Predicate p2 = new Predicate("King", terms2); // King(John)

    Map<Variable, Term> result = unifier.unify(p1, p2, theta);
    Assert.assertEquals(theta, result);
    Assert.assertEquals(1, theta.keySet().size());
    Assert.assertTrue(theta.keySet().contains(new Variable("x"))); // x =
    Assert.assertEquals(new Constant("John"), theta.get(var1)); // John
  }
View Full Code Here

TOP

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

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.