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

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


  @Test
  public void testIsHornClause() {
    Clause c1 = new Clause();
    Assert.assertFalse(c1.isHornClause());

    c1.addNegativeLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    Assert.assertTrue(c1.isHornClause());

    c1.addPositiveLiteral(new Predicate("Pred2", new ArrayList<Term>()));
    Assert.assertTrue(c1.isHornClause());

    c1.addNegativeLiteral(new Predicate("Pred3", new ArrayList<Term>()));
    Assert.assertTrue(c1.isHornClause());
    c1.addNegativeLiteral(new Predicate("Pred4", new ArrayList<Term>()));
    Assert.assertTrue(c1.isHornClause());

    c1.addPositiveLiteral(new Predicate("Pred5", new ArrayList<Term>()));
    Assert.assertFalse(c1.isHornClause());
  }
View Full Code Here


  @Test
  public void testIsDefiniteClause() {
    Clause c1 = new Clause();
    Assert.assertFalse(c1.isDefiniteClause());

    c1.addNegativeLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    Assert.assertFalse(c1.isDefiniteClause());

    c1.addPositiveLiteral(new Predicate("Pred2", new ArrayList<Term>()));
    Assert.assertTrue(c1.isDefiniteClause());

    c1.addNegativeLiteral(new Predicate("Pred3", new ArrayList<Term>()));
    Assert.assertTrue(c1.isDefiniteClause());
    c1.addNegativeLiteral(new Predicate("Pred4", new ArrayList<Term>()));
    Assert.assertTrue(c1.isDefiniteClause());

    c1.addPositiveLiteral(new Predicate("Pred5", new ArrayList<Term>()));
    Assert.assertFalse(c1.isDefiniteClause());
  }
View Full Code Here

  @Test
  public void testIsUnitClause() {
    Clause c1 = new Clause();
    Assert.assertFalse(c1.isUnitClause());

    c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    Assert.assertTrue(c1.isUnitClause());

    c1.addPositiveLiteral(new Predicate("Pred2", new ArrayList<Term>()));
    Assert.assertFalse(c1.isUnitClause());

    c1 = new Clause();
    Assert.assertFalse(c1.isUnitClause());

    c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    Assert.assertTrue(c1.isUnitClause());

    c1.addNegativeLiteral(new Predicate("Pred2", new ArrayList<Term>()));
    Assert.assertFalse(c1.isUnitClause());

    c1 = new Clause();
    Assert.assertFalse(c1.isUnitClause());

    c1.addNegativeLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    Assert.assertTrue(c1.isUnitClause());

    c1.addPositiveLiteral(new Predicate("Pred2", new ArrayList<Term>()));
    Assert.assertFalse(c1.isUnitClause());
  }
View Full Code Here

  @Test
  public void testIsImplicationDefiniteClause() {
    Clause c1 = new Clause();
    Assert.assertFalse(c1.isImplicationDefiniteClause());

    c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    Assert.assertFalse(c1.isImplicationDefiniteClause());

    c1.addNegativeLiteral(new Predicate("Pred2", new ArrayList<Term>()));
    Assert.assertTrue(c1.isImplicationDefiniteClause());
    c1.addNegativeLiteral(new Predicate("Pred3", new ArrayList<Term>()));
    Assert.assertTrue(c1.isImplicationDefiniteClause());

    c1.addPositiveLiteral(new Predicate("Pred4", new ArrayList<Term>()));
    Assert.assertFalse(c1.isImplicationDefiniteClause());
  }
