Beispiel #1
0
  /**
   * ***************************************************************** Iterating through all
   * formulas, return a proof of an inconsistent or redundant one, if such a thing exists.
   */
  public static String kbConsistencyCheck(KB kb) {

    int timeout = 10;
    int maxAnswers = 1;
    String proof;
    String result = null;

    StringBuffer answer = new StringBuffer();
    KB empty = makeEmptyKB("consistencyCheck");

    System.out.println("=================== Consistency Testing ===================");
    try {
      Formula theQuery = new Formula();
      Collection allFormulas = kb.formulaMap.values();
      Iterator it = allFormulas.iterator();
      while (it.hasNext()) {
        Formula query = (Formula) it.next();
        FormulaPreprocessor fp = new FormulaPreprocessor();
        ArrayList processedQueries =
            fp.preProcess(query, false, kb); // may be multiple because of row vars.
        // System.out.println(" query = " + query);
        // System.out.println(" processedQueries = " + processedQueries);

        String processedQuery = null;
        Iterator q = processedQueries.iterator();

        System.out.println(
            "INFO in Diagnostics.kbConsistencyCheck(): size = " + processedQueries.size());
        while (q.hasNext()) {
          Formula f = (Formula) q.next();
          System.out.println("INFO in Diagnostics.kbConsistencyCheck(): formula = " + f.theFormula);
          processedQuery = f.makeQuantifiersExplicit(false);
          System.out.println(
              "INFO in Diagnostics.kbConsistencyCheck(): processedQuery = " + processedQuery);
          proof = StringUtils.join(empty.ask(processedQuery, timeout, maxAnswers), " ");
          StringBuffer a = new StringBuffer();
          a.append(reportAnswer(kb, proof, query, processedQuery, "Redundancy"));
          //  if (answer.length() != 0) return answer;
          answer.append(a);

          StringBuffer negatedQuery = new StringBuffer();
          negatedQuery.append("(not " + processedQuery + ")");
          proof = StringUtils.join(empty.ask(negatedQuery.toString(), timeout, maxAnswers), " ");
          a.append(reportAnswer(kb, proof, query, negatedQuery.toString(), "Inconsistency"));
          if (a.length() != 0) {
            answer.append(a);
            return answer.toString();
          }
        }
        empty.tell(query.theFormula);
      }
    } catch (Exception ex) {
      return ("Error in Diagnostics.kbConsistencyCheck() while executing query: "
          + ex.getMessage());
    }
    return "No contradictions or redundancies found.";
  }