Package aima.core.logic.fol.parsing.ast

Examples of aima.core.logic.fol.parsing.ast.ConnectedSentence


  @Test
  public void testComplexConnectedSentence1() {
    Sentence ps = parser
        .parse("((King(John) AND NOT King(Richard)) OR King(Saladin))");

    Assert.assertEquals(ps, new ConnectedSentence("OR",
        new ConnectedSentence("AND", getKingPredicate(new Constant(
            "John")), new NotSentence(
            getKingPredicate(new Constant("Richard")))),
        getKingPredicate(new Constant("Saladin"))));
  }
View Full Code Here


    Sentence qs = parser
        .parse("EXISTS x,y  (King(x) AND BrotherOf(x) = y)");
    List<Variable> vars = new ArrayList<Variable>();
    vars.add(new Variable("x"));
    vars.add(new Variable("y"));
    ConnectedSentence cse = new ConnectedSentence("AND",
        getKingPredicate(new Variable("x")), new TermEquality(
            getBrotherOfFunction(new Variable("x")), new Variable(
                "y")));
    Assert.assertEquals(qs, new QuantifiedSentence("EXISTS", vars, cse));
  }
View Full Code Here

    Sentence qs = parser
        .parse("(( (EXISTS x,y  (King(x) AND (BrotherOf(x) = y)) ) ))");
    List<Variable> vars = new ArrayList<Variable>();
    vars.add(new Variable("x"));
    vars.add(new Variable("y"));
    ConnectedSentence cse = new ConnectedSentence("AND",
        getKingPredicate(new Variable("x")), new TermEquality(
            getBrotherOfFunction(new Variable("x")), new Variable(
                "y")));
    Assert.assertEquals(qs, new QuantifiedSentence("EXISTS", vars, cse));
  }
View Full Code Here

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

      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

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

    Sentence beta = (Sentence) sentence.getSecond().accept(this, arg);

    // Eliminate <=>, bi-conditional elimination,
    // replace (alpha <=> beta) with (~alpha V beta) ^ (alpha V ~beta).
    if (Connectors.isBICOND(sentence.getConnector())) {
      Sentence first = new ConnectedSentence(Connectors.OR,
          new NotSentence(alpha), beta);
      Sentence second = new ConnectedSentence(Connectors.OR, alpha,
          new NotSentence(beta));

      return new ConnectedSentence(Connectors.AND, first, second);
    }

    // Eliminate =>, implication elimination,
    // replacing (alpha => beta) with (~alpha V beta)
    if (Connectors.isIMPLIES(sentence.getConnector())) {
      return new ConnectedSentence(Connectors.OR, new NotSentence(alpha),
          beta);
    }

    return new ConnectedSentence(sentence.getConnector(), alpha, beta);
  }
View Full Code Here

  public Object visitConnectedSentence(ConnectedSentence sentence, Object arg) {
    Sentence substFirst = (Sentence) sentence.getFirst().accept(this, arg);
    Sentence substSecond = (Sentence) sentence.getSecond()
        .accept(this, arg);
    return new ConnectedSentence(sentence.getConnector(), substFirst,
        substSecond);
  }
View Full Code Here

    if (negated instanceof NotSentence) {
      return ((NotSentence) negated).getNegated().accept(this, arg);
    }

    if (negated instanceof ConnectedSentence) {
      ConnectedSentence negConnected = (ConnectedSentence) negated;
      Sentence alpha = negConnected.getFirst();
      Sentence beta = negConnected.getSecond();
      // ~(alpha ^ beta) equivalent to (~alpha V ~beta) (De Morgan)
      if (Connectors.isAND(negConnected.getConnector())) {
        // I need to ensure the ~s are moved in deeper
        Sentence notAlpha = (Sentence) (new NotSentence(alpha)).accept(
            this, arg);
        Sentence notBeta = (Sentence) (new NotSentence(beta)).accept(
            this, arg);
        return new ConnectedSentence(Connectors.OR, notAlpha, notBeta);
      }

      // ~(alpha V beta) equivalent to (~alpha ^ ~beta) (De Morgan)
      if (Connectors.isOR(negConnected.getConnector())) {
        // I need to ensure the ~s are moved in deeper
        Sentence notAlpha = (Sentence) (new NotSentence(alpha)).accept(
            this, arg);
        Sentence notBeta = (Sentence) (new NotSentence(beta)).accept(
            this, arg);
        return new ConnectedSentence(Connectors.AND, notAlpha, notBeta);
      }
    }

    // in addition, rules for negated quantifiers:
    if (negated instanceof QuantifiedSentence) {
View Full Code Here

    return new NotSentence((Sentence) negated.accept(this, arg));
  }

  public Object visitConnectedSentence(ConnectedSentence sentence, Object arg) {
    return new ConnectedSentence(sentence.getConnector(),
        (Sentence) sentence.getFirst().accept(this, arg),
        (Sentence) sentence.getSecond().accept(this, arg));
  }
View Full Code Here

TOP

Related Classes of aima.core.logic.fol.parsing.ast.ConnectedSentence

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.