-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilewrangler.py
40 lines (34 loc) · 1.06 KB
/
filewrangler.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
def create_corpus(filename):
input_string = getStringFromFile(filename)
input_string = sanitizeText(input_string)
return createWordList(input_string)
def getStringFromFile(filename):
'''
Get string of words from Text File
'''
with open(filename) as f:
return f.read()
def sanitizeText(sourceText):
'''
Santize words
'''
acceptedChars = set("'\nabcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ")
return ''.join(filter(acceptedChars.__contains__, sourceText)).replace("\n", " ").lower()
def createWordList(sourceText):
'''
Create list of words
'''
splitText = sourceText.split(" ")
#Remove any empty values
for item in splitText:
if item == "":
splitText.pop(splitText.index(item))
return [token for token in splitText if token != '']
def create_sentence_list(filename):
'''
Split text into sentences
'''
input_string = getStringFromFile(filename)
input_string = sanitizeText(input_string)
def split_sentences(input_string):
pass