import re


def clean_str(string):
    """
    Tokenization/string cleaning for all datasets except for SST.
    Original taken from https://github.com/yoonkim/CNN_sentence/blob/master/process_data.py
    """
    string = re.sub(r"[^A-Za-z0-9(),!?\'\`]", " ", string)  # replace everything that is not a number, letter or a few chars for a white space
    string = re.sub(r"\'s", " \'s", string)     # adds a space for "'s". Example: that's -> that 's
    string = re.sub(r"\'ve", " \'ve", string)   # adds a space for "'ve". Example: you've -> you 've
    string = re.sub(r"n\'t", " n\'t", string)   # adds a space for "n't". Example: can't -> ca n't
    string = re.sub(r"\'re", " \'re", string)   # adds a space for "'re". Example: you're -> you 're
    string = re.sub(r"\'d", " \'d", string)     # adds a space for "'d". Example: you'd -> you 'd
    string = re.sub(r"\'ll", " \'ll", string)   # adds a space for "'ll". Example: you'll -> you 'll
    string = re.sub(r",", " , ", string)        # adds a space for ",". Example: you, me -> you , me
    string = re.sub(r"!", " ! ", string)        # adds a space for "!". Example: not! -> not !
    string = re.sub(r"\(", " \( ", string)      # adds a slash and space for "(". Example: and) -> and \)
    string = re.sub(r"\)", " \) ", string)      # adds a slash and space for ")". Example: (and -> \( and
    string = re.sub(r"\?", " \? ", string)      # adds a slash and space for "?". Example: and? -> and \?
    string = re.sub(r"\s{2,}", " ", string)     # Replace 2 or more whitespaces for only one
    return string.strip().lower()