Module term_sentiment_data
|
|
1 """
2 This module is a parser for the sentiment elements in NAF/KAF terms
3 """
4
5
6 from lxml import etree
7 from lxml.objectify import dump
8
10 """
11 This class encapsulates the sentiment element
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 if node is None:
21 self.node = etree.Element('sentiment')
22 else:
23 self.node = node
24
25
26
27
28
29
30
31
32
33
34
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
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
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
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
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
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
84 return dump(self.node)
85