Examples of BinarySentence


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

  private Sentence transformNotSentence(UnarySentence us) {
    if (us.getNegated() instanceof UnarySentence) {
      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);
      }
    } else {
      return (Sentence) super.visitNotSentence(us, null);
View Full Code Here

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

      } else if (!isImpliedSentence(sentence)) {
        throw new RuntimeException("Sentence " + sentence
            + " is not a horn clause");

      } else {
        BinarySentence bs = (BinarySentence) sentence;
        head = (Symbol) bs.getSecond();
        inferred.put(head, Boolean.FALSE);
        Set<Symbol> symbolsInPremise = new SymbolCollector()
            .getSymbolsIn(bs.getFirst());
        Iterator<Symbol> iter = symbolsInPremise.iterator();
        while (iter.hasNext()) {
          inferred.put(iter.next(), Boolean.FALSE);
        }
        premiseSymbols = new Converter<Symbol>()
View Full Code Here

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

      return (Sentence) super.visitNotSentence(us, null);
    }
  }

  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

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

  public Object visitNotSentence(UnarySentence fs, Object arg) {
    return new UnarySentence((Sentence) fs.getNegated().accept(this, arg));
  }

  public Object visitBinarySentence(BinarySentence fs, Object arg) {
    return new BinarySentence(fs.getOperator(), (Sentence) fs.getFirst()
        .accept(this, arg), (Sentence) fs.getSecond().accept(this, arg));
  }
View Full Code Here

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

          && (!(lookAhead(1).getText().equals("Not")))) {
        String connector = lookAhead(1).getText();
        consume(); // connector
        Sentence two = parseSentence();
        match(")");
        return new BinarySentence(connector, one, two);
      }

    }
    throw new RuntimeException(
        " Runtime Exception at Bracketed Expression with token "
View Full Code Here

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

    Assert.assertEquals(UnarySentence.class, sen.getClass());
  }

  @Test
  public void testBinarySentenceParse() {
    BinarySentence sen = (BinarySentence) parser
        .parse("(PETER  AND  NORVIG)");
    Assert.assertEquals(BinarySentence.class, sen.getClass());
  }
View Full Code Here

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

    Assert.assertEquals(MultiSentence.class, sen.getClass());
  }

  @Test
  public void testComplexSentenceParse() {
    BinarySentence sen = (BinarySentence) parser
        .parse("((OR  NORVIG AIMA LISP) AND TRUE)");
    Assert.assertEquals(BinarySentence.class, sen.getClass());

    sen = (BinarySentence) parser
        .parse("((OR  NORVIG AIMA LISP) AND (((LISP => COOL))))");
    Assert.assertEquals(BinarySentence.class, sen.getClass());
    Assert.assertEquals(
        " ( ( OR NORVIG AIMA LISP  )  AND  ( LISP => COOL ) )",
        sen.toString());

    String s = "((NOT (P AND Q ))  AND ((NOT (R AND S))))";
    sen = (BinarySentence) parser.parse(s);
    Assert.assertEquals(
        " (  ( NOT  ( P AND Q ) )  AND  ( NOT  ( R AND S ) )  )",
        sen.toString());

    s = "((P AND Q) OR (S AND T))";
    sen = (BinarySentence) parser.parse(s);
    Assert.assertEquals(" (  ( P AND Q ) OR  ( S AND T ) )", sen.toString());
    Assert.assertEquals("OR", sen.getOperator());

    s = "(NOT ((P AND Q) => (S AND T)))";
    UnarySentence nsen = (UnarySentence) parser.parse(s);
    // assertEquals("=>",sen.getOperator());
    s = "(NOT (P <=> (S AND T)))";
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.