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

    Sentence first = sentence.getFirst();
    Sentence second = sentence.getSecond();

    first.accept(this, arg);
    if (Connectors.isAND(sentence.getConnector())) {
      ad.clauses.add(new Clause());
    }
    second.accept(this, arg);

    return sentence;
  }
View Full Code Here

  class ArgData {
    public List<Clause> clauses = new ArrayList<Clause>();
    public boolean negated = false;

    public ArgData() {
      clauses.add(new Clause());
    }
View Full Code Here

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

      for (Literal l : clause.getLiterals()) {
        literals.add(substVisitor.subst(renameSubstitution, l));
      }
      Clause renamed = new Clause(literals);
      renamed.setProofStep(new ProofStepRenaming(renamed, clause
          .getProofStep()));
      return renamed;
    }

    return clause;
View Full Code Here

    FOLParser parser = new FOLParser(domain);

    // Example
    // {~p(a,b),q(c)}
    Clause psi = new Clause();
    psi.addNegativeLiteral((Predicate) parser.parse("P(A,B)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(C)"));
    // {~p(x,y)}
    Clause phi = new Clause();
    phi.addNegativeLiteral((Predicate) parser.parse("P(x,y)"));

    Assert.assertTrue(phi.subsumes(psi));
    // Non-Example
    // {~p(x,b),q(x)}
    psi = new Clause();
    psi.addNegativeLiteral((Predicate) parser.parse("P(x,B)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(x)"));
    // {~p(a,y)}
    phi = new Clause();
    phi.addNegativeLiteral((Predicate) parser.parse("P(A,y)"));
    // Reason for Non-Example:
    // {p(b,b)}
    // {~q(b)}
    Assert.assertFalse(phi.subsumes(psi));

    //
    // Additional Examples

    // Non-Example
    // {~p(x,b),q(z)}
    psi = new Clause();
    psi.addNegativeLiteral((Predicate) parser.parse("P(x,B)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(z)"));
    // {~p(a,y)}
    phi = new Clause();
    phi.addNegativeLiteral((Predicate) parser.parse("P(A,y)"));

    Assert.assertFalse(phi.subsumes(psi));

    // Example
    // {~p(a,b),~p(w,z),q(c)}
    psi = new Clause();
    psi.addNegativeLiteral((Predicate) parser.parse("P(A,B)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(w,z)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(C)"));
    // {~p(x,y),~p(a,b)}
    phi = new Clause();
    phi.addNegativeLiteral((Predicate) parser.parse("P(x,y)"));
    phi.addNegativeLiteral((Predicate) parser.parse("P(A,B)"));

    Assert.assertTrue(phi.subsumes(psi));

    // Non-Example
    // {~p(v,b),~p(w,z),q(c)}
    psi = new Clause();
    psi.addNegativeLiteral((Predicate) parser.parse("P(v,B)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(w,z)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(C)"));
    // {~p(x,y),~p(a,b)}
    phi = new Clause();
    phi.addNegativeLiteral((Predicate) parser.parse("P(x,y)"));
    phi.addNegativeLiteral((Predicate) parser.parse("P(A,B)"));

    Assert.assertFalse(phi.subsumes(psi));

    // Example
    // {~p(a,b),~p(c,d),~p(e,f),~p(g,h),~p(i,j),q(c)}
    psi = new Clause();
    psi.addNegativeLiteral((Predicate) parser.parse("P(A,B)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(C,D)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(E,F)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(G,H)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(I,J)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(C)"));
    // {~p(i,j)}
    phi = new Clause();
    phi.addNegativeLiteral((Predicate) parser.parse("P(I,J)"));

    Assert.assertTrue(phi.subsumes(psi));

    // Example
    // {~p(a,b),~p(c,d),~p(e,f),q(c)}
    psi = new Clause();
    psi.addNegativeLiteral((Predicate) parser.parse("P(A,B)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(C,D)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(E,F)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(C)"));
    // {~p(e,f),~p(a,b),~p(c,d)}
    phi = new Clause();
    phi.addNegativeLiteral((Predicate) parser.parse("P(E,F)"));
    phi.addNegativeLiteral((Predicate) parser.parse("P(A,B)"));
    phi.addNegativeLiteral((Predicate) parser.parse("P(C,D)"));

    Assert.assertTrue(phi.subsumes(psi));

    // Example
    // {~p(a,b),~p(c,d),~p(e,f),~p(g,h),~p(i,j),q(c)}
    psi = new Clause();
    psi.addNegativeLiteral((Predicate) parser.parse("P(A,B)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(C,D)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(E,F)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(G,H)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(I,J)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(C)"));
    // {~p(i,j),~p(c,d)}
    phi = new Clause();
    phi.addNegativeLiteral((Predicate) parser.parse("P(I,J)"));
    phi.addNegativeLiteral((Predicate) parser.parse("P(C,D)"));

    Assert.assertTrue(phi.subsumes(psi));

    // Non-Example
    // {~p(a,b),~p(x,d),~p(e,f),~p(g,h),~p(i,j),q(c)}
    psi = new Clause();
    psi.addNegativeLiteral((Predicate) parser.parse("P(A,B)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(x,D)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(E,F)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(G,H)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(I,J)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(C)"));
    // {~p(i,j),~p(c,d)}
    phi = new Clause();
    phi.addNegativeLiteral((Predicate) parser.parse("P(I,J)"));
    phi.addNegativeLiteral((Predicate) parser.parse("P(C,D)"));

    Assert.assertFalse(phi.subsumes(psi));

    // Example
    // {~p(a,b),~p(c,d),~p(e,f),~p(g,h),~p(i,j),q(c)}
    psi = new Clause();
    psi.addNegativeLiteral((Predicate) parser.parse("P(A,B)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(C,D)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(E,F)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(G,H)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(I,J)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(C)"));
    // {~p(i,j),~p(a,x)}
    phi = new Clause();
    phi.addNegativeLiteral((Predicate) parser.parse("P(I,J)"));
    phi.addNegativeLiteral((Predicate) parser.parse("P(A,x)"));

    Assert.assertTrue(phi.subsumes(psi));

    // Example
    // {~p(a,b),~p(c,d),~p(e,f),~p(g,h),~p(i,j),q(a,b),q(c,d),q(e,f)}
    psi = new Clause();
    psi.addNegativeLiteral((Predicate) parser.parse("P(A,B)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(C,D)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(E,F)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(G,H)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(I,J)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(A,B)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(C,D)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(E,F)"));
    // {~p(i,j),~p(a,b),q(e,f),q(a,b)}
    phi = new Clause();
    phi.addNegativeLiteral((Predicate) parser.parse("P(I,J)"));
    phi.addNegativeLiteral((Predicate) parser.parse("P(A,B)"));
    phi.addPositiveLiteral((Predicate) parser.parse("Q(E,F)"));
    phi.addPositiveLiteral((Predicate) parser.parse("Q(A,B)"));

    Assert.assertTrue(phi.subsumes(psi));

    // Non-Example
    // {~p(a,b),~p(c,d),~p(e,f),~p(g,h),~p(i,j),q(a,b),q(c,d),q(e,f)}
    psi = new Clause();
    psi.addNegativeLiteral((Predicate) parser.parse("P(A,B)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(C,D)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(E,F)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(G,H)"));
    psi.addNegativeLiteral((Predicate) parser.parse("P(I,J)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(A,B)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(C,D)"));
    psi.addPositiveLiteral((Predicate) parser.parse("Q(E,F)"));
    // {~p(i,j),~p(a,b),q(e,f),q(a,b)}
    phi = new Clause();
    phi.addNegativeLiteral((Predicate) parser.parse("P(I,J)"));
    phi.addNegativeLiteral((Predicate) parser.parse("P(A,B)"));
    phi.addPositiveLiteral((Predicate) parser.parse("Q(E,A)"));
    phi.addPositiveLiteral((Predicate) parser.parse("Q(A,B)"));

    Assert.assertFalse(phi.subsumes(psi));
  }
