Module temporal_data
[hide private]
[frames] | no frames]

Source Code for Module temporal_data

  1  """ 
  2  Parser for the tlink layer in KAF/NAF 
  3  """ 
  4  from lxml import etree 
  5   
145   
146 -class CpredicateAnchor:
147 """ 148 This class encapsulates the predicateAnchor object in KAF/NAF 149 """ 150
151 - def __init__(self,node=None):
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
165 - def get_node(self):
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
174 - def set_id(self,this_id):
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
183 - def get_id(self):
184 """ 185 Returns the token identifier 186 @rtype: string 187 @return: the token identifier 188 """ 189 return self.node.get('id')
190 191
192 - def get_anchorTime(self):
193 """ 194 Returns the anchorTime 195 @rtype: string 196 @return: the anchorTime 197 """ 198 return self.node.get('anchorTime')
199 200
201 - def set_anchorTime(self,anchorTime):
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
209 - def get_endPoint(self):
210 """ 211 Returns the endPoint 212 @rtype: string 213 @return: the endPoint 214 """ 215 return self.node.get('endPoint')
216 217
218 - def set_endPoint(self,endPoint):
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
227 - def get_beginPoint(self):
228 """ 229 Returns the beginPoint 230 @rtype: string 231 @return: the beginPoint 232 """ 233 return self.node.get('beginPoint')
234 235
236 - def set_beginPoint(self,beginPoint):
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
245 - def get_span(self):
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
257 - def set_span(self,this_span):
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
269 -class CtemporalRelations:
270 """ 271 This class encapsulates the tlink layer in KAF/NAF 272 """
273 - def __init__(self,node=None):
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
285 - def get_node(self):
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
293 - def to_kaf(self):
294 pass
295
296 - def to_naf(self):
297 pass
298
299 - def __str__(self):
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 320 321
322 - def get_predicateAnchors(self):
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 338 349
350 - def add_predicateAnchor(self,my_predAnch):
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
358 - def remove_this_predicateAnchor(self,predAnch_id):
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