def get_Emoji_sentiment(self, lemma):
		lexeme_sentiment = {}
		unicode_emoji = Emoji.ascii_to_unicode(lemma.upper())
		if len(unicode_emoji) == 1:
			category = unicodedata.category(unicode_emoji)
			if category == 'So': # is "Symbol other" (a specific unicode category)
				shortcode = Emoji.unicode_to_shortcode(unicode_emoji)
				if shortcode != unicode_emoji: # is an emoji only if it has an emoji shortcode
					# check whether the emoji is in the emoji polarity lexicon
					if unicode_emoji in self.emoji: # is in the lexicon
						emodict = self.emoji[unicode_emoji]
						lexeme_sentiment["0"] = { "shortcode":shortcode, "negativity":emodict["negativity"], "positivity":emodict["positivity"] }
					else: # tokenize the shortcode and get its tokens polarities from SentiWordNet
						tokens = shortcode.strip(' :').split('_') # shortcode tokenization seems an easy problem to solve
						negativity = 0
						positivity = 0
						count = 0 # count the number of shortcode tokens with a synset
						for token in tokens:
							synsets = list(swn.senti_synsets(token))
							if len(synsets)>0:
								senti_synset = synsets[0]
								negativity += senti_synset.neg_score()
								positivity += senti_synset.pos_score()
								count += 1
						if count > 1: # take the average of all shortcode tokens polarities
							negativity /= count
							positivity /= count
						lexeme_sentiment["0"] = { "shortcode":shortcode, "negativity":negativity, "positivity":positivity }
					# print(lexeme_sentiment["0"])
		return lexeme_sentiment
예제 #2
0
    def action_from_answer(self, user, msg, story_model=Story):

        answers = self.get_prev_answers(user, story_model=story_model)
        if answers:
            text = Emoji.unicode_to_shortcode(self.read_user_message(msg))
            for f in answers:
                if f.text == text:
                    return f.action
        return None
예제 #3
0
    def action_from_answer(self, user, msg):
        s = Story.objects.filter(bulletin=user.current_bulletin,
                                 order=user.current_story_order).first()
        if s is None:
            return

        f = Fragment.objects.filter(story=s,
                                    text=Emoji.unicode_to_shortcode(
                                        msg['text'])).first()

        if f is None:
            return

        return f.action