from typing import Counter


def preprocess(text):
  """
  Converts any puctuation into tokens, creates a counter dictionary of the data,
  and trims the data dictionary of words with occurrances less than five
  Input:
  * text: a text file containing words
  Output:
  * returns a trimmed counter dictionary of tokenized words 
  """
  # Replace punctuation with tokens so we can use them in our model
  text = text.lower()
  text = text.replace('.', ' <PERIOD> ')
  text = text.replace(',', ' <COMMA> ')
  text = text.replace('"', ' <QUOTATION_MARK> ')
  text = text.replace(';', ' <SEMICOLON> ')
  text = text.replace('!', ' <EXCLAMATION_MARK> ')
  text = text.replace('?', ' <QUESTION_MARK> ')
  text = text.replace('(', ' <LEFT_PAREN> ')
  text = text.replace(')', ' <RIGHT_PAREN> ')
  text = text.replace('--', ' <HYPHENS> ')
  text = text.replace('?', ' <QUESTION_MARK> ')
  # text = text.replace('\n', ' <NEW_LINE> ') # Uncomment this if your text has newlines
  text = text.replace(':', ' <COLON> ')
  words = text.split()
  # Get a dictionary with the words and their occurances
  word_counts = Counter(words)
  # Remove all words with  5 or fewer occurences
  trimmed_words = [word for word in words if word_counts[word] > 5]
  return trimmed_words