Package miopia :: Package analyzer :: Package counter :: Module SentimentCounter
[hide private]
[frames] | no frames]

Source Code for Module miopia.analyzer.counter.SentimentCounter

 1  ''' 
 2  Created on 25/02/2014 
 3   
 4  @author: David Vilares 
 5  ''' 
 6   
 7  from miopia.analyzer.counter.SintacticCounter import SintacticCounter 
 8  from miopia.adapter.Feature import SentimentFeature 
 9  from miopia.util.exceptions.FeatureTypeConfigurationException import FeatureTypeConfigurationException 
10   
11   
12 -class SentimentCounter(SintacticCounter):
13 ''' 14 This counter does not support additional semantic properties 15 ''' 16
17 - def __init__(self,ftc, list_desired_features,sentiment_analyzer):
18 ''' 19 @param ftc: An instance of L{FeatureTypeConfiguration} 20 @param list_desired_features: A set of L{SentimentFeature} values. It indicates the features 21 that this counter will take from a L{SentimentDependencyGraph} once it has been analsed 22 by the L{SentimentAnalyzer} 23 @param sentiment_analyzer: A instance of L{SentimentAnalyzer} 24 ''' 25 super(SentimentCounter,self).__init__(ftc) 26 self._list_desired_features = list_desired_features 27 self._sentiment_analyzer = sentiment_analyzer
28
29 - def _count_graph(self,textid,dg,address):
30 31 """ 32 @param textid: A string. The text file identifier. 33 @param dg: An instance of L{SentimentDependencyGraph}. 34 @param address: An integer. The position of a node in the graph. 35 """ 36 37 if self._ftc.get_semantic_property() != None: 38 raise FeatureTypeConfigurationException("SentimentCounter does not support semantic properties") 39 40 sentiment_info = self._sentiment_analyzer.evaluate(dg,dg.get_by_address(address)) 41 dict_sentiment = {} 42 43 node = dg.get_by_address(address) 44 dict_sentiment[self._id_of_feature(textid, address, SentimentFeature.SUBJECTIVITY)] = sentiment_info.get_subjectivity() 45 dict_sentiment[self._id_of_feature(textid, address, SentimentFeature.SEMANTIC_ORIENTATION)] = sentiment_info.get_so() 46 dict_sentiment[self._id_of_feature(textid, address, SentimentFeature.POS_WORDS)] = sentiment_info.get_pos_words() 47 dict_sentiment[self._id_of_feature(textid, address, SentimentFeature.NEG_WORDS)] = sentiment_info.get_neg_words() 48 dict_sentiment[self._id_of_feature(textid, address, SentimentFeature.NUMBER_INTENSIFIERS)] = sentiment_info.get_number_intensifiers() 49 dict_sentiment[self._id_of_feature(textid, address, SentimentFeature.LENGTH_TEXT)] = sentiment_info.get_length_text() 50 dict_sentiment[self._id_of_feature(textid, address, SentimentFeature.NUMBER_WORDS)] = sentiment_info.get_number_words() 51 52 return {feature_id: dict_sentiment[feature_id] for feature_id in dict_sentiment.keys() 53 if self.name_from_id(feature_id) in self._list_desired_features}
54