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

Source Code for Module external_references_data

  1  """ 
  2  Parser for the external references object in KAF/NAF 
  3  """ 
  4   
  5  # included modification for KAF/NAF 
  6  from term_sentiment_data import Cterm_sentiment 
  7  from lxml import etree 
  8   
9 -class CexternalReference:
10 """ 11 This class encapsulates the external reference object in KAF/NAF 12 """
13 - def __init__(self,node=None):
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 #self.resource = self.reference = self.reftype = self.status = self.source = self.confidence = '' 21 if node is None: 22 self.node = etree.Element('externalRef') 23 else: 24 self.node = node
25
26 - def get_node(self):
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
34 - def get_external_references(self):
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
43 - def add_external_reference(self,ext_ref):
44 self.node.append(ext_ref.get_node())
45
46 - def set_resource(self,resource):
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
54 - def set_confidence(self,confidence):
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
62 - def set_reference(self,reference):
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
70 - def get_resource(self):
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
78 - def get_confidence(self):
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
86 - def get_reference(self):
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
94 - def set_reftype(self,r):
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
102 - def get_reftype(self):
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
110 - def set_source(self,r):
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
118 - def get_source(self):
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
127 -class CexternalReferences:
128 """ 129 This class encapsulates the external references object, which is a set of external reference objects 130 """
131 - def __init__(self,node=None):
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
142 - def add_external_reference(self,ext_ref):
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
150 - def get_node(self):
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
158 - def __iter__(self):
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