def case_normalizer(word, dictionary):
    """In case the word is not available in the vocabulary, we can try multiple
    case normalizing procedures. We consider the best substitute to be the one
    with the lowest index, which is equivalent to the most frequent
    alternative.

    Obtained from

        https://nbviewer.jupyter.org/gist/aboSamoor/6046170

    Args:
        word (str): The word.
        dictionary (list): The dictionary.

    Returns:
        (str): The case-normalized word.

    """
    w = word
    lower = (dictionary.get(w.lower(), 1e12), w.lower())
    upper = (dictionary.get(w.upper(), 1e12), w.upper())
    title = (dictionary.get(w.title(), 1e12), w.title())
    results = [lower, upper, title]
    results.sort()
    index, w = results[0]
    if index != 1e12:
        return w
    return word