From 9e0a8216f4919d566a212329b8a16d6bf768b13f Mon Sep 17 00:00:00 2001 From: pedrojlazevedo Date: Sun, 15 Mar 2020 18:37:50 +0000 Subject: [PATCH] Finishing parsing Gold for every Claim --- metrics.py | 15 +++------------ metrics/claim.py | 7 +++++++ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/metrics.py b/metrics.py index 67792d4b..e088058b 100644 --- a/metrics.py +++ b/metrics.py @@ -41,16 +41,6 @@ lines['claim'] = lines['claim'].replace("-RRB-", " ) ") train_concatenate.append(lines) -# this evidence addition is irrelevant -info_by_id = dict((d['id'], dict(d, index=index)) for (index, d) in enumerate(train_set)) -for lines in train_predictions_file: - #print(lines['id']) - lines['evidence'] = info_by_id.get(lines['id'])['evidence'] - train_prediction.append(lines) - -# All claims -stop = 0 - # List with dicts with all important data ''' id : id of the claim @@ -93,10 +83,11 @@ total_claim = 0 for claim in train_relevant: _id = claim['id'] - gold_dict = gold_data.get(_id) + _claim = Claim.find_by_id(_id)[0] # no search is needed... no information on gold dict about retrieval - if not gold_dict['verifiable']: + print(_claim.id) + if not _claim.verifiable: continue # document analysis diff --git a/metrics/claim.py b/metrics/claim.py index 76ddee08..924ac104 100644 --- a/metrics/claim.py +++ b/metrics/claim.py @@ -1,7 +1,9 @@ from metrics.evidence import Evidence +from collections import defaultdict class Claim: + id_index = defaultdict(list) def __init__(self, _id, name, verifiable): self.id = _id @@ -11,6 +13,7 @@ def __init__(self, _id, name, verifiable): else: self.verifiable = 0 self.gold_evidence = [] + Claim.id_index[_id].append(self) def add_gold_evidence(self, document, evidence, line_num): evidence = Evidence(document, evidence, line_num) @@ -31,3 +34,7 @@ def get_gold_documents(self): for e in self.gold_evidence: docs |= e.documents return docs + + @classmethod + def find_by_id(cls, _id): + return Claim.id_index[_id]