Module external_references_data
|
|
1 """
2 Parser for the external references object in KAF/NAF
3 """
4
5
6 from term_sentiment_data import Cterm_sentiment
7 from lxml import etree
8
10 """
11 This class encapsulates the external reference object in KAF/NAF
12 """
14 """
15 Constructor of the object
16 @type node: xml Element or None (to create and empty one)
17 @param node: this is the node of the element. If it is None it will create a new object
18 """
19 self.type= 'NAF/KAF'
20
21 if node is None:
22 self.node = etree.Element('externalRef')
23 else:
24 self.node = node
25
27 """
28 Returns the node of the element
29 @rtype: xml Element
30 @return: the node of the element
31 """
32 return self.node
33
35 """
36 Returns the external references of an external reference (can be nested)
37 @rtype: L{CexternalReference}
38 @return: iterator of external references
39 """
40 for node in self.node.findall('externalRef'):
41 yield CexternalReference(node)
42
45
47 """
48 Sets the resource for the element
49 @type resource: string
50 @param resource: the resource of the element
51 """
52 self.node.set('resource',resource)
53
55 """
56 Sets the confidence for the element
57 @type confidence: string
58 @param confidence: the confidence of the element
59 """
60 self.node.set('confidence',confidence)
61
63 """
64 Sets the reference for the element
65 @type reference: string
66 @param reference: the reference of the element
67 """
68 self.node.set('reference',reference)
69
71 """
72 Returns the resource of the element
73 @rtype: string
74 @return: the resource of the element
75 """
76 return self.node.get('resource')
77
79 """
80 Returns the confidence of the element
81 @rtype: string
82 @return: the confidence of the element
83 """
84 return self.node.get('confidence')
85
87 """
88 Returns the reference attribute of the element
89 @rtype: string
90 @return: the reference attribute of the element
91 """
92 return self.node.get('reference')
93
95 """
96 Sets the reftype for the element
97 @type r: string
98 @param r: the reftype of the element
99 """
100 self.node.set('reftype',r)
101
103 """
104 Returns the reftype attribute of the element
105 @rtype: string
106 @return: the reftype attribute of the element
107 """
108 return self.node.get('reftype')
109
111 """
112 Sets the source for the element
113 @type r: string
114 @param r: the source of the element
115 """
116 self.node.set('source',r)
117
119 """
120 Returns the source attribute of the element
121 @rtype: string
122 @return: the source attribute of the element
123 """
124 return self.node.get('source')
125
126
128 """
129 This class encapsulates the external references object, which is a set of external reference objects
130 """
132 """
133 Constructor of the object
134 @type node: xml Element or None (to create and empty one)
135 @param node: this is the node of the element. If it is None it will create a new object
136 """
137 if node is None:
138 self.node = etree.Element('externalReferences')
139 else:
140 self.node = node
141
143 """
144 Adds an external reference to the layer
145 @type ext_ref: L{CexternalReference}
146 @param ext_ref: an external reference object
147 """
148 self.node.append(ext_ref.get_node())
149
151 """
152 Returns the node of the element
153 @rtype: xml Element
154 @return: the node of the element
155 """
156 return self.node
157
159 """
160 Iterator that returns all the external reference objects
161 @rtype: L{CexternalReference}
162 @return: list of external references (iterator)
163 """
164 for node in self.node.findall('externalRef'):
165 yield CexternalReference(node)
166