Package aima.core.logic.fol.kb.data

Examples of aima.core.logic.fol.kb.data.Clause


    List<Literal> lits = new ArrayList<Literal>();
    AtomicSentence a1 = (AtomicSentence) parser.parse("P(y, F(A,y))");
    lits.add(new Literal(a1));

    Clause c1 = new Clause(lits);

    lits.clear();
    a1 = (AtomicSentence) parser.parse("F(x,B) = x");
    lits.add(new Literal(a1, true));

    Clause c2 = new Clause(lits);

    Set<Clause> paras = paramodulation.apply(c1, c2);
    Assert.assertEquals(0, paras.size());
  }
View Full Code Here


    Assert.assertFalse(c1.isDefiniteClause());
  }

  @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

    Assert.assertFalse(c1.isUnitClause());
  }

  @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

    AtomicSentence a1 = (AtomicSentence) parser.parse("P(F(x,B),x)");
    AtomicSentence a2 = (AtomicSentence) parser.parse("Q(x)");
    lits.add(new Literal(a1));
    lits.add(new Literal(a2));

    Clause c1 = new Clause(lits);

    lits.clear();
    a1 = (AtomicSentence) parser.parse("F(A,y) = y");
    a2 = (AtomicSentence) parser.parse("R(y)");
    lits.add(new Literal(a1));
    lits.add(new Literal(a2));

    Clause c2 = new Clause(lits);

    Paramodulation paramodulation = new Paramodulation();
    Set<Clause> paras = paramodulation.apply(c1, c2);

    System.out.println("Paramodulate '" + c1 + "' with '" + c2
View Full Code Here

    domain.addPredicate("Pred1");
    domain.addPredicate("Pred2");
    domain.addPredicate("Pred3");
    domain.addPredicate("Pred4");

    Clause c1 = new Clause();

    // Ensure that resolving to self when empty returns an empty clause
    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()
        .getNumberNegativeLiterals());
    Assert.assertEquals(1, c2.binaryResolvents(c1).iterator().next()
        .getNumberPositiveLiterals());
    Assert.assertEquals(1, c2.binaryResolvents(c1).iterator().next()
        .getNumberNegativeLiterals());
  }
View Full Code Here

      clauses.addAll(newClauses);
      newClauses.clear();
      Clause[] clausesA = new Clause[clauses.size()];
      clauses.toArray(clausesA);
      for (int i = 0; i < clausesA.length; i++) {
        Clause cI = clausesA[i];
        for (int j = 0; j < clausesA.length; j++) {
          Clause cJ = clausesA[j];

          newClauses.addAll(cI.getFactors());
          newClauses.addAll(cJ.getFactors());

          Set<Clause> cIresolvents = cI.binaryResolvents(cJ);
          Set<Clause> cJresolvents = cJ.binaryResolvents(cI);
          if (!cIresolvents.equals(cJresolvents)) {
            System.err.println("cI=" + cI);
            System.err.println("cJ=" + cJ);
            System.err.println("cIR=" + cIresolvents);
            System.err.println("cJR=" + cJresolvents);
View Full Code Here

    domain.addConstant("B");

    FOLParser parser = new FOLParser(domain);

    // B = A
    Clause c1 = new Clause();
    c1.addPositiveLiteral((AtomicSentence) parser.parse("B = A"));

    Clause c2 = new Clause();
    c2.addNegativeLiteral((AtomicSentence) parser.parse("B = A"));
    c2.addPositiveLiteral((AtomicSentence) parser.parse("B = A"));

    Set<Clause> resolvents = c1.binaryResolvents(c2);

    Assert.assertEquals(1, resolvents.size());
    Assert.assertEquals("[[B = A]]", resolvents.toString());
View Full Code Here

    pts1.add(var1);
    pts2.add(cons2);
    pts2.add(cons1);
    pts2.add(var1);

    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

    pts1.add(var1);
    pts2.add(cons2);
    pts2.add(cons1);
    pts2.add(var1);

    Clause c1 = new Clause();
    Clause c2 = new Clause();
    Assert.assertTrue(c1.equals(c1));
    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

    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);

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

    s1 = parser.parse("((x1 = y1 AND y1 = z1) => x1 = z1)");
    s2 = parser.parse("((x2 = y2 AND y2 = z2) => x2 = z2)");
View Full Code Here

TOP

Related Classes of aima.core.logic.fol.kb.data.Clause

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.