-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_structure.py
executable file
·127 lines (95 loc) · 2.9 KB
/
data_structure.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
class Entity:
def __init__(self):
self.id = None
self.type = None
self.spans = [] # a couple of spans, list (start, end)
self.tkSpans = []
self.labelSpans = []
self.name = None
self.sent_idx = None
self.norm_ids = []
self.norm_names = []
self.norm_confidences = []
# for FDA challenge
self.section = None
# for ensemble
self.rule_id = None
self.vsm_id = None
self.neural_id = None
# def create(self, id, type, start, end, text, sent_idx, tf_start, tf_end):
# self.id = id
# self.type = type
# self.start = start
# self.end = end
# self.text = text
# self.sent_idx = sent_idx
# self.tf_start = tf_start
# self.tf_end = tf_end
#
# def append(self, start, end, text, tf_end):
#
# whitespacetoAdd = start - self.end
# for _ in range(whitespacetoAdd):
# self.text += " "
# self.text += text
#
# self.end = end
# self.tf_end = tf_end
#
# def getlength(self):
# return self.end-self.start
def equals(self, other):
if self.type == other.type and len(self.spans) == len(other.spans) :
for i in range(len(self.spans)) :
if self.spans[i][0] != other.spans[i][0] or self.spans[i][1] != other.spans[i][1]:
return False
return True
else:
return False
def equals_span(self, other):
if len(self.spans) == len(other.spans):
for i in range(len(self.spans)):
if self.spans[i][0] != other.spans[i][0] or self.spans[i][1] != other.spans[i][1]:
return False
return True
else:
return False
def equalsTkSpan(self, other):
if len(self.tkSpans) == len(other.tkSpans):
for i in range(len(self.tkSpans)):
if self.tkSpans[i][0] != other.tkSpans[i][0] or self.tkSpans[i][1] != other.tkSpans[i][1]:
return False
return True
else:
return False
class Document:
def __init__(self):
self.entities = None
self.sentences = None
self.name = None
self.text = None
# used for FDA challenge
class Section:
def __init__(self):
self.id = None
self.name = None
self.text = ""
class IgnoredRegion:
def __init__(self):
self.name = None
self.section = None
self.start = None
self.end = None
# for tac 2017
class Reaction:
def __init__(self):
self.id = None
self.name = None
self.normalizations = []
class Normalization:
def __init__(self):
self.id = None
self.meddra_pt = None
self.meddra_pt_id = None
self.meddra_llt = None
self.meddra_llt_id = None