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

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


    // Ensure reflexivity axiom is added to usable if using paramodulation.
    if (isUseParamodulation()) {
      // Reflexivity Axiom: x = x
      TermEquality reflexivityAxiom = new TermEquality(new Variable("x"),
          new Variable("x"));
      Clause reflexivityClause = new Clause();
      reflexivityClause.addLiteral(new Literal(reflexivityAxiom));
      reflexivityClause = KB.standardizeApart(reflexivityClause);
      reflexivityClause.setStandardizedApartCheckNotRequired();
      usable.add(reflexivityClause);
    }

    Sentence notAlpha = new NotSentence(alpha);
    // Want to use an answer literal to pull
    // query variables where necessary
    Literal answerLiteral = KB.createAnswerLiteral(notAlpha);
    Set<Variable> answerLiteralVariables = KB
        .collectAllVariables(answerLiteral.getAtomicSentence());
    Clause answerClause = new Clause();

    if (answerLiteralVariables.size() > 0) {
      Sentence notAlphaWithAnswer = new ConnectedSentence(Connectors.OR,
          notAlpha, answerLiteral.getAtomicSentence());
      for (Clause c : KB.convertToClauses(notAlphaWithAnswer)) {
        c = KB.standardizeApart(c);
        c.setProofStep(new ProofStepGoal(c));
        c.setStandardizedApartCheckNotRequired();
        sos.addAll(c.getFactors());
      }

      answerClause.addLiteral(answerLiteral);
    } else {
      for (Clause c : KB.convertToClauses(notAlpha)) {
        c = KB.standardizeApart(c);
        c.setProofStep(new ProofStepGoal(c));
        c.setStandardizedApartCheckNotRequired();
View Full Code Here


    getLightestClauseHeuristic().initialSOS(sos);

    // * repeat
    do {
      // * clause <- the lightest member of sos
      Clause clause = getLightestClauseHeuristic().getLightestClause();
      if (null != clause) {
        // * move clause from sos to usable
        sos.remove(clause);
        getLightestClauseHeuristic().removedClauseFromSOS(clause);
        usable.add(clause);
View Full Code Here

    CNF cnf = cnfConverter.convertToCNF(s1);

    Assert.assertEquals(1, cnf.getNumberOfClauses());

    Clause simplified = simplifier.simplify(cnf.getConjunctionOfClauses()
        .get(0));

    Assert.assertEquals("[P(y,y), P(y,ONE), P(ONE,y)]",
        simplified.toString());
  }
View Full Code Here

    StandardizeApartIndexicalFactory.flush();
  }

  @Test
  public void testImmutable() {
    Clause c = new Clause();

    Assert.assertFalse(c.isImmutable());

    c.addNegativeLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    c.addPositiveLiteral(new Predicate("Pred2", new ArrayList<Term>()));

    c.setImmutable();

    Assert.assertTrue(c.isImmutable());

    try {
      c.addNegativeLiteral(new Predicate("Pred3", new ArrayList<Term>()));

      Assert.fail("Should have thrown an IllegalStateException");
    } catch (IllegalStateException ise) {
      // Ok, Expected
    }

    try {
      c.addPositiveLiteral(new Predicate("Pred3", new ArrayList<Term>()));

      Assert.fail("Should have thrown an IllegalStateException");
    } catch (IllegalStateException ise) {
      // Ok, Expected
    }
View Full Code Here

    }
  }

  @Test
  public void testIsEmpty() {
    Clause c1 = new Clause();
    Assert.assertTrue(c1.isEmpty());

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

    Clause c2 = new Clause();
    Assert.assertTrue(c2.isEmpty());

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

    Clause c3 = new Clause();
    Assert.assertTrue(c3.isEmpty());

    c3.addNegativeLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    c3.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    // Should be empty as they resolved with each other
    Assert.assertFalse(c3.isEmpty());

    c3.addNegativeLiteral(new Predicate("Pred1", new ArrayList<Term>()));
    c3.addPositiveLiteral(new Predicate("Pred2", new ArrayList<Term>()));
    Assert.assertFalse(c3.isEmpty());
  }
View Full Code Here

    Assert.assertFalse(c3.isEmpty());
  }

  @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

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

  @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

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

    Set<Clause> paras = paramodulation.apply(c1, c2);
    Assert.assertEquals(2, paras.size());

    Iterator<Clause> it = paras.iterator();
View Full Code Here

    lits.add(new Literal(a2));
    lits.add(new Literal(a3));
    lits.add(new Literal(a4));
    lits.add(new Literal(a5));

    Clause c1 = new Clause(lits);

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

    Clause c2 = new Clause(lits);

    Set<Clause> paras = paramodulation.apply(c1, c2);
    Assert.assertEquals(5, paras.size());

    Iterator<Clause> it = paras.iterator();
View Full Code Here

    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("x = x");
    lits.add(new Literal(a1));

    Clause c2 = new Clause(lits);

    Set<Clause> paras = paramodulation.apply(c1, c2);
    Assert.assertEquals(0, paras.size());
  }
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.