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

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


  public List<Sentence> clausesWithNonTrueValues(List<Sentence> clauseList,
      Model model) {
    List<Sentence> clausesWithNonTrueValues = new ArrayList<Sentence>();
    for (int i = 0; i < clauseList.size(); i++) {
      Sentence clause = clauseList.get(i);
      if (!(isClauseTrueInModel(clause, model))) {
        if (!(clausesWithNonTrueValues.contains(clause))) {// defensive
          // programming not really necessary
          clausesWithNonTrueValues.add(clause);
        }
View Full Code Here


  public SymbolValuePair findPureSymbolValuePair(List<Sentence> clauseList,
      Model model, List<Symbol> symbols) {
    List<Sentence> clausesWithNonTrueValues = clausesWithNonTrueValues(
        clauseList, model);
    Sentence nonTrueClauses = LogicUtils.chainWith("AND",
        clausesWithNonTrueValues);
    // System.out.println("Unsatisfied clauses = "
    // + clausesWithNonTrueValues.size());
    Set<Symbol> symbolsAlreadyAssigned = model.getAssignedSymbols();
View Full Code Here

        clauses, newSymbols, model.extend(symbol, false)));
  }

  private boolean isEvenOneClauseFalse(Model model, List<Sentence> clauseList) {
    for (int i = 0; i < clauseList.size(); i++) {
      Sentence clause = clauseList.get(i);
      if (model.isFalse(clause)) {
        // System.out.println(clause.toString() + " is false");
        return true;
      }
View Full Code Here

  }

  private boolean areAllClausesTrue(Model model, List<Sentence> clauseList) {

    for (int i = 0; i < clauseList.size(); i++) {
      Sentence clause = clauseList.get(i);
      // System.out.println("evaluating " + clause.toString());
      if (!isClauseTrueInModel(clause, model)) { // ie if false or
        // UNKNOWN
        // System.out.println(clause.toString()+ " is not true");
        return false;
View Full Code Here

  }

  private SymbolValuePair findUnitClause(List<Sentence> clauseList,
      Model model, List<Symbol> symbols) {
    for (int i = 0; i < clauseList.size(); i++) {
      Sentence clause = (Sentence) clauseList.get(i);
      if ((clause instanceof Symbol)
          && (!(model.getAssignedSymbols().contains(clause)))) {
        // System.out.println("found unit clause - assigning");
        return new SymbolValuePair(new Symbol(
            ((Symbol) clause).getValue()), true);
      }

      if (clause instanceof UnarySentence) {
        UnarySentence sentence = (UnarySentence) clause;
        Sentence negated = sentence.getNegated();
        if ((negated instanceof Symbol)
            && (!(model.getAssignedSymbols().contains(negated)))) {
          // System.out.println("found unit clause type 2 -
          // assigning");
          return new SymbolValuePair(new Symbol(
View Full Code Here

  }

  private List<HornClause> asHornClauses(List<Sentence> sentences) {
    List<HornClause> hornClauses = new ArrayList<HornClause>();
    for (int i = 0; i < sentences.size(); i++) {
      Sentence sentence = sentences.get(i);
      HornClause clause = new HornClause(sentence);
      hornClauses.add(clause);
    }
    return hornClauses;
  }
View Full Code Here

   * @return a satisfying model or failure (null).
   */
  public Model findModelFor(String logicalSentence, int numberOfFlips,
      double probabilityOfRandomWalk) {
    myModel = new Model();
    Sentence s = (Sentence) new PEParser().parse(logicalSentence);
    CNFTransformer transformer = new CNFTransformer();
    CNFClauseGatherer clauseGatherer = new CNFClauseGatherer();
    SymbolCollector sc = new SymbolCollector();

    List<Symbol> symbols = new Converter<Symbol>().setToList(sc
        .getSymbolsIn(s));
    for (int i = 0; i < symbols.size(); i++) {
      Symbol sym = (Symbol) symbols.get(i);
      myModel = myModel.extend(sym, Util.randomBoolean());
    }
    List<Sentence> clauses = new Converter<Sentence>()
        .setToList(clauseGatherer.getClausesFrom(transformer
            .transform(s)));

    for (int i = 0; i < numberOfFlips; i++) {
      if (getNumberOfClausesSatisfiedIn(
          new Converter<Sentence>().listToSet(clauses), myModel) == clauses
          .size()) {
        return myModel;
      }
      Sentence clause = clauses.get(random.nextInt(clauses.size()));

      List<Symbol> symbolsInClause = new Converter<Symbol>().setToList(sc
          .getSymbolsIn(clause));
      if (random.nextDouble() >= probabilityOfRandomWalk) {
        Symbol randomSymbol = symbolsInClause.get(random
View Full Code Here

  private int getNumberOfClausesSatisfiedIn(Set<Sentence> clauses, Model model) {
    int retVal = 0;
    Iterator<Sentence> i = clauses.iterator();
    while (i.hasNext()) {
      Sentence s = i.next();
      if (model.isTrue(s)) {
        retVal += 1;
      }
    }
    return retVal;
View Full Code Here

    if (sentences.size() == 0) {
      return null;
    } else if (sentences.size() == 1) {
      return sentences.get(0);
    } else {
      Sentence soFar = sentences.get(0);
      for (int i = 1; i < sentences.size(); i++) {
        Sentence next = sentences.get(i);
        soFar = new BinarySentence(connector, soFar, next);
      }
      return soFar;
    }
  }
View Full Code Here

   *            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

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.