-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstopword_bs.py
45 lines (27 loc) · 1.01 KB
/
stopword_bs.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
import nltk
from nltk.corpus import stopwords
import json
from sklearn.feature_extraction.text import CountVectorizer
from tokenizec import NlpTokenizer
def createfolder(text):
from nltk.corpus import stopwords
path='{}.json'.format(text)
f = open(path,)
data = json.load(f)
stopwords=stopwords.words('english')
Data_withoutstopwords={}
for fn in data.keys():
tags_values={}
for tag in data[fn].keys():
list=[]
for values in data[fn][tag]:
if values not in stopwords:
list.append(values)
tags_values[tag]=list
Data_withoutstopwords[fn]=tags_values
out_path='without_stopword_{}.json'.format(text)
with open(out_path,'w')as json_file:
json.dump(Data_withoutstopwords, json_file,indent=4)
filenames=['ps_stemmed','custom_stemmed','lc_stemmed','sb_stemmed','tokenized']
for fn in filenames:
createfolder(fn)