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

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


        AtomicSentence atom = (AtomicSentence) substVisitor.subst(
            renameSubstitution, l.getAtomicSentence());
        lits.add(l.newInstance(atom));
      }

      Chain renamed = new Chain(lits);

      renamed.setProofStep(new ProofStepRenaming(renamed, chain
          .getProofStep()));

      return renamed;
    }
View Full Code Here


  //
  private List<Chain> createChainsFromClauses(Set<Clause> clauses) {
    List<Chain> chains = new ArrayList<Chain>();

    for (Clause c : clauses) {
      Chain chn = new Chain(c.getLiterals());
      chn.setProofStep(new ProofStepChainFromClause(chn, c));
      chains.add(chn);
      chains.addAll(chn.getContrapositives());
    }

    return chains;
  }
View Full Code Here

      if (ansHandler.isComplete()) {
        break;
      }

      // Reduction
      Chain nextNearParent = indexedFarParents.attemptReduction(
          nearParent, farParentIdx);

      if (null == nextNearParent) {
        // Unable to remove the head via reduction
        continue;
      }

      // Handle Canceling and Dropping
      boolean cancelled = false;
      boolean dropped = false;
      do {
        cancelled = false;
        Chain nextParent = null;
        while (nextNearParent != (nextParent = tryCancellation(nextNearParent))) {
          nextNearParent = nextParent;
          cancelled = true;
        }
View Full Code Here

              for (Literal lfc : c.getTail()) {
                AtomicSentence a = (AtomicSentence) substVisitor
                    .subst(subst, lfc.getAtomicSentence());
                cancLits.add(lfc.newInstance(a));
              }
              Chain cancellation = new Chain(cancLits);
              cancellation
                  .setProofStep(new ProofStepChainCancellation(
                      cancellation, c, subst));
              return cancellation;
            }
          }
View Full Code Here

  // Returns c if no dropping occurred
  private Chain tryDropping(Chain c) {
    Literal head = c.getHead();
    if (null != head && (head instanceof ReducedLiteral)) {
      Chain dropped = new Chain(c.getTail());
      dropped.setProofStep(new ProofStepChainDropped(dropped, c));
      return dropped;
    }

    return c;
  }
View Full Code Here

    }
    return 0;
  }

  public Chain attemptReduction(Chain nearParent, int farParentIndex) {
    Chain nnpc = null;

    Literal nearLiteral = nearParent.getHead();

    Map<String, List<Chain>> candidateHeads = null;
    if (nearLiteral.isPositiveLiteral()) {
      candidateHeads = negHeads;
    } else {
      candidateHeads = posHeads;
    }

    AtomicSentence nearAtom = nearLiteral.getAtomicSentence();
    String nearestKey = nearAtom.getSymbolicName();
    List<Chain> farParents = candidateHeads.get(nearestKey);
    if (null != farParents) {
      Chain farParent = farParents.get(farParentIndex);
      standardizeApart(farParent);
      Literal farLiteral = farParent.getHead();
      AtomicSentence farAtom = farLiteral.getAtomicSentence();
      Map<Variable, Term> subst = unifier.unify(nearAtom, farAtom);

      // If I was able to unify with one
      // of the far heads
      if (null != subst) {
        // Want to always apply reduction uniformly
        Chain topChain = farParent;
        Literal botLit = nearLiteral;
        Chain botChain = nearParent;

        // Need to apply subst to all of the
        // literals in the reduction
        List<Literal> reduction = new ArrayList<Literal>();
        for (Literal l : topChain.getTail()) {
          AtomicSentence atom = (AtomicSentence) substVisitor.subst(
              subst, l.getAtomicSentence());
          reduction.add(l.newInstance(atom));
        }
        reduction.add(new ReducedLiteral((AtomicSentence) substVisitor
            .subst(subst, botLit.getAtomicSentence()), botLit
            .isNegativeLiteral()));
        for (Literal l : botChain.getTail()) {
          AtomicSentence atom = (AtomicSentence) substVisitor.subst(
              subst, l.getAtomicSentence());
          reduction.add(l.newInstance(atom));
        }

        nnpc = new Chain(reduction);
        nnpc.setProofStep(new ProofStepChainReduction(nnpc, nearParent,
            farParent, subst));
      }
    }
View Full Code Here

    return nnpc;
  }

  public Chain addToIndex(Chain c) {
    Chain added = null;
    Literal head = c.getHead();
    if (null != head) {
      Map<String, List<Chain>> toAddTo = null;
      if (head.isPositiveLiteral()) {
        toAddTo = posHeads;
View Full Code Here

*/
public class ChainTest {

  @Test
  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

    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();
    Assert.assertEquals(0, conts.size());

    c.addLiteral(p);
    conts = c.getContrapositives();
    Assert.assertEquals(0, conts.size());

    c.addLiteral(notq);
    conts = c.getContrapositives();
    Assert.assertEquals(1, conts.size());
    Assert.assertEquals("<~Q(),P()>", conts.get(0).toString());

    c.addLiteral(notr);
    conts = c.getContrapositives();
    Assert.assertEquals(2, conts.size());
    Assert.assertEquals("<~Q(),P(),~R()>", conts.get(0).toString());
    Assert.assertEquals("<~R(),P(),~Q()>", conts.get(1).toString());
  }
View Full Code Here

  //
  private List<Chain> createChainsFromClauses(Set<Clause> clauses) {
    List<Chain> chains = new ArrayList<Chain>();

    for (Clause c : clauses) {
      Chain chn = new Chain(c.getLiterals());
      chn.setProofStep(new ProofStepChainFromClause(chn, c));
      chains.add(chn);
      chains.addAll(chn.getContrapositives());
    }

    return chains;
  }
View Full Code Here

TOP

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

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.