Ejemplo n.º 1
0
def emotion_data(comment):
    comment = comment.translate({ord(c): '' for c in string.punctuation})
    sn = Senticnet()
    polarity_intense = 0
    comment_sentics = {
        'sensitivity': 0,
        'attention': 0,
        'pleasantness': 0,
        'aptitude': 0
    }
    comment_mood_tags = []
    words = comment.split(" ")
    total_word_count = len(words)
    final_output = {
        'sentics': {
            'sensitivity': '0',
            'attention': '0',
            'pleasantness': '0',
            'aptitude': '0',
            'polarity': '0'
        },
        'mood tags': {}
    }
    for i in words:

        try:
            #word_emotion(i, sn)
            polarity_intense += float(sn.polarity_intense(i))
            #print sn.sentics(i)
            sentics_values(i, sn, comment_sentics)
            add_mood_tags(comment_mood_tags, sn, i)
        except KeyError:
            #print "This word does not exist", i
            if (total_word_count > 1):
                total_word_count -= 1
            pass
    comment_sentics_average(total_word_count, comment_sentics)
    final_output['sentics']['polarity'] = polarity_intense / total_word_count
    final_output['mood tags'] = comment_mood_tags
    for output in final_output['sentics']:
        if output in comment_sentics:
            final_output['sentics'][output] = comment_sentics[output]

    json_output = json.dumps(final_output)
    print(json_output)
    return json_output
Ejemplo n.º 2
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"
Ejemplo n.º 3
0
from senticnet.senticnet import Senticnet

sn = Senticnet()
print "polarity value:", sn.polarity_value("love")
print "polarity intense:", sn.polarity_intense("love")
print "moodtags:", ", ".join(sn.moodtags("love"))
print "semantics:", ", ".join(sn.semantics("love"))
print "\n".join(
    [key + ": " + str(value) for key, value in sn.sentics("love").items()])
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
def score_calculation(sentence):
    sno = SnowballStemmer('english')
    lemma = WordNetLemmatizer()
    sn = Senticnet()
    polarity_intense = 0
    comment_sentics = {
        'sensitivity': 0,
        'attention': 0,
        'pleasantness': 0,
        'aptitude': 0
    }
    comment_mood_tags = []
    total_word_count = len(sentence)
    final_output = {
        'sentics': {
            'sensitivity': '0',
            'attention': '0',
            'pleasantness': '0',
            'aptitude': '0',
            'polarity': '0'
        },
        'mood tags': {}
    }
    for i in sentence:
        try:
            #word_emotion(i,sn)
            polarity_intense += float(sn.polarity_intense(i))
            sentics_values(i, sn, comment_sentics)
            add_mood_tags(comment_mood_tags, sn, i)
        except KeyError:
            #print "This word does not exist"
            try:
                current_word = lemma.lemmatize(i)
                #word_emotion(current_word,sn)
                polarity_intense += float(sn.polarity_intense(current_word))
                sentics_values(current_word, sn, comment_sentics)
                add_mood_tags(comment_mood_tags, sn, current_word)
            except KeyError:

                #print("This didnt work again")
                try:
                    # word_emotion(sno.stem(current_word),sn)
                    current_word = sno.stem(current_word)
                    polarity_intense += float(
                        sn.polarity_intense(current_word))
                    sentics_values(current_word, sn, comment_sentics)
                    add_mood_tags(comment_mood_tags, sn, current_word)
                except KeyError:
                    if (total_word_count > 1):
                        total_word_count -= 1
                    pass
    comment_sentics_average(total_word_count, comment_sentics)
    final_output['sentics']['polarity'] = polarity_intense / total_word_count
    final_output['mood tags'] = comment_mood_tags
    for output in final_output['sentics']:
        if output in comment_sentics:
            final_output['sentics'][output] = comment_sentics[output]
    json_output = json.dumps(final_output)
    final_excitement = {'score': '0', 'mood tags': {}}
    final_excitement_score = comment_sentics['attention'] + comment_sentics[
        'pleasantness']
    final_excitement['score'] = str(final_excitement_score)
    final_excitement['mood tags'] = comment_mood_tags

    #print json_output
    #print final_excitement

    return final_excitement