def align_corpora(old_corpus, new_corpus, remove_empty=True):
    """Takes two Corpus objects `old_corpus` and `new_corpus` and returns
    a copy of `new_corpus` with the following modifications: (1) the
    word to integer mapping agrees with that of `old_corpus` and (2)
    words in `new_corpus` which do not appear in `old_corpus` are
    removed from the corpus. Empty documents are removed.

    """
    new_words = [w for w in new_corpus.words if w not in old_corpus.words]
    out = new_corpus.apply_stoplist(new_words)
    if remove_empty:
        out.remove_empty()

    int_words = out.words
    words_int = old_corpus.words_int
    int_int = {}
    for i in range(len(int_words)):
        int_int[i] = words_int[int_words[i]]

    for i in range(len(out.corpus)):
        out.corpus[i] = int_int[out.corpus[i]]
    out.words = old_corpus.words.copy()
    out._set_words_int()

    return out