/** * *************************************************************** Compute binding and proof from * E's response */ public static TPTP3ProofProcessor parseProofOutput(ArrayList<String> lines, KB kb) { TPTP3ProofProcessor tpp = new TPTP3ProofProcessor(); try { boolean inProof = false; boolean finishAnswersTuple = false; String line; Iterator<String> it = lines.iterator(); while (it.hasNext()) { line = it.next(); if (line.indexOf("SZS output start") != -1) { inProof = true; line = it.next(); } if (line.indexOf("SZS status") != -1) { tpp.status = line.substring(15); } if (line.indexOf("SZS answers") != -1) { if (!finishAnswersTuple) { tpp.processAnswers(line.substring(20).trim()); finishAnswersTuple = true; } } if (inProof) { if (line.indexOf("SZS output end") != -1) { inProof = false; } else { ProofStep ps = tpp.parseProofStep(line); if (ps != null) { tpp.proof.add(ps); } } } } } catch (Exception ex) { System.out.println(ex.getMessage()); } // remove unnecessary steps, eg: conjectures, duplicate trues tpp.proof = ProofStep.removeUnnecessary(tpp.proof); tpp.proof = ProofStep.removeDuplicates(tpp.proof); // find types for skolem terms findTypesForSkolemTerms(tpp, kb); return tpp; }
/** * *************************************************************** Parse a step like the following * into its constituents fof(c_0_5, axiom, (s__subclass(s__Artifact,s__Object)), c_0_3). * * <p>fof(c_0_2, negated_conjecture, (~(?[X1]:(s__subclass(X1,s__Object)&~$answer(esk1_1(X1))))), * inference(assume_negation,[status(cth)],[inference(add_answer_literal,[status(thm)],[c_0_0, * theory(answers)])])). */ public ProofStep parseProofStep(String line) { if (StringUtil.emptyString(line)) return null; ProofStep ps = new ProofStep(); // System.out.println("Info in TPTP3ProofProcessor.parseProofStep(): " + line); int paren = line.indexOf("("); if (paren == -1) { System.out.println("Error in TPTP3ProofProcessor.parseProofStep() bad format: " + line); return null; } String type = line.substring(0, paren); if (!line.endsWith(").")) { System.out.println("Error in TPTP3ProofProcessor.parseProofStep() bad format: " + line); return null; } String withoutWrapper = line.substring(paren + 1, line.length() - 2); int comma1 = withoutWrapper.indexOf(","); String id = withoutWrapper.substring(0, comma1).trim(); // System.out.println("ID : " + id); Integer intID = new Integer(idCounter++); idTable.put(id, intID); ps.number = intID; int comma2 = withoutWrapper.indexOf(",", comma1 + 1); String formulaType = withoutWrapper.substring(comma1 + 1, comma2).trim(); ps.formulaType = formulaType; // System.out.println("type : " + formulaType); String rest = withoutWrapper.substring(comma2 + 1).trim(); int statementEnd = StringUtil.findBalancedParen( rest.indexOf("("), rest); // startIndex = index_of_first_"(", instead of 0; // TODO: check if exists "=" if (statementEnd == rest.length() - 1) // sepecial case: rest = "s__Class30_1=s__Reptile, // file('/var/folders/s4/38700c8541z9h0t0sy_6lmk40000gn/T//epr_diiVH1', i_0_23)" statementEnd = rest.indexOf(","); // expected: "foo(s__Class30_1,s__Reptile), // file('/var/folders/s4/38700c8541z9h0t0sy_6lmk40000gn/T//epr_diiVH1', i_0_23)" String stmnt = trimParens(rest.substring(0, statementEnd + 1).trim()); // System.out.println("stmnt : " + stmnt); // line = line.replaceAll("\\$answer\\(","answer("); // System.out.println("after remove $answer: " + line); StringReader reader = new StringReader(line); // kif = TPTP2SUMO.convert(reader, false); try { TPTPParser tptpP = TPTPParser.parse(new BufferedReader(reader)); // System.out.println(tptpP.Items.get(0)); Iterator<String> it = tptpP.ftable.keySet().iterator(); while (it.hasNext()) { String tptpid = it.next(); TPTPFormula tptpF = tptpP.ftable.get(tptpid); stmnt = TPTP2SUMO.convertType(tptpF, 0, 0, true).toString(); } } catch (Exception e) { System.out.println("Error in TPTP3ProofProcessor.parseProofStep(): " + e.getMessage()); e.printStackTrace(); System.out.println("with input: " + line); } // System.out.println("KIF stmnt : " + stmnt); ps.axiom = stmnt; String supportId = rest.substring(statementEnd + 2, rest.length()).trim(); // System.out.println("supportID: " + supportId); // add an inference type ps.inferenceType = getInferenceType(supportId.trim()); ps.premises.addAll(parseSupports(supportId.trim())); return ps; }