View Full Code Here

    Assert.assertNotNull(c1.binaryResolvents(c1));
    Assert.assertEquals(1, c1.binaryResolvents(c1).size());
    Assert.assertTrue(c1.binaryResolvents(c1).iterator().next().isEmpty());

    // Check if resolve with self to an empty clause
    c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    c1.addNegativeLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    Assert.assertNotNull(c1.binaryResolvents(c1));
    Assert.assertEquals(1, c1.binaryResolvents(c1).size());
    // i.e. resolving a tautology with a tautology gives you
    // back a tautology.
    Assert.assertEquals("[~Pred1(), Pred1()]", c1.binaryResolvents(c1)
        .iterator().next().toString());

    // Check if try to resolve with self and no resolvents
    c1 = new Clause();
    c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    Assert.assertEquals(0, c1.binaryResolvents(c1).size());

    c1 = new Clause();
    Clause c2 = new Clause();
    // Ensure that two empty clauses resolve to an empty clause
    Assert.assertNotNull(c1.binaryResolvents(c2));
    Assert.assertEquals(1, c1.binaryResolvents(c2).size());
    Assert.assertTrue(c1.binaryResolvents(c2).iterator().next().isEmpty());
    Assert.assertNotNull(c2.binaryResolvents(c1));
    Assert.assertEquals(1, c2.binaryResolvents(c1).size());
    Assert.assertTrue(c2.binaryResolvents(c1).iterator().next().isEmpty());

    // Enusre the two complementary clauses resolve
    // to the empty clause
    c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    c2.addNegativeLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    Assert.assertNotNull(c1.binaryResolvents(c2));
    Assert.assertEquals(1, c1.binaryResolvents(c2).size());
    Assert.assertTrue(c1.binaryResolvents(c2).iterator().next().isEmpty());
    Assert.assertNotNull(c2.binaryResolvents(c1));
    Assert.assertEquals(1, c2.binaryResolvents(c1).size());
    Assert.assertTrue(c2.binaryResolvents(c1).iterator().next().isEmpty());

    // Ensure that two clauses that have two complementaries
    // resolve with two resolvents
    c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    c2.addNegativeLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    c1.addPositiveLiteral(new Predicate("Pred2", new ArrayList<Term>()));
    c2.addNegativeLiteral(new Predicate("Pred2", new ArrayList<Term>()));
    Assert.assertNotNull(c1.binaryResolvents(c2));
    Assert.assertEquals(2, c1.binaryResolvents(c2).size());
    Assert.assertNotNull(c2.binaryResolvents(c1));
    Assert.assertEquals(2, c2.binaryResolvents(c1).size());

    // Ensure two clauses that factor are not
    // considered resolved
    c1 = new Clause();
    c2 = new Clause();
    c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    c1.addPositiveLiteral(new Predicate("Pred2", new ArrayList<Term>()));
    c1.addNegativeLiteral(new Predicate("Pred3", new ArrayList<Term>()));
    c1.addNegativeLiteral(new Predicate("Pred4", new ArrayList<Term>()));
    c2.addPositiveLiteral(new Predicate("Pred2", new ArrayList<Term>()));
    c2.addNegativeLiteral(new Predicate("Pred4", new ArrayList<Term>()));
    Assert.assertNotNull(c1.binaryResolvents(c2));
    Assert.assertEquals(0, c1.binaryResolvents(c2).size());
    Assert.assertNotNull(c2.binaryResolvents(c1));
    Assert.assertEquals(0, c2.binaryResolvents(c1).size());

    // Ensure the resolvent is a subset of the originals
    c1 = new Clause();
    c2 = new Clause();
    c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    c1.addNegativeLiteral(new Predicate("Pred2", new ArrayList<Term>()));
    c1.addNegativeLiteral(new Predicate("Pred3", new ArrayList<Term>()));
    c2.addPositiveLiteral(new Predicate("Pred2", new ArrayList<Term>()));
    Assert.assertNotNull(c1.binaryResolvents(c2));
    Assert.assertNotNull(c2.binaryResolvents(c1));
    Assert.assertEquals(1, c1.binaryResolvents(c2).iterator().next()
        .getNumberPositiveLiterals());
    Assert.assertEquals(1, c1.binaryResolvents(c2).iterator().next()
View Full Code Here

    Clause c1 = new Clause();
    Clause c2 = new Clause();
    Assert.assertEquals(c1.hashCode(), c2.hashCode());

    c1.addNegativeLiteral(new Predicate("Pred1", pts1));
    Assert.assertNotSame(c1.hashCode(), c2.hashCode());
    c2.addNegativeLiteral(new Predicate("Pred1", pts1));
    Assert.assertEquals(c1.hashCode(), c2.hashCode());

    c1.addPositiveLiteral(new Predicate("Pred1", pts1));
    Assert.assertNotSame(c1.hashCode(), c2.hashCode());
    c2.addPositiveLiteral(new Predicate("Pred1", pts1));
    Assert.assertEquals(c1.hashCode(), c2.hashCode());
  }
