def create_filtered_vocabulary(preprocessed_word_to_occurrence,
                               special_symbols,
                               vocabulary_filter):
    """Creates a vocabulary (word enumeration and occurrence dicts) from candidate set filtered with a vocabulary_filter
       predicate and additional special symbols"""
    word_to_occurrence = {}
    word_to_id = {}
    new_word_id = lambda : len(word_to_id)

    # Add special symbols to the vocabulary first
    for sw in special_symbols:
        # print("Adding special symbol to vocabulary %s" % sw)
        word_to_occurrence[sw] = 0
        word_to_id[sw] = new_word_id()

    for word, occurrence in preprocessed_word_to_occurrence.items():
        if word not in word_to_id:
            if vocabulary_filter(word, occurrence):
                word_to_id[word] = new_word_id()
                word_to_occurrence[word] = preprocessed_word_to_occurrence[word]

    return word_to_id, word_to_occurrence