-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext_preprocessing.py
60 lines (53 loc) · 1.71 KB
/
text_preprocessing.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
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
from Sastrawi.Stemmer.StemmerFactory import StemmerFactory
f=open("data kumpulan kalimat .txt", "r")
text=f.read()
#remove punctuation
punctuations = '''!()-[]{};:'",<>./?@#$%^&*_~'''
text_no_punct = ""
for char in text:
if char not in punctuations:
text_no_punct = text_no_punct + char
#tokenization
tokenize_word = word_tokenize(text_no_punct)
#lower case converting
words=[]
for word in tokenize_word :
words.append(word.lower())
#stop words
stops = set(stopwords.words('indonesian'))
word_tokens_no_stopwords = [w for w in words if not w in stops]
#stemming
factory = StemmerFactory()
stemmer = factory.create_stemmer()
word_stemming = []
for word in word_tokens_no_stopwords:
word_stemming.append(stemmer.stem(word))
i=True
while i==True :
print("======Menu=====")
print("1. Word Tokenization")
print("2. Lower Case Converting")
print("3. Stop Word Removal")
print("4. Stemming")
print("5. Exit")
print(" NB : If you want to change dataset, please edit the file named 'data kumpulan kalimat .txt' which is included in this folder of script file")
no=input("Choose the number of menu = ")
no = int(no)
if no==1:
print("\n=====Word Tokenize=====\n")
print(tokenize_word, "\n \n")
elif no==2:
print("\n=====Lower Case Converting=====\n")
print(words, "\n \n")
elif no==3:
print("\n=====Stop Word Removal=====\n")
print(word_tokens_no_stopwords, "\n \n")
elif no==4 :
print("\n=====Stemming=====\n")
print(word_stemming, "\n \n")
elif no==5 :
exit()
else :
print("Input the number range 1-5")