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

Source Code for Module term_sentiment_data

 1  """ 
 2  This module is a parser for the sentiment elements in NAF/KAF terms 
 3  """ 
 4   
 5  # Modified for NAF KAF 
 6  from lxml import etree 
 7  from lxml.objectify import dump 
 8   
9 -class Cterm_sentiment:
10 """ 11 This class encapsulates the sentiment element 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 if node is None: 21 self.node = etree.Element('sentiment') 22 else: 23 self.node = node
24 #self.resource = self.polarity = self.strength = self.subjectivity = self.semantic_type = self.modifier = self.marker = self.product_feature = '' 25 #if node is not None: 26 # self.resource = node.get('resource','') 27 # self.polarity = node.get('polarity','') 28 # self.strength = node.get('strength','') 29 # self.subjectivity = node.get('subjectivity','') 30 #self.semantic_type = node.get('sentiment_semantic_type','') 31 # self.modifier = node.get('sentiment modifier','') 32 # self.marker = node.get('sentiment_marker','') 33 # self.product_feature = node.get('sentiment product feature','') 34
35 - def set_resource(self,r):
36 """ 37 Sets the resource for the sentiment element 38 @type r: string 39 @param r: the resource for the element 40 """ 41 self.node.set('resource',r)
42
43 - def get_node(self):
44 """ 45 Returns the node of the element 46 @rtype: xml Element 47 @return: the node of the element 48 """ 49 return self.node
50
51 - def get_polarity(self):
52 """ 53 Returns the polarity of the element 54 @rtype: string 55 @return: the polarity of the element 56 """ 57 return self.node.get('polarity')
58
59 - def set_polarity(self,p):
60 """ 61 Sets the resource for the polarity element 62 @type p: string 63 @param p: the polarity for the element 64 """ 65 self.node.set('polarity',p)
66
67 - def get_modifier(self):
68 """ 69 Returns the modifier of the element 70 @rtype: string 71 @return: the modifier of the element 72 """ 73 return self.node.get('sentiment_modifier')
74
75 - def set_modifier(self,sm):
76 """ 77 Sets the sentiment modifier for the sentiment element 78 @type sm: string 79 @param sm: the modifier for the element 80 """ 81 self.node.set('sentiment_modifier',sm)
82
83 - def __str__(self):
84 return dump(self.node)
85