Skip to content

Commit bb5bf97

Browse files
author
Pascual Martinez-Gomez
committed
Reproduced EACL result in this branch for trial set
1 parent f91c6aa commit bb5bf97

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

scripts/abduction_tools.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def GetConclusionLine(coq_output_lines):
8181
return None
8282
return coq_output_lines[line_index_last_conclusion_sep + 1]
8383

84+
# This function was used for EACL 2017.
8485
def GetPremisesThatMatchConclusionArgs_(premises, conclusion):
8586
"""
8687
Returns premises where the predicates have at least one argument
@@ -126,6 +127,13 @@ def MakeAxiomsFromPremisesAndConclusion(premises, conclusion):
126127
axioms = MakeAxiomsFromPreds(premise_preds, conclusion_pred, pred_args)
127128
return axioms
128129

130+
def parse_coq_line(coq_line):
131+
try:
132+
tree_args = tree_or_string('(' + coq_line + ')')
133+
except ValueError:
134+
tree_args = None
135+
return tree_args
136+
129137
def get_tree_pred_args(line, is_conclusion=False):
130138
"""
131139
Given the string representation of a premise, where each premise is:
@@ -137,10 +145,10 @@ def get_tree_pred_args(line, is_conclusion=False):
137145
"""
138146
tree_args = None
139147
if not is_conclusion:
140-
tree_args = tree_or_string('(' + ' '.join(line.split()[2:]) + ')')
148+
tree_args = parse_coq_line(' '.join(line.split()[2:]))
141149
else:
142-
tree_args = tree_or_string('(' + line + ')')
143-
if len(tree_args) < 1:
150+
tree_args = parse_coq_line(line)
151+
if tree_args is None or len(tree_args) < 1:
144152
return None
145153
return tree_args[0]
146154

scripts/tree_tools.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def IsString(variable):
2727
def get_top(tr):
2828
"""Given a thing that might be a tree or maybe a terminal string, return
2929
the 'top' of it -- either the node of a tree, or just the string itself."""
30+
if tr is None:
31+
return None
3032
return (tr if IsString(tr) else tr.label())
3133

3234

@@ -37,6 +39,9 @@ def TreeContains(tree, subtree):
3739
# Subtree is a variable, and matches everything.
3840
subtree_top = get_top(subtree)
3941
tree_top = get_top(tree)
42+
if tree_top is None or subtree_top is None:
43+
return False
44+
4045
if subtree_top.startswith('?x') and not tree_is_inst_nltk:
4146
# Get type of the variable.
4247
var_type = '|'.join(subtree_top.split('|')[1:])

0 commit comments

Comments
 (0)