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

Source Code for Module miopia.classifier.TernaryStrategy

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