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

Source Code for Module factuality_data

  1  """ 
  2  Parser for the factvalue layer in KAF/NAF 
  3  """ 
  4   
  5  from lxml import etree 
  6  from span_data import * 
  7   
  8   
9 -class Cfactval:
10
11 - def __init__(self,node=None):
12 """ 13 Constructor of the object 14 @type node: xml Element or None (to create and empty one) 15 @param node: this is the node of the element. If it is None it will create a new object 16 """ 17 self.type = 'NAF/KAF' 18 if node is None: 19 self.node = etree.Element('factVal') 20 else: 21 self.node = node
22
23 - def get_node(self):
24 """ 25 Returns the node 26 """ 27 return self.node
28
29 - def get_resource(self):
30 """ 31 Returns the resource that defines the factuality value 32 """ 33 return self.node.get('resource')
34
35 - def set_resource(self,r):
36 """ 37 Sets the resource that defines the factuality value 38 @type r: string 39 @param r: the resource defining factuality 40 """ 41 self.node.set('resource',r)
42 43
44 - def get_value(self):
45 """ 46 Returns the value of the factVal element 47 """ 48 return self.node.get('value')
49 50
51 - def set_value(self,v):
52 """ 53 Sets the value for the factVal element 54 @type v: string 55 @param v: the value for the element 56 """ 57 self.node.set('value',v)
58
59 - def get_confidence(self):
60 """ 61 Returns the confidence of the factVal element 62 """ 63 return self.node.get('confidence')
64 65
66 - def set_confidence(self,c):
67 """ 68 Sets confidence for the factVal element 69 @type c: string 70 @param c: the value for the element 71 """ 72 self.node.set('confidence',c)
73 74
75 -class Cfactuality:
76
77 - def __init__(self,node=None,type='NAF'):
78 """ 79 Constructor of the object 80 @type node: xml Element or None (to create and empty one) 81 @param node: this is the node of the element. If it is None it will create a new object 82 @type type: string 83 @param type: the type of the object (KAF or NAF) 84 """ 85 self.type = type 86 if node is None: 87 self.node = etree.Element('factuality') 88 else: 89 self.node = node
90
91 - def get_node(self):
92 """ 93 Returns the node 94 """ 95 return self.node
96 97
98 - def get_id(self):
99 """ 100 Returns the identifier of the factuality element 101 """ 102 return self.node.get('id')
103
104 - def set_id(self,this_id):
105 """ 106 Sets the id of the element 107 @type this_id: string 108 @param this_id: the resource defining factuality 109 """ 110 self.node.set('id',this_id)
111 112
113 - def get_span(self):
114 """ 115 Returns the span of the factuality element 116 @type my_span: L{Cspan} 117 @param my_span: span object 118 """ 119 span_obj = self.node.find('span') 120 if span_obj is not None: 121 return Cspan(span_obj) 122 return None
123
124 - def set_span(self,my_span):
125 """ 126 Sets the id of the element 127 @type this_id: L{Cspan} 128 @param this_id: the resource defining factuality 129 """ 130 self.node.append(my_span.get_node())
131
132 - def add_factval(self,fval):
133 """ 134 Sets the id of the element 135 @type this_id: L{Cspan} 136 @param this_id: the resource defining factuality 137 """ 138 self.node.append(fval.get_node())
139 140
141 - def get_factVals(self):
142 """ 143 Iterator to get the factuality values 144 @rtype: L{Cfactuality} 145 @return: iterator for getting the factuality's value objects 146 """ 147 for node_pre in self.node.findall('factVal'): 148 yield Cfactval(node_pre)
149 150
151 -class Cfactualities:
152 """ 153 This class represents the new factuality layer 154 """
155 - def __init__(self,node=None,type='NAF'):
156 """ 157 Constructor of the object 158 @type node: xml ELement or None (to create an empty one) 159 @param node: this is the node of the element. If it is None it will create a new object 160 @type type: string 161 @param type: the type of the object (KAF or NAF), NAF is default 162 """ 163 self.type = type 164 if node is None: 165 self.node = etree.Element('factualities') 166 else: 167 self.node = node
168
169 - def get_node(self):
170 """ 171 Returns the node of the element 172 @rtype: xml Element 173 @return: the node of the element 174 """ 175 return self.node
176 177
178 - def add_factuality(self, factval):
179 """ 180 Adds a factuality element to the layer 181 """ 182 self.node.append(factval.get_node())
183 184
185 - def get_factualities(self):
186 """ 187 Iterator to get the factualities 188 @rtype: L{Cfactuality} 189 @return: iterator for getting the factuality objects 190 """ 191 for node_pre in self.node.findall('factuality'): 192 yield Cfactuality(node_pre)
193
194 - def to_kaf(self):
195 pass
196
197 - def to_naf(self):
198 pass
199
200 - def __str__(self):
201 return dump(self.node)
202 203 204 205 206
207 -class Cfactvalue:
208 """ 209 This class encapsulates a factvalue object in KAF/NAF (old version) 210 """
211 - def __init__(self,node=None):
212 """ 213 Constructor of the object 214 @type node: xml Element or None (to create and empty one) 215 @param node: this is the node of the element. 216 If it is None it will create a new object 217 """ 218 if node is None: 219 self.node = etree.Element('factvalue') 220 else: 221 self.node = node
222
223 - def get_node(self):
224 """ 225 Returns the node of the element 226 @rtype: xml Element 227 @return: the node of the element 228 """ 229 return self.node
230
231 - def get_id(self):
232 """ 233 Returns the fact identifier 234 @rtype: string 235 @return: the fact identifier 236 """ 237 return self.node.get('id')
238
239 - def get_prediction(self):
240 """ 241 Returns the prediction attribute of the factvalue 242 @rtype: string 243 @return: the prediction attribute 244 """ 245 return self.node.get('prediction')
246
247 - def get_confidence(self):
248 """ 249 Returns the confidence of the element 250 @rtype: string 251 @return: the confidence of the element 252 """ 253 return self.node.get('confidence')
254
255 - def set_id(self,this_id):
256 """ 257 Set the identifier for the fact 258 @type this_id: string 259 @param this_id: the identifier 260 """ 261 return self.node.set('id',this_id)
262
263 - def set_prediction(self,prediction):
264 """ 265 Sets the prediction attribute 266 @type prediction: string 267 @param prediction: the prediction attribute 268 """ 269 self.node.set('prediction',prediction)
270
271 - def set_confidence(self,confidence):
272 """ 273 Sets the confidence attribute 274 @type confidence: string 275 @param confidence: the confidence attribute 276 """ 277 self.node.set('confidence',confidence)
278
279 - def __str__(self):
280 return dump(self.node)
281
282 -class Cfactualitylayer:
283 """ 284 This class encapsulates the factvalue layer in KAF/NAF (old version) 285 """
286 - def __init__(self,node=None):
287 """ 288 Constructor of the object 289 @type node: xml Element or None (to create and empty one) 290 @param node: this is the node of the element. 291 If it is None it will create a new object 292 """ 293 if node is None: 294 self.node = etree.Element('factualitylayer') 295 else: 296 self.node = node
297
298 - def get_node(self):
299 """ 300 Returns the node of the element 301 @rtype: xml Element 302 @return: the node of the element 303 """ 304 return self.node
305
306 - def to_kaf(self):
307 pass
308
309 - def to_naf(self):
310 pass
311
312 - def __str__(self):
313 return dump(self.node)
314
315 - def __get_factvalue_nodes(self):
316 for node_factvalue in self.node.findall('factvalue'): 317 yield node_factvalue
318
319 - def get_factvalues(self):
320 """ 321 Iterator that returns all the factualitylayer in the layer 322 @rtype: L{Cfactvalue} 323 @return: list of factualitylayer (iterator) 324 """ 325 for node in self.__get_factvalue_nodes(): 326 yield Cfactvalue(node)
327
328 - def add_factvalue(self,my_factvalue):
329 """ 330 Adds a factvalue object to the layer 331 @type my_factvalue: L{Cfactvalue} 332 @param my_factvalue: the factvalue object to be added 333 """ 334 self.node.append(my_factvalue.get_node())
335
336 - def remove_this_factvalue(self,factvalue_id):
337 """ 338 Removes the factvalue for the given factvalue identifier 339 @type factvalue_id: string 340 @param factvalue_id: the factvalue identifier to be removed 341 """ 342 for fact in self.get_factvalues(): 343 if fact.get_id() == factvalue_id: 344 self.node.remove(fact.get_node()) 345 break
346