forked from cltl/KafNafParserPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal_references_data.py
More file actions
167 lines (145 loc) · 4.9 KB
/
Copy pathexternal_references_data.py
File metadata and controls
167 lines (145 loc) · 4.9 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
"""
Parser for the external references object in KAF/NAF
"""
# included modification for KAF/NAF
from term_sentiment_data import Cterm_sentiment
from lxml import etree
class CexternalReference:
"""
This class encapsulates the external reference object in KAF/NAF
"""
def __init__(self,node=None):
"""
Constructor of the object
@type node: xml Element or None (to create and empty one)
@param node: this is the node of the element. If it is None it will create a new object
"""
self.type= 'NAF/KAF'
#self.resource = self.reference = self.reftype = self.status = self.source = self.confidence = ''
if node is None:
self.node = etree.Element('externalRef')
else:
self.node = node
def get_node(self):
"""
Returns the node of the element
@rtype: xml Element
@return: the node of the element
"""
return self.node
def get_external_references(self):
"""
Returns the external references of an external reference (can be nested)
@rtype: L{CexternalReference}
@return: iterator of external references
"""
for node in self.node.findall('externalRef'):
yield CexternalReference(node)
def add_external_reference(self,ext_ref):
self.node.append(ext_ref.get_node())
def set_resource(self,resource):
"""
Sets the resource for the element
@type resource: string
@param resource: the resource of the element
"""
self.node.set('resource',resource)
def set_confidence(self,confidence):
"""
Sets the confidence for the element
@type confidence: string
@param confidence: the confidence of the element
"""
self.node.set('confidence',confidence)
def set_reference(self,reference):
"""
Sets the reference for the element
@type reference: string
@param reference: the reference of the element
"""
self.node.set('reference',reference)
def get_resource(self):
"""
Returns the resource of the element
@rtype: string
@return: the resource of the element
"""
return self.node.get('resource')
def get_confidence(self):
"""
Returns the confidence of the element
@rtype: string
@return: the confidence of the element
"""
return self.node.get('confidence')
def get_reference(self):
"""
Returns the reference attribute of the element
@rtype: string
@return: the reference attribute of the element
"""
return self.node.get('reference')
def set_reftype(self,r):
"""
Sets the reftype for the element
@type r: string
@param r: the reftype of the element
"""
self.node.set('reftype',r)
def get_reftype(self):
"""
Returns the reftype attribute of the element
@rtype: string
@return: the reftype attribute of the element
"""
return self.node.get('reftype')
def set_source(self,r):
"""
Sets the source for the element
@type r: string
@param r: the source of the element
"""
self.node.set('source',r)
def get_source(self):
"""
Returns the source attribute of the element
@rtype: string
@return: the source attribute of the element
"""
return self.node.get('source')
class CexternalReferences:
"""
This class encapsulates the external references object, which is a set of external reference objects
"""
def __init__(self,node=None):
"""
Constructor of the object
@type node: xml Element or None (to create and empty one)
@param node: this is the node of the element. If it is None it will create a new object
"""
if node is None:
self.node = etree.Element('externalReferences')
else:
self.node = node
def add_external_reference(self,ext_ref):
"""
Adds an external reference to the layer
@type ext_ref: L{CexternalReference}
@param ext_ref: an external reference object
"""
self.node.append(ext_ref.get_node())
def get_node(self):
"""
Returns the node of the element
@rtype: xml Element
@return: the node of the element
"""
return self.node
def __iter__(self):
"""
Iterator that returns all the external reference objects
@rtype: L{CexternalReference}
@return: list of external references (iterator)
"""
for node in self.node.findall('externalRef'):
yield CexternalReference(node)