def character_index(X, digits_word):
    """
    Map each character present in the dataset into an unique integer.

    From: https://github.com/dhlab-epfl/LinkedBooksDeepReferenceParsing

    All digits are mapped into a single array.

    Args:
        X(list): Data to retrieve characters from.
        digits_word(str): Words regrouping all digits

    Returns:
        A dictionary where each character is maped into a unique integer, the
            maximum number of words in the data, the maximum of characters in
            a word.
    """

    # Create a set of all character

    all_chars = list(set([c for s in X for w in s for c in w]))

    # Create an index for each character. The index 1 is reserved for the
    # digits, substituted by digits_word.

    char2ind = {char: index for index, char in enumerate(all_chars, 2)}
    ind2char = {index: char for index, char in enumerate(all_chars, 2)}

    # To deal with out-of-vocabulary words

    char2ind.update({digits_word: 1})
    ind2char.update({1: digits_word})

    # For padding

    max_char = max([len(w) for s in X for w in s])

    return char2ind, max_char