-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestSet.py
67 lines (56 loc) · 2.66 KB
/
TestSet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from Set import Set
from Feature import Feature
import numpy
from feature.exception import FailedProcessingFeature
from Constraints import Constraints
class TestSet(Set):
def __init__(self, *corpora):
# No inverses and closures in the test set
Set.__init__(self, False, False, False, *corpora)
self.relations_optimized = []
def create_evaluation_files(self):
for text_obj in self.text_objects:
text_obj.generate_output_tml_file()
def create_confidence_scores(self, classifier_event_event, classifier_event_timex):
# Apply the global constraints to all relations of each text object
for text_obj in self.text_objects:
# Create all confidence scores between every relation
text_obj.create_confidence_scores(classifier_event_event, classifier_event_timex)
def apply_global_model(self):
changed = 0
no_changes = 0
ee_changed = 0
et_changed = 0
improvement = 0
degradation = 0
changes_with_no_effect = 0
for text_obj in self.text_objects:
# Create all optimal relations for text object
ilp = Constraints(text_obj)
text_obj.relations_plain_optimized = ilp.get_best_set()
self.relations_optimized += text_obj.relations_plain_optimized
tmp_changed, tmp_ee_changed, tmp_et_changed, tmp_improvement, tmp_degradation, tmp_changes_with_no_effect = ilp.get_number_of_relations_changed()
changed += tmp_changed
ee_changed += tmp_ee_changed
et_changed += tmp_et_changed
improvement += tmp_improvement
degradation += tmp_degradation
changes_with_no_effect += tmp_changes_with_no_effect
print "Global model changed %s relations" % changed
print "%s relations were event-event relations" % ee_changed
print "%s relations were event-timex relations" % et_changed
print "The global model lead to %s improvements" % improvement
print "The global model introduced %s new misclassifications" % degradation
print "The global model changed %s relations wrongly which had no effect since they were already wrong" % changes_with_no_effect
def get_event_event_targets(self):
targets = []
for relation in self.relations_optimized:
if relation.is_event_event():
targets.append(relation.relation_type)
return targets
def get_event_timex_targets(self):
targets = []
for relation in self.relations_optimized:
if relation.is_event_timex():
targets.append(relation.relation_type)
return targets