View Full Code Here

  }

  //
  // START-LightestClauseHeuristic
  public Clause getLightestClause() {
    Clause lightest = null;

    if (sos.size() > 0) {
      lightest = sos.first();
    }
View Full Code Here

  }

  //
  // START-ClauseSimplifier
  public Clause simplify(Clause c) {
    Clause simplified = c;

    // Apply each of the rewrite rules to
    // the clause
    for (TermEquality te : rewrites) {
      Clause dc = simplified;
      // Keep applying the rewrite as many times as it
      // can be applied before moving on to the next one.
      while (null != (dc = demodulation.apply(te, dc))) {
        simplified = dc;
      }
View Full Code Here

    public void stepResolved(Clause iFactor, Clause jFactor,
        Set<Clause> resolvents) {
      noPairsResolved++;

      Clause egLargestClause = null;
      for (Clause c : resolvents) {
        if (c.getNumberLiterals() > maxClauseSizeSeen) {
          egLargestClause = c;
          maxClauseSizeSeen = c.getNumberLiterals();
        }
View Full Code Here

public class Demodulation extends AbstractModulation {
  public Demodulation() {
  }

  public Clause apply(TermEquality assertion, Clause clExpression) {
    Clause altClExpression = null;

    for (Literal l1 : clExpression.getLiterals()) {
      AtomicSentence altExpression = apply(assertion,
          l1.getAtomicSentence());
      if (null != altExpression) {
        // I have an alternative, create a new clause
        // with the alternative and return
        List<Literal> newLits = new ArrayList<Literal>();
        for (Literal l2 : clExpression.getLiterals()) {
          if (l1.equals(l2)) {
            newLits.add(l1.newInstance(altExpression));
          } else {
            newLits.add(l2);
          }
        }
        // Only apply demodulation at most once on
        // each call.
        altClExpression = new Clause(newLits);
        altClExpression.setProofStep(new ProofStepClauseDemodulation(
            altClExpression, clExpression, assertion));
        if (clExpression.isImmutable()) {
          altClExpression.setImmutable();
        }
        if (!clExpression.isStandardizedApartCheckRequired()) {
          altClExpression.setStandardizedApartCheckNotRequired();
        }
        break;
      }
    }
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.