Package aima.core.logic.fol.kb.data

Examples of aima.core.logic.fol.kb.data.CNF


  public CNF convertToCNF(Sentence sentence) {
    return cnfConverter.convertToCNF(sentence);
  }

  public Set<Clause> convertToClauses(Sentence sentence) {
    CNF cnf = cnfConverter.convertToCNF(sentence);

    return new LinkedHashSet<Clause>(cnf.getConjunctionOfClauses());
  }
View Full Code Here


  // Note: pg 278, STORE(s) concept.
  private synchronized void store(Sentence sentence) {
    originalSentences.add(sentence);

    // Convert the sentence to CNF
    CNF cnfOfOrig = cnfConverter.convertToCNF(sentence);
    for (Clause c : cnfOfOrig.getConjunctionOfClauses()) {
      c.setProofStep(new ProofStepClauseClausifySentence(c, sentence));
      if (c.isEmpty()) {
        // This should not happen, if so the user
        // is trying to add an unsatisfiable sentence
        // to the KB.
View Full Code Here

  public CNF construct(Sentence orDistributedOverAnd) {
    ArgData ad = new ArgData();

    orDistributedOverAnd.accept(this, ad);

    return new CNF(ad.clauses);
  }
View Full Code Here

    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);

    Assert.assertEquals(1, cnf.getNumberOfClauses());

    Clause simplified = simplifier.simplify(cnf.getConjunctionOfClauses()
        .get(0));

    Assert.assertEquals("[P(y,y), P(y,ONE), P(ONE,y)]",
        simplified.toString());
  }
View Full Code Here

    FOLParser parser = new FOLParser(domain);

    CNFConverter cnfConverter = new CNFConverter(parser);
    Sentence s1 = parser.parse("((x1 = y1 AND y1 = z1) => x1 = z1)");
    Sentence s2 = parser.parse("((x2 = y2 AND F(y2) = z2) => F(x2) = z2)");
    CNF cnf1 = cnfConverter.convertToCNF(s1);
    CNF cnf2 = cnfConverter.convertToCNF(s2);

    Clause c1 = cnf1.getConjunctionOfClauses().get(0);
    Clause c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertFalse(c1.equals(c2));

    s1 = parser.parse("((x1 = y1 AND y1 = z1) => x1 = z1)");
    s2 = parser.parse("((x2 = y2 AND y2 = z2) => x2 = z2)");
    cnf1 = cnfConverter.convertToCNF(s1);
    cnf2 = cnfConverter.convertToCNF(s2);

    c1 = cnf1.getConjunctionOfClauses().get(0);
    c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertTrue(c1.equals(c2));

    s1 = parser.parse("((x1 = y1 AND y1 = z1) => x1 = z1)");
    s2 = parser.parse("((y2 = z2 AND x2 = y2) => x2 = z2)");
    cnf1 = cnfConverter.convertToCNF(s1);
    cnf2 = cnfConverter.convertToCNF(s2);

    c1 = cnf1.getConjunctionOfClauses().get(0);
    c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertTrue(c1.equals(c2));

    s1 = parser.parse("(((x1 = y1 AND y1 = z1) AND z1 = r1) => x1 = r1)");
    s2 = parser.parse("(((x2 = y2 AND y2 = z2) AND z2 = r2) => x2 = r2)");
    cnf1 = cnfConverter.convertToCNF(s1);
    cnf2 = cnfConverter.convertToCNF(s2);

    c1 = cnf1.getConjunctionOfClauses().get(0);
    c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertTrue(c1.equals(c2));

    s1 = parser.parse("(((x1 = y1 AND y1 = z1) AND z1 = r1) => x1 = r1)");
    s2 = parser.parse("(((z2 = r2 AND y2 = z2) AND x2 = y2) => x2 = r2)");
    cnf1 = cnfConverter.convertToCNF(s1);
    cnf2 = cnfConverter.convertToCNF(s2);

    c1 = cnf1.getConjunctionOfClauses().get(0);
    c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertTrue(c1.equals(c2));

    s1 = parser.parse("(((x1 = y1 AND y1 = z1) AND z1 = r1) => x1 = r1)");
    s2 = parser.parse("(((x2 = y2 AND y2 = z2) AND z2 = y2) => x2 = r2)");
    cnf1 = cnfConverter.convertToCNF(s1);
    cnf2 = cnfConverter.convertToCNF(s2);

    c1 = cnf1.getConjunctionOfClauses().get(0);
    c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertFalse(c1.equals(c2));

    s1 = parser
        .parse("(((((x1 = y1 AND y1 = z1) AND z1 = r1) AND r1 = q1) AND q1 = s1) => x1 = r1)");
    s2 = parser
        .parse("(((((x2 = y2 AND y2 = z2) AND z2 = r2) AND r2 = q2) AND q2 = s2) => x2 = r2)");
    cnf1 = cnfConverter.convertToCNF(s1);
    cnf2 = cnfConverter.convertToCNF(s2);

    c1 = cnf1.getConjunctionOfClauses().get(0);
    c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertTrue(c1.equals(c2));

    s1 = parser
        .parse("((((NOT(Animal(c1920)) OR NOT(Animal(c1921))) OR NOT(Kills(c1922,c1920))) OR NOT(Kills(c1919,c1921))) OR NOT(Kills(SF0(c1922),SF0(c1919))))");
    s2 = parser
        .parse("((((NOT(Animal(c1929)) OR NOT(Animal(c1928))) OR NOT(Kills(c1927,c1929))) OR NOT(Kills(c1930,c1928))) OR NOT(Kills(SF0(c1930),SF0(c1927))))");
    cnf1 = cnfConverter.convertToCNF(s1);
    cnf2 = cnfConverter.convertToCNF(s2);

    c1 = cnf1.getConjunctionOfClauses().get(0);
    c2 = cnf2.getConjunctionOfClauses().get(0);

    Assert.assertTrue(c1.equals(c2));
  }
