import re


def encode_text(text, lookup_table, max_sequence_length=None):
  """Encode a sentence into tokens with a lookup table.

  Args:
    text: a string to be encoded
    lookup_table: a table that maps tokens to integers
    max_sequence_length: maximum length of the token sequences

  Returns:
    encoded text
  """
  if text[-3:] != 'eos':
    text += ' eos'
  sentence = re.findall(r"[\w']+|[.,!?;]", text)
  encoded_sentence = []
  for w in sentence:
    if w == 'that': continue
    encoded_sentence.append(lookup_table[w.lower()])
  if max_sequence_length:
    return encoded_sentence[:max_sequence_length]
  else:
    return encoded_sentence