-
Notifications
You must be signed in to change notification settings - Fork 7
/
convert_sentistrength.py
132 lines (98 loc) · 3.2 KB
/
convert_sentistrength.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# This file is for convert data format to SentiStrength-SE format
# Created by happygirlzt
import pandas as pd
import numpy as np
import re
from pathlib import Path
data_folder=Path('YOUR_DATA_FOLDER')
api_train=data_folder/'api-train.pkl'
api_test=data_folder/'api-test.pkl'
gh_train=data_folder/'gh-train.pkl'
gh_test=data_folder/'gh-test.pkl'
jira_train=data_folder/'jira-train.pkl'
jira_test=data_folder/'jira-test.pkl'
so_train=data_folder/'so-train.pkl'
so_test=data_folder/'so-test.pkl'
app_train=data_folder/'app-train.pkl'
app_test=data_folder/'app-test.pkl'
cr_train=data_folder/'cr-train.pkl'
cr_test=data_folder/'cr-test.pkl'
def convert_jira_test():
df=pd.read_pickle(jira_test)
sents=[]
for index, row in df.iterrows():
text=row['sentence']
text=''.join(text.split('\n'))
sents.append(text)
#print(len(sents))
new_df=pd.DataFrame(sents,columns=['sentence'])
df.update(new_df)
df.to_csv('../data/jira-test-se.csv',header=None,index=False)
def convert_so_test():
df=pd.read_pickle(so_test)
sents=[]
for index, row in df.iterrows():
text=row['sentence']
text=''.join(text.split('\n'))
sents.append(text)
#print(len(sents))
new_df=pd.DataFrame(sents,columns=['sentence'])
df.update(new_df)
df.to_csv('../data/so-test-se.csv',header=None,index=False)
def convert_api_test():
df=pd.read_pickle(api_test)
sents=[]
for index, row in df.iterrows():
text=row['sentence']
text=''.join(str(text).split('\n'))
sents.append(text)
#print(len(sents))
new_df=pd.DataFrame(sents,columns=['sentence'])
df.update(new_df)
df.to_csv('../data/api-test-se.csv',header=None,index=False)
def convert_app_test():
df=pd.read_pickle(app_test)
sents=[]
for index, row in df.iterrows():
text=row['sentence']
text=''.join(str(text).split('\n'))
sents.append(text)
#print(len(sents))
new_df=pd.DataFrame(sents,columns=['sentence'])
df.update(new_df)
df.to_csv('../data/app-test-se.csv',header=None,index=False)
#convert_api_test()
def convert_cr_test():
df=pd.read_pickle(cr_test)
sents=[]
labels=[]
for index, row in df.iterrows():
text=row['sentence']
text=''.join(text.split('\n'))
sents.append(text)
labels.append(row['label'])
#print(len(sents))
new_df=pd.DataFrame({'sentence': sents,'label': labels})
sents=[]
labels=[]
for index, row in new_df.iterrows():
text=row['sentence']
text=''.join(text.split('\n'))
sents.append(text)
labels.append(row['label'])
pd.DataFrame({'sentence': sents,'label': labels}).to_csv('../data/cr-test-se.csv',header=None,index=False)
#convert_so_test()
convert_cr_test()
#convert_app_test()
def convert_gh_test():
df=pd.read_pickle(gh_test)
sents=[]
for index, row in df.iterrows():
text=row['sentence']
text=''.join(text.split('\n'))
sents.append(text)
#print(len(sents))
new_df=pd.DataFrame(sents,columns=['sentence'])
df.update(new_df)
df.to_csv('../data/gh-test-se.csv',header=None,index=False)
#convert_gh_test()