|
1 | 1 | #!/usr/bin/python |
2 | 2 | # -*- coding: utf-8 -*- |
| 3 | +from __future__ import print_function |
3 | 4 |
|
4 | 5 | import codecs |
| 6 | +from collections import OrderedDict |
| 7 | +import json |
5 | 8 | import logging |
6 | 9 | import re |
7 | 10 | from subprocess import call, Popen |
8 | 11 | import subprocess |
| 12 | +import sys |
9 | 13 |
|
10 | 14 | from nltk import Tree |
11 | 15 |
|
12 | 16 | from knowledge import GetLexicalRelationsFromPreds |
| 17 | +from normalization import denormalize_token |
13 | 18 | from semantic_tools import is_theorem_defined |
14 | 19 | from tactics import get_tactics |
15 | 20 | from tree_tools import tree_or_string, TreeContains |
@@ -119,12 +124,38 @@ def GetPremisesThatMatchConclusionArgs(premises, conclusion): |
119 | 124 | candidate_premises.append(premise_line) |
120 | 125 | return candidate_premises |
121 | 126 |
|
| 127 | +def make_failure_log(conclusion_pred, premise_preds, conclusion, premises): |
| 128 | + """ |
| 129 | + Produces a dictionary with the following structure: |
| 130 | + {"unproved sub-goal" : "sub-goal_predicate", |
| 131 | + "matching premises" : ["premise1", "premise2", ...], |
| 132 | + "raw sub-goal" : "conclusion", |
| 133 | + "raw premises" : ["raw premise1", "raw premise2", ...]} |
| 134 | + Raw sub-goal and raw premises are the coq lines with the premise |
| 135 | + internal name and its predicates. E.g. |
| 136 | + H : premise (Acc x1) |
| 137 | + Note that this function is not capable of returning all unproved |
| 138 | + sub-goals in coq's stack. We only return the top unproved sub-goal. |
| 139 | + """ |
| 140 | + failure_log = OrderedDict() |
| 141 | + conclusion_base = denormalize_token(conclusion_pred) |
| 142 | + failure_log["unproved sub-goal"] = conclusion_base |
| 143 | + premises_base = [denormalize_token(p) for p in premise_preds] |
| 144 | + failure_log["matching premises"] = premises_base |
| 145 | + failure_log["raw sub-goal"] = conclusion |
| 146 | + failure_log["raw premises"] = premises |
| 147 | + return failure_log |
| 148 | + |
122 | 149 | def MakeAxiomsFromPremisesAndConclusion(premises, conclusion): |
123 | 150 | matching_premises = GetPremisesThatMatchConclusionArgs(premises, conclusion) |
124 | 151 | premise_preds = [premise.split()[2] for premise in matching_premises] |
125 | 152 | conclusion_pred = conclusion.split()[0] |
126 | 153 | pred_args = GetPredicateArguments(premises, conclusion) |
127 | 154 | axioms = MakeAxiomsFromPreds(premise_preds, conclusion_pred, pred_args) |
| 155 | + if not axioms and 'False' not in conclusion_pred: |
| 156 | + failure_log = make_failure_log( |
| 157 | + conclusion_pred, premise_preds, conclusion, premises) |
| 158 | + print(json.dumps(failure_log), file=sys.stderr) |
128 | 159 | return axioms |
129 | 160 |
|
130 | 161 | def parse_coq_line(coq_line): |
@@ -299,33 +330,3 @@ def TryAbduction(coq_script, previous_axioms=set(), expected='yes'): |
299 | 330 | inference_result_str = expected if IsTheoremDefined(output_lines) else 'unknown' |
300 | 331 | return inference_result_str, [new_coq_script], axioms |
301 | 332 |
|
302 | | -def main(args = None): |
303 | | - finput_filename = 'abduction/test1.out' |
304 | | - finput = codecs.open(finput_filename, 'r', 'utf-8') |
305 | | - lines = [line.strip() for line in finput.readlines()] |
306 | | - finput.close() |
307 | | - |
308 | | - print('Is incomplete proof: {0}'.format(IsIncompleteProof(lines))) |
309 | | - |
310 | | - print('Premises:') |
311 | | - premise_lines = GetPremiseLines(lines) |
312 | | - for premise_line in premise_lines: |
313 | | - print(premise_line) |
314 | | - |
315 | | - print('Conclusion:') |
316 | | - conclusion = GetConclusionLine(lines) |
317 | | - print(conclusion) |
318 | | - |
319 | | - matching_premises = GetPremisesThatMatchConclusionArgs(premise_lines, conclusion) |
320 | | - print('Matching premises:') |
321 | | - for premise in matching_premises: |
322 | | - print(premise) |
323 | | - |
324 | | - axioms = MakeAxiomsFromPremisesAndConclusion(premise_lines, conclusion) |
325 | | - print('Axioms:') |
326 | | - for axiom in axioms: |
327 | | - print(axiom) |
328 | | - |
329 | | -if __name__ == '__main__': |
330 | | - main() |
331 | | - |
|
0 commit comments