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

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


   *            a question to ASK the knowledge base
   *
   * @return the answer to the specified question using the DPLL algorithm.
   */
  public boolean askWithDpll(String queryString) {
    Sentence query = null, cnfForm = null;
    try {
      // just a check to see that the query is well formed
      query = (Sentence) parser.parse(queryString);
    } catch (Exception e) {
      System.out.println("error parsing query" + e.getMessage());
    }

    Sentence kbSentence = asSentence();
    Sentence kbPlusQuery = null;
    if (kbSentence != null) {
      kbPlusQuery = (Sentence) parser.parse(" ( " + kbSentence.toString()
          + " AND (NOT " + queryString + " ))");
    } else {
      kbPlusQuery = query;
View Full Code Here


    }
  }

  private UnarySentence parseNotSentence() {
    match("NOT");
    Sentence sen = parseSentence();
    return new UnarySentence(sen);
  }
View Full Code Here

    consume();
    String connector = lookAhead(1).getText();
    consume();
    List<Sentence> sentences = new ArrayList<Sentence>();
    while (lookAhead(1).getType() != LogicTokenTypes.RPAREN) {
      Sentence sen = parseSentence();
      // consume();
      sentences.add(sen);
    }
    match(")");
    return new MultiSentence(connector, sentences);
View Full Code Here

    if (detectMultiOperator()) {
      return parseMultiSentence();
    } else {
      match("(");
      Sentence one = parseSentence();
      if (lookAhead(1).getType() == LogicTokenTypes.RPAREN) {
        match(")");
        return one;
      } else if ((lookAhead(1).getType() == LogicTokenTypes.CONNECTOR)
          && (!(lookAhead(1).getText().equals("Not")))) {
        String connector = lookAhead(1).getText();
        consume(); // connector
        Sentence two = parseSentence();
        match(")");
        return new BinarySentence(connector, one, two);
      }

    }
View Full Code Here

  @Test
  public void testDPLLReturnsTrueWhenAllClausesTrueInModel() {
    Model model = new Model();
    model = model.extend(new Symbol("A"), true).extend(new Symbol("B"),
        true);
    Sentence sentence = (Sentence) parser.parse("((A AND B) AND (A OR B))");
    boolean satisfiable = dpll.dpllSatisfiable(sentence, model);
    Assert.assertEquals(true, satisfiable);
  }
View Full Code Here

  @Test
  public void testDPLLReturnsFalseWhenOneClauseFalseInModel() {
    Model model = new Model();
    model = model.extend(new Symbol("A"), true).extend(new Symbol("B"),
        false);
    Sentence sentence = (Sentence) parser.parse("((A OR B) AND (A => B))");
    boolean satisfiable = dpll.dpllSatisfiable(sentence, model);
    Assert.assertEquals(false, satisfiable);
  }
View Full Code Here

  @Test
  public void testDPLLFiltersClausesTheStatusOfWhichAreKnown() {
    Model model = new Model();
    model = model.extend(new Symbol("A"), true).extend(new Symbol("B"),
        true);
    Sentence sentence = (Sentence) parser
        .parse("((A AND B) AND (B AND C))");
    List<Sentence> clauseList = new Converter<Sentence>()
        .setToList(new CNFClauseGatherer()
            .getClausesFrom(new CNFTransformer()
                .transform(sentence)));
    List<Sentence> clausesWithNonTrueValues = dpll
        .clausesWithNonTrueValues(clauseList, model);
    Assert.assertEquals(1, clausesWithNonTrueValues.size());
    Sentence nonTrueClause = (Sentence) parser.parse("(B AND C)");
    clausesWithNonTrueValues.contains(nonTrueClause);
  }
View Full Code Here

  @Test
  public void testDPLLFilteringNonTrueClausesGivesNullWhenAllClausesAreKnown() {
    Model model = new Model();
    model = model.extend(new Symbol("A"), true)
        .extend(new Symbol("B"), true).extend(new Symbol("C"), true);
    Sentence sentence = (Sentence) parser
        .parse("((A AND B) AND (B AND C))");
    List<Sentence> clauseList = new Converter<Sentence>()
        .setToList(new CNFClauseGatherer()
            .getClausesFrom(new CNFTransformer()
                .transform(sentence)));
View Full Code Here

  @Test
  public void testDPLLFindsPurePositiveSymbolsWhenTheyExist() {
    Model model = new Model();
    model = model.extend(new Symbol("A"), true).extend(new Symbol("B"),
        true);
    Sentence sentence = (Sentence) parser
        .parse("((A AND B) AND (B AND C))");
    List<Sentence> clauseList = new Converter<Sentence>()
        .setToList(new CNFClauseGatherer()
            .getClausesFrom(new CNFTransformer()
                .transform(sentence)));
View Full Code Here

  @Test
  public void testDPLLFindsPureNegativeSymbolsWhenTheyExist() {
    Model model = new Model();
    model = model.extend(new Symbol("A"), true).extend(new Symbol("B"),
        true);
    Sentence sentence = (Sentence) parser
        .parse("((A AND B) AND ( B  AND (NOT C) ))");
    List<Sentence> clauseList = new Converter<Sentence>()
        .setToList(new CNFClauseGatherer()
            .getClausesFrom(new CNFTransformer()
                .transform(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.