Package aima.core.logic.propositional.parsing.ast

Examples of aima.core.logic.propositional.parsing.ast.Sentence


   *            the query, a sentence in propositional logic
   *
   * @return the answer to the specified question using PL-Resolution.
   */
  public boolean plResolution(KnowledgeBase kb, Sentence alpha) {
    Sentence kBAndNotAlpha = new BinarySentence("AND", kb.asSentence(),
        new UnarySentence(alpha));
    Set<Sentence> clauses = new CNFClauseGatherer()
        .getClausesFrom(new CNFTransformer().transform(kBAndNotAlpha));
    clauses = filterOutClausesWithTwoComplementaryLiterals(clauses);
    Set<Sentence> newClauses = new HashSet<Sentence>();
View Full Code Here


  }

  public boolean plResolution(String kbs, String alphaString) {
    KnowledgeBase kb = new KnowledgeBase();
    kb.tell(kbs);
    Sentence alpha = (Sentence) new PEParser().parse(alphaString);
    return plResolution(kb, alpha);
  }
View Full Code Here

      Set<Sentence> clauses) {
    Set<Sentence> filtered = new HashSet<Sentence>();
    SymbolClassifier classifier = new SymbolClassifier();
    Iterator<Sentence> iter = clauses.iterator();
    while (iter.hasNext()) {
      Sentence clause = iter.next();
      Set<Symbol> positiveSymbols = classifier
          .getPositiveSymbolsIn(clause);
      Set<Symbol> negativeSymbols = classifier
          .getNegativeSymbolsIn(clause);
      if ((SetOps.intersection(positiveSymbols, negativeSymbols).size() == 0)) {
View Full Code Here

    List<List<Sentence>> pairs = new ArrayList<List<Sentence>>();
    for (int i = 0; i < clausesList.size(); i++) {
      for (int j = i; j < clausesList.size(); j++) {
        List<Sentence> pair = new ArrayList<Sentence>();
        Sentence first = clausesList.get(i);
        Sentence second = clausesList.get(j);

        if (!(first.equals(second))) {
          pair.add(first);
          pair.add(second);
          pairs.add(pair);
View Full Code Here

   *            a sentence of propositional logic
   *
   * @return the specified sentence in conjunctive normal form.
   */
  public Sentence transform(Sentence s) {
    Sentence toTransform = s;
    while (!(toTransform.equals(step(toTransform)))) {
      toTransform = step(toTransform);
    }

    return toTransform;
  }
View Full Code Here

  private Sentence step(Sentence s) {
    return (Sentence) s.accept(this, null);
  }

  private Sentence transformBiConditionalSentence(BinarySentence bs) {
    Sentence first = new BinarySentence("=>", (Sentence) bs.getFirst()
        .accept(this, null), (Sentence) bs.getSecond().accept(this,
        null));
    Sentence second = new BinarySentence("=>", (Sentence) bs.getSecond()
        .accept(this, null), (Sentence) bs.getFirst()
        .accept(this, null));
    return new BinarySentence("AND", first, second);
  }
View Full Code Here

        .accept(this, null));
    return new BinarySentence("AND", first, second);
  }

  private Sentence transformImpliedSentence(BinarySentence bs) {
    Sentence first = new UnarySentence((Sentence) bs.getFirst().accept(
        this, null));
    return new BinarySentence("OR", first, (Sentence) bs.getSecond()
        .accept(this, null));
  }
View Full Code Here

      return (Sentence) ((UnarySentence) us.getNegated()).getNegated()
          .accept(this, null);
    } else if (us.getNegated() instanceof BinarySentence) {
      BinarySentence bs = (BinarySentence) us.getNegated();
      if (bs.isAndSentence()) {
        Sentence first = new UnarySentence((Sentence) bs.getFirst()
            .accept(this, null));
        Sentence second = new UnarySentence((Sentence) bs.getSecond()
            .accept(this, null));
        return new BinarySentence("OR", first, second);
      } else if (bs.isOrSentence()) {
        Sentence first = new UnarySentence((Sentence) bs.getFirst()
            .accept(this, null));
        Sentence second = new UnarySentence((Sentence) bs.getSecond()
            .accept(this, null));
        return new BinarySentence("AND", first, second);
      } else {
        return (Sentence) super.visitNotSentence(us, null);
      }
View Full Code Here

  }

  private Sentence distributeOrOverAnd(BinarySentence bs) {
    BinarySentence andTerm = bs.firstTermIsAndSentence() ? (BinarySentence) bs
        .getFirst() : (BinarySentence) bs.getSecond();
    Sentence otherterm = bs.firstTermIsAndSentence() ? bs.getSecond() : bs
        .getFirst();
    // (alpha or (beta and gamma) = ((alpha or beta) and (alpha or gamma))
    Sentence alpha = (Sentence) otherterm.accept(this, null);
    Sentence beta = (Sentence) andTerm.getFirst().accept(this, null);
    Sentence gamma = (Sentence) andTerm.getSecond().accept(this, null);
    Sentence distributed = new BinarySentence("AND", new BinarySentence(
        "OR", alpha, beta), new BinarySentence("OR", alpha, gamma));
    return distributed;
  }
View Full Code Here

   *            a String representation of a Sentence in propositional logic
   *
   * @return <code>true</code> if the specified sentence is satisfiable.
   */
  public boolean dpllSatisfiable(String string) {
    Sentence sen = (Sentence) new PEParser().parse(string);
    return dpllSatisfiable(sen, new Model());
  }
View Full Code Here

TOP

Related Classes of aima.core.logic.propositional.parsing.ast.Sentence

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.