1 """
2 Parser for the references objects in KAF/NAF
3 """
4
5 from span_data import *
6
8 """
9 This class encapsulates the references objects in KAF/NAF
10 """
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('references')
20 else:
21 self.node = node
22
24 """
25 Returns the node of the element
26 @rtype: xml Element
27 @return: the node of the element
28 """
29 return self.node
30
32 """
33 Iterator that returns all the span objects in the reference
34 @rtype: L{Cspan}
35 @return: list of span objects (iterator)
36 """
37 for span_node in self.node.findall('span'):
38 yield Cspan(span_node)
39
41 """
42 Adds a list of term ids a new span in the references
43 @type term_span: list
44 @param term_span: list of term ids
45 """
46 new_span = Cspan()
47 new_span.create_from_ids(term_span)
48 self.node.append(new_span.get_node())
49
51 """
52 Returns the span object of the reference
53 @rtype: L{Cspan}
54 @return: the term span
55 """
56 node_span = self.node.find('span')
57 if node_span is not None:
58 return Cspan(node_span)
59 else:
60 return None
61
63 """
64 Sets the span for the lemma
65 @type this_span: L{Cspan}
66 @param this_span: lemma identifier
67 """
68 self.node.append(this_span.get_node())
69