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

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


        beforeSubst);
  }

  @Test
  public void testParanthisedSingleVariable() {
    Sentence beforeSubst = parser.parse("((( King(x))))");
    Sentence expectedAfterSubst = parser.parse("King(John) ");

    Map<Variable, Term> p = new LinkedHashMap<Variable, Term>();
    p.put(new Variable("x"), new Constant("John"));

    Sentence afterSubst = sv.subst(p, beforeSubst);
    Assert.assertEquals(expectedAfterSubst, afterSubst);
    Assert.assertEquals(parser.parse("((( King(x))))"), beforeSubst);
  }
View Full Code Here


      reflexivityClause = KB.standardizeApart(reflexivityClause);
      reflexivityClause.setStandardizedApartCheckNotRequired();
      usable.add(reflexivityClause);
    }

    Sentence notAlpha = new NotSentence(alpha);
    // Want to use an answer literal to pull
    // query variables where necessary
    Literal answerLiteral = KB.createAnswerLiteral(notAlpha);
    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

    public AnswerHandler(FOLKnowledgeBase kb, Sentence aQuery,
        long maxQueryTime) {

      finishTime = System.currentTimeMillis() + maxQueryTime;

      Sentence refutationQuery = new NotSentence(aQuery);

      // Want to use an answer literal to pull
      // query variables where necessary
      Literal answerLiteral = kb.createAnswerLiteral(refutationQuery);
      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

    rewrites.add((TermEquality) parser.parse("Power(x, ONE) = x"));
    rewrites.add((TermEquality) parser.parse("Power(x, ZERO) = ONE"));
    DefaultClauseSimplifier simplifier = new DefaultClauseSimplifier(
        rewrites);

    Sentence s1 = parser
        .parse("((P(Plus(y,ZERO),Plus(ZERO,y)) OR P(Power(y, ONE),Power(y,ZERO))) OR P(Power(y,ZERO),Plus(y,ZERO)))");

    CNFConverter cnfConverter = new CNFConverter(parser);

    CNF cnf = cnfConverter.convertToCNF(s1);
View Full Code Here

    String c3 = "patrons(v,Full) AND (hungry(v) AND (type(v,Thai) AND fri_sat(v)))";
    String c4 = "patrons(v,Full) AND (hungry(v) AND type(v,Burger))";
    String sh = "FORALL v (will_wait(v) <=> (" + c1 + " OR (" + c2
        + " OR (" + c3 + " OR (" + c4 + ")))))";

    Sentence hypothesis = parser.parse(sh);
    Sentence desc = parser
        .parse("(((((((((alternate(X0) AND NOT(bar(X0))) AND NOT(fri_sat(X0))) AND hungry(X0)) AND patrons(X0,Full)) AND price(X0,$)) AND NOT(raining(X0))) AND NOT(reservation(X0))) AND type(X0,Thai)) AND wait_estimate(X0,_30_60))");
    Sentence classification = parser.parse("will_wait(X0)");

    FOLKnowledgeBase kb = new FOLKnowledgeBase(domain,
        new FOLOTTERLikeTheoremProver(false));

    kb.tell(hypothesis);
View Full Code Here

            theta = KB.unify(qDelta.getAtomicSentence(),
                alpha.getAtomicSentence());
            // if theta is not fail then return theta
            if (null != theta) {
              for (Literal l : newSentences) {
                Sentence s = null;
                if (l.isPositiveLiteral()) {
                  s = l.getAtomicSentence();
                } else {
                  s = new NotSentence(l.getAtomicSentence());
                }
                KB.tell(s);
              }
              ansHandler.setAnswers(KB.fetch(alpha));
              return ansHandler;
            }
          }
        }
      }
      // add new to KB
      for (Literal l : newSentences) {
        Sentence s = null;
        if (l.isPositiveLiteral()) {
          s = l.getAtomicSentence();
        } else {
          s = new NotSentence(l.getAtomicSentence());
        }
View Full Code Here

  private static void unifierDemo() {
    FOLParser parser = new FOLParser(DomainFactory.knowsDomain());
    Unifier unifier = new Unifier();
    Map<Variable, Term> theta = new Hashtable<Variable, Term>();

    Sentence query = parser.parse("Knows(John,x)");
    Sentence johnKnowsJane = parser.parse("Knows(y,Mother(y))");

    System.out.println("------------");
    System.out.println("Unifier Demo");
    System.out.println("------------");
    Map<Variable, Term> subst = unifier.unify(query, johnKnowsJane, theta);
View Full Code Here

    System.out.println("Conjuctive Normal Form for First Order Logic Demo");
    System.out.println("-------------------------------------------------");
    FOLDomain domain = DomainFactory.lovesAnimalDomain();
    FOLParser parser = new FOLParser(domain);

    Sentence origSentence = parser
        .parse("FORALL x (FORALL y (Animal(y) => Loves(x, y)) => EXISTS y Loves(y, x))");

    CNFConverter cnfConv = new CNFConverter(parser);

    CNF cnf = cnfConv.convertToCNF(origSentence);
View Full Code Here

      this.inferenceProcedure = inferenceProcedure;
    }
  }

  public Sentence tell(String aSentence) {
    Sentence s = parser.parse(aSentence);
    tell(s);
    return s;
  }
View Full Code Here

    for (Clause c : KB.getAllClauses()) {
      c = KB.standardizeApart(c);
      c.setStandardizedApartCheckNotRequired();
      clauses.addAll(c.getFactors());
    }
    Sentence notAlpha = new NotSentence(alpha);
    // Want to use an answer literal to pull
    // query variables where necessary
    Literal answerLiteral = KB.createAnswerLiteral(notAlpha);
    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

TOP

Related Classes of aima.core.logic.fol.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.