from typing import Counter


def get_vocabulary(fobj, nb_lines=None):
    """Read text and return dictionary that encodes vocabulary
    """
    vocab = Counter()
    for index, line in enumerate(fobj):
        if nb_lines is not None and index >= nb_lines:
            break

        for word in line.strip().split(" "):
            vocab[word] += 1

    return vocab