forked from meliksahturker/Turkish-NLP-Preprocessing-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utility.py
26 lines (19 loc) · 726 Bytes
/
Utility.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
def load_file(filename):
file = open(filename, "r", encoding = 'utf-8')
if file.mode == 'r':
contents = file.read()
return contents
def write_file(list_of_tokens, filename):
file = open(filename, "a+", encoding = 'utf-8')
size = len(list_of_tokens)
for i in range(size):
file.write("%s\r\n" % (list_of_tokens[i]))
def load_words(wordlist_filename):
wordlist = list()
# 'with' can automate finish 'open' and 'close' file
with open(wordlist_filename, encoding = 'utf-8') as f:
# fetch one line each time, include '\n'
for line in f:
# strip '\n', then append it to wordlist
wordlist.append(line.rstrip('\n'))
return wordlist