-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameparser.py
More file actions
39 lines (32 loc) · 1.47 KB
/
Copy pathGameparser.py
File metadata and controls
39 lines (32 loc) · 1.47 KB
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
import string
#List of "unimportant" words (feel free to add more)
skip_words = ['a', 'about', 'all', 'an', 'another', 'any', 'around', 'at',
'bad', 'bat', 'beautiful', 'been', 'better', 'big', 'can', 'do', 'every', 'for',
'from', 'good', 'gun', 'have', 'her', 'here', 'hers', 'his', 'how',
'i', 'if', 'in', 'into', 'is', 'it', 'its', 'large', 'later',
'like', 'little', 'main', 'me', 'mine', 'more', 'my', 'now',
'of', 'off', 'oh', 'on', 'please', 'show', 'small', 'some', 'soon',
'that', 'the', 'then', 'this', 'those', 'through', 'till', 'to',
'towards', 'until', 'us', 'use', 'want', 'we', 'what', 'when', 'why',
'wish', 'with', 'would']
def filter_words(words, skip_words):
#This function filters user's input using skip_words dictionary.
new_words = words.copy()
for n_word in words:
for s_word in skip_words:
if(n_word == s_word):
new_words.remove(n_word)
return new_words
def remove_punct(text):
#This removes all of the punctuation
no_punct = ""
for char in text:
if not (char in string.punctuation):
no_punct = no_punct + char
return no_punct
def normalise_input(user_input):
#Remove punctuation and convert to lower case
no_punct = remove_punct(user_input).lower()
no_punct = no_punct.split()
no_punct = filter_words(no_punct, skip_words)
return no_punct