def get_kwic(tokens, index, context_window=5):
    """
    keyword in context

    Parameters
    ----------
    tokens : list of str
        a text represented as a list of tokens
    index : int
        the index of the keyword in the token list
    context_window : int
        the number of preceding/succeding words of the keyword to be
        retrieved

    Returns
    -------
    before : list of str
        the tokens preceding the keyword
    keyword : str
        the token at the index position
    after : list of str
        the tokens succeding the keyword
    """
    text_length = len(tokens)
    start_before = max(0, index-context_window)
    end_before = max(0, index)
    before = tokens[start_before:end_before]
    start_after = min(text_length, index+1)
    end_after = min(text_length, index+context_window+1)
    after = tokens[start_after:end_after]
    return before, tokens[index], after
keyword in context

    Parameters
    ----------
    tokens : list of str
        a text represented as a list of tokens
    index : int
        the index of the keyword in the token list
    context_window : int
        the number of preceding/succeding words of the keyword to be
        retrieved

    Returns
    -------
    before : list of str
        the tokens preceding the keyword
    keyword : str
        the token at the index position
    after : list of str
        the tokens succeding the keyword