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

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


        getKingPredicate(new Constant("Saladin"))));
  }

  @Test
  public void testQuantifiedSentenceWithSingleVariable() {
    Sentence qs = parser.parse("FORALL x  King(x)");
    List<Variable> vars = new ArrayList<Variable>();
    vars.add(new Variable("x"));
    Assert.assertEquals(qs, new QuantifiedSentence("FORALL", vars,
        getKingPredicate(new Variable("x"))));
  }
View Full Code Here


        getKingPredicate(new Variable("x"))));
  }

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

    Assert.assertEquals(qs, new QuantifiedSentence("EXISTS", vars, cse));
  }

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

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

  public Object visitQuantifiedSentence(QuantifiedSentence sentence,
      Object arg) {

    Map<Variable, Term> substitution = (Map<Variable, Term>) arg;

    Sentence quantified = sentence.getQuantified();
    Sentence quantifiedAfterSubs = (Sentence) quantified.accept(this, arg);

    List<Variable> variables = new ArrayList<Variable>();
    for (Variable v : sentence.getVariables()) {
      Term st = substitution.get(v);
      if (null != st) {
View Full Code Here

  }

  @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

  }

  @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.assertEquals(new Constant("John"), theta.get(var1)); // John
  }

  @Test
  public void testKnows1() {
    Sentence query = parser.parse("Knows(John,x)");
    Sentence johnKnowsJane = parser.parse("Knows(John,Jane)");
    Map<Variable, Term> result = unifier.unify(query, johnKnowsJane, theta);
    Assert.assertEquals(theta, result);
    Assert.assertTrue(theta.keySet().contains(new Variable("x"))); // x =
    Assert.assertEquals(new Constant("Jane"), theta.get(new Variable("x"))); // Jane
  }
View Full Code Here

    Assert.assertEquals(new Constant("Jane"), theta.get(new Variable("x"))); // Jane
  }

  @Test
  public void testKnows2() {
    Sentence query = parser.parse("Knows(John,x)");
    Sentence johnKnowsJane = parser.parse("Knows(y,Bill)");
    Map<Variable, Term> result = unifier.unify(query, johnKnowsJane, theta);

    Assert.assertEquals(2, result.size());

    Assert.assertEquals(new Constant("Bill"), theta.get(new Variable("x"))); // x
View Full Code Here

    // John
  }

  @Test
  public void testKnows3() {
    Sentence query = parser.parse("Knows(John,x)");
    Sentence johnKnowsJane = parser.parse("Knows(y,Mother(y))");
    Map<Variable, Term> result = unifier.unify(query, johnKnowsJane, theta);

    Assert.assertEquals(2, result.size());

    List<Term> terms = new ArrayList<Term>();
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.