Exemplo n.º 1
0
 def findFrequencies(self, tweets):
     model = EmotionPredictor(classification='ekman',
                              setting='mc',
                              use_unison_model=True)
     self.__predictions = model.predict_classes(tweets)
     i = 0
     for index, row in self.__predictions.iterrows():
         self.__emotionFrequency[row['Emotion']] += 1
# print (noOfTweets)
model = EmotionPredictor(classification='plutchik', setting='mc')

# tweets = [
#     "Watching the sopranos again from start to finish!",
#     "Finding out i have to go to the  dentist tomorrow",
#     "I want to go outside and chalk but I have no chalk",
#     "Stock market hit all time low on friday",
#     "Stock market hit all time high on friday",  
#     "I believe you",
#     "My mom wasn't mad",
#     "Do people have no Respect for themselves or you know others peoples homes",
#     "www.google.com I am happy",
# ]

result = model.predict_classes(tweets)
probabilities=model.predict_probabilities(tweets)
print (result)
print (probabilities)
print (probabilities.to_dict[0])

anger = probabilities["Anger"].values.tolist()
joy   = probabilities["Joy"].values.tolist()
fear  = probabilities["Fear"].values.tolist()
surprise = probabilities["Surprise"].values.tolist()
disgust = probabilities["Disgust"].values.tolist()
trust = probabilities["Trust"].values.tolist()
anticipation = probabilities["Anticipation"].values.tolist()
sadness = probabilities["Sadness"].values.tolist()

text = result["Tweet"].values.tolist()
Exemplo n.º 3
0
# pd.options.display.max_columns = 7      # maximal number of columns

# Predictor for Ekman's emotions in multiclass setting.
model = EmotionPredictor(classification='ekman',
                         setting='mc',
                         use_unison_model=True)

tweets = []
with open(
        '/home/didier/ASONAMW/PA/Sentiment/Billboard_Music_Awards_2016_Sentiment.txt',
        'r') as csvfile:
    plots = csv.reader(csvfile, delimiter=';')
    for row in plots:
        tweets.append(row[1])

predictions = model.predict_classes(tweets)
predictions.to_csv(
    "/home/didier/ASONAMW/PA/Sentiment/Billboard_Music_Awards_2016_Emotions.txt",
    sep=';',
    encoding='utf-8')

tweets = []
with open(
        '/home/didier/ASONAMW/PA/Sentiment/Billboard_Music_Awards_2017_Sentiment.txt',
        'r') as csvfile:
    plots = csv.reader(csvfile, delimiter=';')
    for row in plots:
        tweets.append(row[1])

predictions = model.predict_classes(tweets)
predictions.to_csv(
with open(file, "r+") as rf, tempfile:
    reader = csv.reader(rf, delimiter=',')
    writer = csv.writer(tempfile, delimiter=',')
    for tweetRow in reader:
        # emotions
        # print (tweetRow)
        if (tweetRow[0] == "id"):
            continue
        words = []
        emotions = {}
        if (tweetRow[17] == "-"):
            word = tweetRow[13]
            words.append(word)
            # print (words)
            result = model.predict_classes(words)
            probabilities = model.predict_probabilities(words)

            anger = probabilities["Anger"].values.tolist()
            joy = probabilities["Joy"].values.tolist()
            fear = probabilities["Fear"].values.tolist()
            surprise = probabilities["Surprise"].values.tolist()
            disgust = probabilities["Disgust"].values.tolist()
            trust = probabilities["Trust"].values.tolist()
            anticipation = probabilities["Anticipation"].values.tolist()
            sadness = probabilities["Sadness"].values.tolist()

            emotions["Anger"] = anger[0]
            emotions["joy"] = joy[0]
            emotions["fear"] = fear[0]
            emotions["surprise"] = surprise[0]
Exemplo n.º 5
0
from emotion_predictor import EmotionPredictor

model = EmotionPredictor(classification='plutchik',
                         setting='mc',
                         use_unison_model=True)

print("************")
predictions = model.predict_classes(["I like to play cricket"])
print(predictions.iloc[0]['Tweet'], '\t', predictions.iloc[0]['Emotion'])
#path_to_json = 'C:/Users/Αναστασία/Desktop/json/'
#for file_name in [file for file in os.listdir(path_to_json) if file.endswith('.json')]:
#  with open(path_to_json + file_name) as json_file:
#    data=json.load(json_file)
# read list inside dict
#_list = data['Reviews']
# read listvalue and load dict
#for v in _list:
#   reviews.append(v['Content'])
#predictions = model.predict_classes(reviews)
#probabilities = model.predict_probabilities(reviews)
#embeddings = model.embed(reviews)

#forOneJsonFile
with open('C:/Users/Αναστασία/Desktop/json/72572.json', 'r') as f:
    data = json.load(f)

# read list inside dict
_list = data['Reviews']
# read listvalue and load dict
for v in _list:
    reviews.append(v['Content'])

predictions = model.predict_classes(reviews)
print(predictions, '\n')

probabilities = model.predict_probabilities(reviews)
print(probabilities, '\n')

embeddings = model.embed(reviews)
print(embeddings, '\n')
Exemplo n.º 7
0
#pathOfJsonFiles
path_to_json = 'json/'
for file_name in [file for file in os.listdir(path_to_json) if file.endswith('.json')]:
  with open(path_to_json + file_name) as json_file:
    data= []
    data=json.load(json_file)
    # read list inside dict
    _list = data['Reviews']
    # read listvalue and load dict
    for v in _list:
        if ('Title' in v):
            fullContent = v['Title']
        else:
            fullContent = ''

        fullContent = fullContent + ' ' + v['Content']
        reviews.append(fullContent)

        ratings.append(v['Ratings'])
        authors.append(v['Author'])
        hotels.append(data['HotelInfo']['HotelID'])

predictions = model.predict_classes(reviews, ratings, authors, hotels)
print(predictions, '\n')

probabilities = model.predict_probabilities(reviews, ratings, authors, hotels)
print(probabilities, '\n')

embeddings = model.embed(reviews, ratings, authors, hotels)
print(embeddings, '\n')
    tweet = emoji.demojize(tweet)
    tweet = tweet.replace(":"," ")
    tweet = ' '.join(tweet.split())

    return tweet

def removeContent(df:str, colname:str, *args):
    sens ='df[{}]'.format("|".join(["df.{}.str.contains('"'{}'"')".format(colname,x) for x in list(args)]))
    df_other_list1 = list(eval(sens)[colname])
    df_other_list2 = list(df[colname])
    ret = list(set(df_other_list2) ^ set(df_other_list1))
    result = df[df[colname].isin(ret)]
    return result    


tweets_table = pd.read_csv("clean#excitement.csv",usecols=["id","created_at","new_text"])

model = EmotionPredictor(classification='ekman', setting='mc', use_unison_model=True)
predictions = model.predict_classes([process_emoji(tw) for tw in tweets_table.new_text.tolist()])
#print(predictions, '\n')

tweets_table["emotion"]=predictions["Emotion"].tolist()

result=removeContent(tweets_table.astype(str),"emotion", 'Disgust', 'Fear','Sadness')

#print(result)
print(result.shape[0])
result=result.drop(['emotion'],axis=1)

result.to_csv("cs_excitement.csv", mode='a',encoding="utf-8",index=None)