Ejemplo n.º 1
0
  /**
   * *************************************************************** Return the most specific type
   * for skolem variable.
   *
   * @param tpp The structure learned from E's response
   * @param kb The knowledge base used to find skolem term's types
   *     <p>For example, original binding = esk3_0 set binding = "An instance of Human" (Human is
   *     the most specific type for esk3_0 in the given proof)
   *     <p>original binding = esk3_1 set binding = "An instance of Human, Agent" (If multiple types
   *     are found for esk3_1)
   */
  public static void findTypesForSkolemTerms(TPTP3ProofProcessor tpp, KB kb) {

    ArrayList<String> bindings = tpp.bindings;
    FormulaPreprocessor fp = new FormulaPreprocessor();
    for (int i = 0; i < bindings.size(); i++) {
      String binding = bindings.get(i);
      if (binding.startsWith("esk")) {
        ArrayList<String> skolemStmts = ProofProcessor.returnSkolemStmt(binding, tpp.proof);
        HashSet<String> types = new HashSet<>();
        for (String skolemStmt : skolemStmts) {
          Pattern p = Pattern.compile("\\(instance ([a-zA-Z0-9\\-_]+) ([a-zA-Z0-9\\-_]+)");
          Matcher m = p.matcher(skolemStmt);
          while (m.find()) {
            String cl = m.group(2);
            types.add(cl);
          }

          p = Pattern.compile("\\(subclass ([a-zA-Z0-9\\-_]+) ([a-zA-Z0-9\\-]+)");
          m = p.matcher(skolemStmt);
          while (m.find()) {
            String cl = m.group(2);
            types.add(cl);
          }
        }
        if (kb.kbCache.checkDisjoint(kb, types) == true) {
          // check if there are contradiction among the types returned from E
          bindings.remove(binding);
          binding = "Get type contradiction for " + binding + " in " + types;
          bindings.add(binding);
        } else {
          fp.winnowTypeList(types, kb);
          if (types != null && types.size() > 0) {
            if (types.size() == 1) {
              binding = "an instance of " + types.toArray()[0];
            } else {
              binding = "an instance of ";
              boolean start = true;
              for (String t : types) {
                if (start) {
                  binding += t;
                  start = false;
                } else {
                  binding += ", " + t;
                }
              }
            }
            bindings.set(i, binding);
          }
        }
      } else {
        binding = TPTP2SUMO.transformTerm(binding);
        bindings.set(i, binding);
      }
    }
  }