pd.options.display.width = 200  # don't break columns
# 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 = [
    "Watching the sopranos again from start to finish!",
    "Finding out i have to go to the  dentist tomorrow",
    "Sun in my eyes but I don't mind, what a beautiful day we've had in New York today!",
    "Feels like someone's stabbed me in my hope",
    "Do people have no Respect for themselves or you know others peoples homes",
    "I want to go outside and chalk but I have no chalk",
    "I hate coming to the doctors when I feel as if I might have a big problem",
    "My mom wasn't mad",
    "You don't indicate once I'm already in the road THEN rev and honk at me you stupid bitch #learnhowtodrive #bitch",
    "Come home from work and this is on my doorstep. I guess he has a secret admirer",
    "The 'egyption hot models' facebook page is pathetic... simply photos of obese horny women.",
    "I HATE PAPERS AH #AH #HATE",
]

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

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

#embeddings = model.embed(tweets)
#print(embeddings, '\n')
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]
            emotions["disgust"] = disgust[0]
#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')
cursor2 = cnx.cursor()
cursor3 = cnx.cursor()
select_text = ("SELECT id,title FROM goal ")
cursor.execute(select_text)
result = cursor.fetchall()
dictlist = []
ids = []
i = 1
for items in result:
    dictlist.append(cleaner(items[1]))
    ids.append(items[0])
    print(i)
    i += 1

emotion_list = []
probabilities = model.predict_probabilities(dictlist)
print("classifier start working:  ")
# Anger Disgust Fear Joy Sadness Surprise
# predict lists for identifyed emotions
model_emotion_Anger = probabilities['Anger']
Anger_list = probabilities.iloc[:, 1].tolist()
model_emotion_Disgust = probabilities['Disgust']
Disgust_list = probabilities.iloc[:, 2].tolist()
model_emotion_Fear = probabilities['Fear']
Fear_list = probabilities.iloc[:, 3].tolist()
model_emotion_Joy = probabilities['Joy']
Joy_list = probabilities.iloc[:, 4].tolist()
model_emotion_Sadness = probabilities['Sadness']
Sadness_list = probabilities.iloc[:, 5].tolist()
model_emotion_Surprise = probabilities['Surprise']
Surprise_list = probabilities.iloc[:, 6].tolist()
Exemple #5
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')