View Full Code Here

    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);

    System.out.println("Convert '" + origSentence + "' to CNF.");
    System.out.println("CNF=" + cnf.toString());
    System.out.println("");
  }
View Full Code Here

  public CNF convertToCNF(Sentence aSentence) {
    return cnfConverter.convertToCNF(aSentence);
  }

  public Set<Clause> convertToClauses(Sentence aSentence) {
    CNF cnf = cnfConverter.convertToCNF(aSentence);

    return new LinkedHashSet<Clause>(cnf.getConjunctionOfClauses());
  }
View Full Code Here

  // Note: pg 278, STORE(s) concept.
  private synchronized void store(Sentence aSentence) {
    originalSentences.add(aSentence);

    // Convert the sentence to CNF
    CNF cnfOfOrig = cnfConverter.convertToCNF(aSentence);
    for (Clause c : cnfOfOrig.getConjunctionOfClauses()) {
      c.setProofStep(new ProofStepClauseClausifySentence(c, aSentence));
      if (c.isEmpty()) {
        // This should not happen, if so the user
        // is trying to add an unsatisfiable sentence
        // to the KB.
View Full Code Here

    Sentence s = parser.parse(sh);

    CNFConverter cnfConv = new CNFConverter(parser);

    CNF cnf = cnfConv.convertToCNF(s);

    // Contains 9 duplicates
    Assert.assertEquals(40, cnf.getNumberOfClauses());

    Set<Clause> clauses = new HashSet<Clause>(cnf.getConjunctionOfClauses());

    // duplicates removed
    Assert.assertEquals(31, clauses.size());

    clauses.removeAll(SubsumptionElimination.findSubsumedClauses(clauses));
View Full Code Here

  public CNF construct(Sentence orDistributedOverAnd) {
    ArgData ad = new ArgData();

    orDistributedOverAnd.accept(this, ad);

    return new CNF(ad.clauses);
  }
View Full Code Here

TOP

Related Classes of aima.core.logic.fol.kb.data.CNF

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.