Skip to content

Commit

Permalink
Report exact tree match
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitakit committed Feb 1, 2019
1 parent 8238e79 commit cc62f28
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
import trees

class FScore(object):
def __init__(self, recall, precision, fscore, tagging_accuracy=100):
def __init__(self, recall, precision, fscore, complete_match, tagging_accuracy=100):
self.recall = recall
self.precision = precision
self.fscore = fscore
self.complete_match = complete_match
self.tagging_accuracy = tagging_accuracy

def __str__(self):
if self.tagging_accuracy < 100:
return "(Recall={:.2f}, Precision={:.2f}, FScore={:.2f}, TaggingAccuracy={:.2f})".format(
self.recall, self.precision, self.fscore, self.tagging_accuracy)
return "(Recall={:.2f}, Precision={:.2f}, FScore={:.2f}, CompleteMatch={:.2f}, TaggingAccuracy={:.2f})".format(
self.recall, self.precision, self.fscore, self.complete_match, self.tagging_accuracy)
else:
return "(Recall={:.2f}, Precision={:.2f}, FScore={:.2f})".format(
self.recall, self.precision, self.fscore, self.tagging_accuracy)
return "(Recall={:.2f}, Precision={:.2f}, FScore={:.2f}, CompleteMatch={:.2f})".format(
self.recall, self.precision, self.fscore, self.complete_match)

def evalb(evalb_dir, gold_trees, predicted_trees, ref_gold_path=None):
assert os.path.exists(evalb_dir)
Expand Down Expand Up @@ -77,7 +78,7 @@ def evalb(evalb_dir, gold_trees, predicted_trees, ref_gold_path=None):
)
subprocess.run(command, shell=True)

fscore = FScore(math.nan, math.nan, math.nan)
fscore = FScore(math.nan, math.nan, math.nan, math.nan)
with open(output_path) as infile:
for line in infile:
match = re.match(r"Bracketing Recall\s+=\s+(\d+\.\d+)", line)
Expand All @@ -89,6 +90,9 @@ def evalb(evalb_dir, gold_trees, predicted_trees, ref_gold_path=None):
match = re.match(r"Bracketing FMeasure\s+=\s+(\d+\.\d+)", line)
if match:
fscore.fscore = float(match.group(1))
match = re.match(r"Complete match\s+=\s+(\d+\.\d+)", line)
if match:
fscore.complete_match = float(match.group(1))
match = re.match(r"Tagging accuracy\s+=\s+(\d+\.\d+)", line)
if match:
fscore.tagging_accuracy = float(match.group(1))
Expand Down

0 comments on commit cc62f28

Please sign in to comment.