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

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


      thisLevelProofSteps.add(new ArrayList<ProofStepBwChGoal>());
      return thisLevelProofSteps;
    }

    // qDelta <- SUBST(theta, FIRST(goals))
    Literal qDelta = KB.subst(theta, goals.get(0));

    // for each sentence r in KB where
    // STANDARDIZE-APART(r) = (p1 ^ ... ^ pn => q)
    for (Clause r : KB.getAllDefiniteClauses()) {
      r = KB.standardizeApart(r);
      // and thetaDelta <- UNIFY(q, qDelta) succeeds
      Map<Variable, Term> thetaDelta = KB.unify(r.getPositiveLiterals()
          .get(0).getAtomicSentence(), qDelta.getAtomicSentence());
      if (null != thetaDelta) {
        // new_goals <- [p1,...,pn|REST(goals)]
        List<Literal> newGoals = new ArrayList<Literal>(
            r.getNegativeLiterals());
        newGoals.addAll(goals.subList(1, goals.size()));
View Full Code Here


    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());
View Full Code Here

    }
  }

  // Returns c if no cancellation occurred
  private Chain tryCancellation(Chain c) {
    Literal head = c.getHead();
    if (null != head && !(head instanceof ReducedLiteral)) {
      for (Literal l : c.getTail()) {
        if (l instanceof ReducedLiteral) {
          // if they can be resolved
          if (head.isNegativeLiteral() != l.isNegativeLiteral()) {
            Map<Variable, Term> subst = unifier
                .unify(head.getAtomicSentence(),
                    l.getAtomicSentence());
            if (null != subst) {
              // I have a cancellation
              // Need to apply subst to all of the
              // literals in the cancellation
View Full Code Here

    return c;
  }

  // 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;
    }
View Full Code Here

      Sentence refutationQuery = new NotSentence(aQuery);

      // Want to use an answer literal to pull
      // query variables where necessary
      Literal answerLiteral = kb.createAnswerLiteral(refutationQuery);
      answerLiteralVariables = kb.collectAllVariables(answerLiteral
          .getAtomicSentence());

      // Create the Set of Support based on the Query.
      if (answerLiteralVariables.size() > 0) {
        Sentence refutationQueryWithAnswer = new ConnectedSentence(
            Connectors.OR, refutationQuery, answerLiteral
                .getAtomicSentence().copy());

        sos = createChainsFromClauses(kb
            .convertToClauses(refutationQueryWithAnswer));
View Full Code Here

  public IndexedFarParents(List<Chain> sos, List<Chain> background) {
    constructInternalDataStructures(sos, background);
  }

  public int getNumberFarParents(Chain farParent) {
    Literal head = farParent.getHead();

    Map<String, List<Chain>> heads = null;
    if (head.isPositiveLiteral()) {
      heads = posHeads;
    } else {
      heads = negHeads;
    }
    String headKey = head.getAtomicSentence().getSymbolicName();

    List<Chain> farParents = heads.get(headKey);
    if (null != farParents) {
      return farParents.size();
    }
View Full Code Here

    }
    return 0;
  }

  public void resetNumberFarParentsTo(Chain farParent, int toSize) {
    Literal head = farParent.getHead();
    Map<String, List<Chain>> heads = null;
    if (head.isPositiveLiteral()) {
      heads = posHeads;
    } else {
      heads = negHeads;
    }
    String key = head.getAtomicSentence().getSymbolicName();
    List<Chain> farParents = heads.get(key);
    while (farParents.size() > toSize) {
      farParents.remove(farParents.size() - 1);
    }
  }
View Full Code Here

      farParents.remove(farParents.size() - 1);
    }
  }

  public int getNumberCandidateFarParents(Chain nearParent) {
    Literal nearestHead = nearParent.getHead();

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

    String nearestKey = nearestHead.getAtomicSentence().getSymbolicName();

    List<Chain> farParents = candidateHeads.get(nearestKey);
    if (null != farParents) {
      return farParents.size();
    }
View Full Code Here

  }

  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));
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;
      } else {
        toAddTo = negHeads;
      }

      String key = head.getAtomicSentence().getSymbolicName();
      List<Chain> farParents = toAddTo.get(key);
      if (null == farParents) {
        farParents = new ArrayList<Chain>();
        toAddTo.put(key, farParents);
      }
View Full Code Here

TOP

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

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.