def get_avg_polarity(message): threshold = 0.3 sn = Senticnet() count = 0 summ = 0 for word_options in get_words_bag(message): polarity = 0 for word in word_options: try: concept = sn.concept(word) polarity = concept['polarity'] break except urllib2.HTTPError: pass #Do next if abs(polarity) > threshold: summ += polarity count += 1 return summ / count if count > 0 else 0
def getInfo(self, concept): try: sn = Senticnet() concept_info = sn.concept(concept) polarity_value = sn.polarity_value(concept) polarity_intense = sn.polarity_intense(concept) moodtags = sn.moodtags(concept) semantics = sn.semantics(concept) sentics = sn.sentics(concept) """print(concept) print("concept_info: {}".format(concept_info)) print("polarity_value: {}".format(polarity_value)) print("polarity_intense: {}".format(polarity_intense)) print("moodtags: {}".format(moodtags)) print("semantics: {}".format(semantics)) print("sentics: {}".format(sentics)) print("\n\n")""" return "{} - {}".format(polarity_value, polarity_intense) except: return "NOT POSSIBLE"
__author__ = 'cloudera' from senticnet.senticnet import Senticnet from textblob import TextBlob sentence = "One of the very first Apple 1 computers, worth about 500,000, goes on sale later this month at Christie's auction house, the latest vintage tech sale." sn = Senticnet() concept_info = sn.concept('love') print 'sn.concept(love) = ', concept_info polarity = sn.polarity('love') print 'polarity(love) = ', polarity semantics = sn.semantics('love') print 'semantics = ', semantics sentics = sn.sentics('love') print 'sentics = ', sentics sentenceBlob = TextBlob(sentence) print sentenceBlob.parse() print sentenceBlob.sentiment sentenceConcept = sn.concept(sentence) print sentenceConcept
for concept in concepts: concept = concept.replace('[', '') concept = concept.replace('u\'', '') concept = concept.replace('_', ' ') concept = concept.replace('...', '') concept = concept.replace(']', '') concept = concept.replace('\'', '') concept = concept.split(',') print('internal loop') for item in concept: print('item:') print(item) item = str(item) #item='love' try: concept_info = sn.concept(item) polarity_value = sn.polarity_value(item) polarity_intense = sn.polarity_intense(item) print(polarity_value) moodtags = sn.moodtags(item) semantics = sn.semantics(item) sentics = sn.sentics(item) polarity_intense_result.append(polarity_intense) polarity_value_result.append(polarity_value) concept_info_result.append(concept_info) except: print('Concept not in senticnet') print(polarity_value_result)