1 """
2 Parser for the tlink layer in KAF/NAF
3 """
4 from lxml import etree
5
7 """
8 This class encapsulates a tlink object in KAF/NAF
9 """
11 """
12 Constructor of the object
13 @type node: xml Element or None (to create and empty one)
14 @param node: this is the node of the element.
15 If it is None it will create a new object
16 """
17 if node is None:
18 self.node = etree.Element('tlink')
19 else:
20 self.node = node
21
29
31 """
32 Returns the node of the element
33 @rtype: xml Element
34 @return: the node of the element
35 """
36 return self.node
37
39 """
40 Returns the token identifier
41 @rtype: string
42 @return: the token identifier
43 """
44 return self.node.get('id')
45
47 """
48 Returns the from attribute of the tlink
49 @rtype: string
50 @return: the from attribute
51 """
52 return self.node.get('from')
53
55 """
56 Returns the from attribute of the tlink
57 @rtype: string
58 @return: the from attribute
59 """
60 return self.node.get('fromType')
61
63 """
64 Returns the to attribute of the tlink
65 @rtype: string
66 @return: the to attribute
67 """
68 return self.node.get('to')
69
71 """
72 Returns the to attribute of the tlink
73 @rtype: string
74 @return: the to attribute
75 """
76 return self.node.get('toType')
77
79 """
80 Returns the to attribute of the tlink
81 @rtype: string
82 @return: the to attribute
83 """
84 return self.node.get('relType')
85
87 """
88 Set the identifier for the token
89 @type this_id: string
90 @param this_id: the identifier
91 """
92 return self.node.set('id',this_id)
93
95 """
96 Sets the from attribute
97 @type f: string
98 @param f: the from attribute
99 """
100 self.node.set('from',f)
101
103 """
104 Sets the from attribute
105 @type f: string
106 @param f: the from attribute
107 """
108 self.node.set('fromType',f)
109
111 """
112 Sets the to attribute
113 @type t: string
114 @param t: the to attribute
115 """
116 self.node.set('to',t)
117
119 """
120 Sets the to attribute
121 @type t: string
122 @param t: the to attribute
123 """
124 self.node.set('toType',t)
125
127 """
128 Sets the to attribute
129 @type t: string
130 @param t: the to attribute
131 """
132 self.node.set('relType',t)
133
142
144 return dump(self.node)
145
147 """
148 This class encapsulates the predicateAnchor object in KAF/NAF
149 """
150
152 """
153 Constructor of the object
154 @type node: xml Element or None (to create and empty one)
155 @param node: this is the node of the element.
156 If it is None it will create a new object
157 """
158 if node is None:
159 self.node = etree.Element('predicateAnchor')
160 else:
161 self.node = node
162
163
164
166 """
167 Returns the node of the element
168 @rtype: xml Element
169 @return: the node of the element
170 """
171 return self.node
172
173
175 """
176 Set the identifier for the token
177 @type this_id: string
178 @param this_id: the identifier
179 """
180 return self.node.set('id',this_id)
181
182
184 """
185 Returns the token identifier
186 @rtype: string
187 @return: the token identifier
188 """
189 return self.node.get('id')
190
191
193 """
194 Returns the anchorTime
195 @rtype: string
196 @return: the anchorTime
197 """
198 return self.node.get('anchorTime')
199
200
202 """
203 Set the anchor time for the event
204 @type anchorTime: string
205 @param anchorTime: the anchorTime id
206 """
207 return self.node.set('anchorTime',anchorTime)
208
210 """
211 Returns the endPoint
212 @rtype: string
213 @return: the endPoint
214 """
215 return self.node.get('endPoint')
216
217
219 """
220 Set the endPoint for the event
221 @type endPoint: string
222 @param endPoint: the endPoint id
223 """
224 return self.node.set('endPoint',endPoint)
225
226
228 """
229 Returns the beginPoint
230 @rtype: string
231 @return: the beginPoint
232 """
233 return self.node.get('beginPoint')
234
235
237 """
238 Set the beginPoint for the event
239 @type beginPoint: string
240 @param beginPoint: the beginPoint id
241 """
242 return self.node.set('beginPoint',beginPoint)
243
244
246 """
247 Returns the span object of the term
248 @rtype: L{Cspan}
249 @return: the term span
250 """
251 node_span = self.node.find('span')
252 if node_span is not None:
253 return Cspan(node_span)
254 else:
255 return None
256
258 """
259 Sets the span for the lemma
260 @type this_span: L{Cspan}
261 @param this_span: lemma identifier
262 """
263 self.node.append(this_span.get_node())
264
265
266
267
268
270 """
271 This class encapsulates the tlink layer in KAF/NAF
272 """
274 """
275 Constructor of the object
276 @type node: xml Element or None (to create and empty one)
277 @param node: this is the node of the element.
278 If it is None it will create a new object
279 """
280 if node is None:
281 self.node = etree.Element('temporalRelations')
282 else:
283 self.node = node
284
286 """
287 Returns the node of the element
288 @rtype: xml Element
289 @return: the node of the element
290 """
291 return self.node
292
295
298
300 return dump(self.node)
301
302
304 for node_tlink in self.node.findall('tlink'):
305 yield node_tlink
306
307
309 for node_predAnch in self.node.findall('predicateAnchor'):
310 yield node_predAnch
311
313 """
314 Iterator that returns all the temporalRelations in the layer
315 @rtype: L{Ctlink}
316 @return: list of temporalRelations (iterator)
317 """
318 for node in self.__get_node_temporalRelations():
319 yield Ctlink(node)
320
321
323 """
324 Iterator that returns all the temporalRelation anchors in the layer
325 @rtype: L{CpredicateAnchor}
326 @return: list of temporalRelations (iterator)
327 """
328 for node in self.__get_node_predicateAnchors():
329 yield CpredicateAnchor(node)
330
332 """
333 Adds a tlink object to the layer
334 @type my_tlink: L{Ctlink}
335 @param my_tlink: the tlink object to be added
336 """
337 self.node.append(my_tlink.get_node())
338
340 """
341 Removes the tlink for the given tlink identifier
342 @type tlink_id: string
343 @param tlink_id: the tlink identifier to be removed
344 """
345 for tlink in self.get_tlinks():
346 if tlink.get_id() == tlink_id:
347 self.node.remove(tlink.get_node())
348 break
349
351 """
352 Adds a predAnch object to the layer
353 @type my_predAnch: L{CpredAnch}
354 @param my_predAnch: the predAnc object to be added
355 """
356 self.node.append(my_predAnch.get_node())
357
359 """
360 Removes the predicate anchor for the given predicate anchor identifier
361 @type predAnch_id: string
362 @param predAnch_id: the predicate anchor identifier to be removed
363 """
364 for predAnch in self.get_predicateAnchors():
365 if predAnch.get_id() == predAnch_id:
366 self.node.remove(predAnch.get_node())
367 break
368