Exemple #1
0
#add your keys below
public_key = "PUBaxIIThb7R7A%ZePGtuLDl-olsIsXZ"
private_key = "PRIBfWPexYV6YyqR3AmwIK%QpNIil7-0"

#build the Free API object with your keys
chatterboxapi = SentimentAnalysisFree(public_key, private_key)

f = open('../test set.txt', 'r')
total = 0
count = 0
for line in f:
    total += 1
    
    tweet = line.split(' .:. ')
    sentiment = tweet[0]
    result = chatterboxapi.classifytext("en", tweet)
    
    sentiment_label = result['sent']
    if sentiment_label == 1:
        sentiment_label = 'pos'
    elif sentiment_label == -1:
        sentiment_label = 'neg'
    else:
        sentiment_label = 'neutral'        

        
#    score = result['value']
#    if abs(score) < 0.20:
#        sentiment_label = 'neutral'
#    elif score > 0:
#        sentiment_label = 'pos'
	"Well, Saudi Airlines have really messed up our holiday. Pretty pissed off they can get away with it.",
	"How did someone make it to our site using the keywords: \"different types of birth control\"? #odd",
	"Apple Mail, why do you crash so? #grrrr",
	"If you ever wonder 'how bad can a coffee from burger king be, really?' the answer is bad, very bad. #badcoffeebadmorning",
	"Great meeting with TK from the Queen Mary student paper - really interesting questions!"]

highestnumber = 0
highesttext = False

try:
	for sampletext in sampletexts:
		print "Text: " + sampletext
		
		#Here we do the actual classification.  We pass in a language
		#identifier and the text we wish to be classified.
		classification = chatterboxapi.classifytext("en",sampletext)
		
		#Uncomment this line if you want to inspect the result.
		#print classification.body
		
		#Value is the predicted strength of the sentiment in the text
		sentiment_value = classification.body['value']
		
		if sentiment_value > highestnumber:
			highestnumber = sentiment_value
			highesttext = sampletext
			
		#Sent is the sentiment class. 1 is positive, -1 is negative
		sentiment_label = classification.body['sent']
		
		if abs(sentiment_value) < 0.25:
Exemple #3
0
    "How did someone make it to our site using the keywords: \"different types of birth control\"? #odd",
    "Apple Mail, why do you crash so? #grrrr",
    "If you ever wonder 'how bad can a coffee from burger king be, really?' the answer is bad, very bad. #badcoffeebadmorning",
    "Great meeting with TK from the Queen Mary student paper - really interesting questions!"
]

highestnumber = 0
highesttext = False

try:
    for sampletext in sampletexts:
        print "Text: " + sampletext

        #Here we do the actual classification.  We pass in a language
        #identifier and the text we wish to be classified.
        classification = chatterboxapi.classifytext("en", sampletext)

        #Uncomment this line if you want to inspect the result.
        #print classification.body

        #Value is the predicted strength of the sentiment in the text
        sentiment_value = classification.body['value']

        if sentiment_value > highestnumber:
            highestnumber = sentiment_value
            highesttext = sampletext

        #Sent is the sentiment class. 1 is positive, -1 is negative
        sentiment_label = classification.body['sent']

        if abs(sentiment_value) < 0.25: