-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathprepare_emolex.py
85 lines (80 loc) · 2.37 KB
/
prepare_emolex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
## Prepare EmoLex
from os import system
from os.path import isfile
import pandas as pd
if not isfile("NRC - Sentiment Lexicon - Research EULA Sept 2017 .pdf"):
system("wget http://sentiment.nrc.ca/lexicons-for-research/NRC-Emotion-Lexicon.zip")
system("unzip NRC-Emotion-Lexicon.zip")
system("rm NRC-Emotion-Lexicon.zip")
original_df = pd.read_excel(
"NRC-Emotion-Lexicon-v0.92/NRC-Emotion-Lexicon-v0.92-In105Languages-Nov2017Translations.xlsx"
) # Open the downloaded Excel file
# For English:
if not isfile("english_emolex.csv"):
df = original_df[
[
"English (en)",
"Anger",
"Anticipation",
"Disgust",
"Fear",
"Joy",
"Sadness",
"Surprise",
"Trust",
]
] # Keep only the English tokens and the annotated emotions
df = df[
df[
[
"Anger",
"Anticipation",
"Disgust",
"Fear",
"Joy",
"Sadness",
"Surprise",
"Trust",
]
].sum(axis=1)
> 0
] # Drop words that does not relate to any emotion
df.to_csv("english_emolex.csv", index=False) # Save to file
# For Mandarin Chinese:
if not isfile("chinese_emolex.csv"):
df = original_df[
[
"Chinese (Simplified) (zh-CN)",
"Anger",
"Anticipation",
"Disgust",
"Fear",
"Joy",
"Sadness",
"Surprise",
"Trust",
]
] # Keep only the Chinese tokens and the annotated emotions
df.drop_duplicates(
subset=["Chinese (Simplified) (zh-CN)"], inplace=True
) # translation inbalances
df = df[
df[
[
"Anger",
"Anticipation",
"Disgust",
"Fear",
"Joy",
"Sadness",
"Surprise",
"Trust",
]
].sum(axis=1)
> 0
] # Drop words that does not relate to any emotion
df.to_csv("chinese_emolex.csv", index=False) # Save to file
if isfile("NRC - Sentiment Lexicon - Research EULA Sept 2017 .pdf"):
system(
'rm -r NRC-Emotion-Lexicon-v0.92/ "NRC - Sentiment Lexicon - Research EULA Sept 2017 .pdf"'
) # Remove unzipped files