Package miopia :: Package classifier :: Module QuaternaryStrategy
[hide private]
[frames] | no frames]

Source Code for Module miopia.classifier.QuaternaryStrategy

 1  ''' 
 2  @author: David Vilares Calvo 
 3  ''' 
 4   
 5  from miopia.classifier.ClassificationStrategy import ClassificationStrategy 
 6  from miopia.classifier.PolarityType import PolarityType 
 7   
8 -class QuaternaryStrategy(ClassificationStrategy):
9 ''' 10 This strategy allows to classify texts such as Positive, Negative 11 Neutral (the text merges positive and negative ideas) or None (without any sentiment) 12 ''' 13 14
15 - def __init__(self,threshold):
16 ''' 17 Constructor 18 @param threshold: A float. It establish a numerical threshold to distinguish between classes 19 ''' 20 super(QuaternaryStrategy,self).__init__(threshold)
21 22
23 - def _type(self, sentiment_info):
24 """ 25 @param sentiment_info: A L{SentimentInfo} object 26 @return: A L{PolarityType} value in {NEGATIVE, POSITIVE, NEUTRAL, NONE} 27 """ 28 so = sentiment_info.get_so() 29 subj = sentiment_info.get_subjectivity() 30 31 if subj is False: return PolarityType.NONE 32 else: 33 if so > self._threshold: return PolarityType.POSITIVE 34 if so < self._threshold: return PolarityType.NEGATIVE 35 return PolarityType.NEUTRAL
36