Skip to content
Snippets Groups Projects
gameparser.py 1.29 KiB
Newer Older
Evan Morgan's avatar
Evan Morgan committed
# List of "unimportant" words (feel free to add more)
skip_words = ['a', 'about', 'all', 'an', 'another', 'any', 'around', 'at',
              'bad', 'beautiful', 'been', 'better', 'big', 'can', 'every', 'for',
              'from', 'good', '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', 'small', 'some', 'soon',
              'that', 'the', 'then', 'this', 'those', 'through', 'till', 'to',
              'towards', 'until', 'us', 'want', 'we', 'what', 'when', 'why',
              'wish', 'with', 'would']

def filter_words(words, skip_words):
    for x in words:
        for y in skip_words:
            if x == y:
                words.remove(x)
Evan Morgan's avatar
Evan Morgan committed
    return words

def remove_punct(text):
    no_punct = ""
    punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^`{|}~'
Evan Morgan's avatar
Evan Morgan committed
    for char in text:
        if not (char in punctuation):
Evan Morgan's avatar
Evan Morgan committed
            no_punct = no_punct + char

    return no_punct

def normalise_input(user_input):
    user_input = remove_punct(user_input).lower()
    user_input = user_input.strip()
    user_input = list(user_input.split(" "))
    user_input = filter_words(user_input, skip_words)
    return user_input