View Full Code Here

    Assert.assertTrue(c2.equals(c2));
    Assert.assertTrue(c1.equals(c2));
    Assert.assertTrue(c2.equals(c1));

    // Check negatives
    c1.addNegativeLiteral(new Predicate("Pred1", pts1));
    Assert.assertFalse(c1.equals(c2));
    Assert.assertFalse(c2.equals(c1));
    c2.addNegativeLiteral(new Predicate("Pred1", pts1));
    Assert.assertTrue(c1.equals(c2));
    Assert.assertTrue(c2.equals(c1));

    c1.addNegativeLiteral(new Predicate("Pred2", pts2));
    Assert.assertFalse(c1.equals(c2));
    Assert.assertFalse(c2.equals(c1));
    c2.addNegativeLiteral(new Predicate("Pred2", pts2));
    Assert.assertTrue(c1.equals(c2));
    Assert.assertTrue(c2.equals(c1));
    // Check same but added in different order
    c1.addNegativeLiteral(new Predicate("Pred3", pts1));
    Assert.assertFalse(c1.equals(c2));
    Assert.assertFalse(c2.equals(c1));
    c1.addNegativeLiteral(new Predicate("Pred4", pts1));
    Assert.assertFalse(c1.equals(c2));
    Assert.assertFalse(c2.equals(c1));
    c2.addNegativeLiteral(new Predicate("Pred4", pts1));
    Assert.assertFalse(c1.equals(c2));
    Assert.assertFalse(c2.equals(c1));
    c2.addNegativeLiteral(new Predicate("Pred3", pts1));
    Assert.assertTrue(c1.equals(c2));
    Assert.assertTrue(c2.equals(c1));

    // Check positives
    c1.addPositiveLiteral(new Predicate("Pred1", pts1));
    Assert.assertFalse(c1.equals(c2));
    Assert.assertFalse(c2.equals(c1));
    c2.addPositiveLiteral(new Predicate("Pred1", pts1));
    Assert.assertTrue(c1.equals(c2));
    Assert.assertTrue(c2.equals(c1));

    c1.addPositiveLiteral(new Predicate("Pred2", pts2));
    Assert.assertFalse(c1.equals(c2));
    Assert.assertFalse(c2.equals(c1));
    c2.addPositiveLiteral(new Predicate("Pred2", pts2));
    Assert.assertTrue(c1.equals(c2));
    Assert.assertTrue(c2.equals(c1));
    // Check same but added in different order
    c1.addPositiveLiteral(new Predicate("Pred3", pts1));
    Assert.assertFalse(c1.equals(c2));
    Assert.assertFalse(c2.equals(c1));
    c1.addPositiveLiteral(new Predicate("Pred4", pts1));
    Assert.assertFalse(c1.equals(c2));
    Assert.assertFalse(c2.equals(c1));
    c2.addPositiveLiteral(new Predicate("Pred4", pts1));
    Assert.assertFalse(c1.equals(c2));
    Assert.assertFalse(c2.equals(c1));
    c2.addPositiveLiteral(new Predicate("Pred3", pts1));
    Assert.assertTrue(c1.equals(c2));
    Assert.assertTrue(c2.equals(c1));
  }
View Full Code Here

  public void testIsEmpty() {
    Chain c = new Chain();

    Assert.assertTrue(c.isEmpty());

    c.addLiteral(new Literal(new Predicate("P", new ArrayList<Term>())));

    Assert.assertFalse(c.isEmpty());

    List<Literal> lits = new ArrayList<Literal>();

    lits.add(new Literal(new Predicate("P", new ArrayList<Term>())));

    c = new Chain(lits);

    Assert.assertFalse(c.isEmpty());
  }
View Full Code Here

  }

  @Test
  public void testContrapositives() {
    List<Chain> conts;
    Literal p = new Literal(new Predicate("P", new ArrayList<Term>()));
    Literal notq = new Literal(new Predicate("Q", new ArrayList<Term>()),
        true);
    Literal notr = new Literal(new Predicate("R", new ArrayList<Term>()),
        true);

    Chain c = new Chain();

    conts = c.getContrapositives();
View Full Code Here

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

TOP

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

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.