def emoticons_from_dictionary(text,dict_emoticons):
    feature_set = dict()
    feature_set['score_emoticons']=0
    feature_set['number_emoticons']=0
    tweet_tokens_emoticons=clean_text.normalize_emoticons(text)
    text = tweet_tokens_emoticons.split()
    for emoticon in text:
        if emoticon in dict_emoticons:
            feature_set['score_emoticons']+=dict_emoticons[emoticon]
            feature_set['score_'+emoticon]=dict_emoticons[emoticon]
            feature_set['number_emoticons']+=1
            if tweet_tokens_emoticons.endswith(emoticon):
                if dict_emoticons[emoticon] > 0:
                    feature_set['ends_with_positive_emoticon']=True
                elif dict_emoticons[emoticon] <0:
                    feature_set['end_with_negative_emoticon']=True
                else:
                    feature_set['end_with_neutral_emoticon']=True
    return feature_set
 def emoticons_from_dictionary(text,dict_emoticons):
     """This function returns the number of emoticons, the score that each one has, the total score and if the sentence is
         finished with a negative, positive or neutral emoticon
     """
     feature_set = dict()
     feature_set['score_emoticons']=0
     feature_set['number_emoticons']=0
     tweet_tokens_emoticons=clean_text.normalize_emoticons(text)
     text = tweet_tokens_emoticons.split()
     for emoticon in text:
         if emoticon in dict_emoticons:
             feature_set['score_emoticons']+=dict_emoticons[emoticon]
             feature_set['score_'+emoticon]=dict_emoticons[emoticon]
             feature_set['number_emoticons']+=1
             if tweet_tokens_emoticons.endswith(emoticon):
                 if dict_emoticons[emoticon] > 0:
                     feature_set['ends_with_positive_emoticon']=True
                 elif dict_emoticons[emoticon] <0:
                     feature_set['end_with_negative_emoticon']=True
                 else:
                     feature_set['end_with_neutral_emoticon']=True
     return feature_set
Beispiel #3
0
 def normalize_emoticons_test(self):
     texts=[":))",":((","::)",":)))))"]
     texts_clean=[":)",":(",":)",":)"]
     for i in range(len(texts)):
         self.assertEqual(ct.normalize_emoticons(texts[i]),texts_clean[i])