def search_corpus(pattern, corpus, context, case_insensitive=True, expand_keyword=False, lemmatized=False, threshold=0.70):
    """Search for pattern in TLG or PHI5.
    TODO: Cleanup hyphenation.
    """

    corpora = ['tlg', 'phi5']
    assert corpus in corpora, "Available corpora: '{}'.".format(corpora)

    if type(context) is str:
        contexts = ['sentence', 'paragraph']
        assert context in contexts or type(context) is int, 'Available contexts: {}'.format(contexts)
    else:
        context = int(context)

    if corpus == 'phi5':
        lang = 'latin'
        index = PHI5_INDEX
        paths = assemble_phi5_author_filepaths()
    elif corpus == 'tlg':
        index = TLG_INDEX
        lang = 'greek'
        paths = assemble_tlg_author_filepaths()

    if expand_keyword:
        # Strip off all regex characters from pattern for Word2Vec lookup
        # First rm escaped chars
        # TODO: Add '\u', '\U', '\x' to this list
        escapes_list = [r'\a', r'\b', r'\f', r'\n', r'\r', r'\t', r'\v', r'\\']
        escapes_str = '|'.join(escapes_list)
        comp_escapes = regex.compile(escapes_str, flags=regex.VERSION1)
        pattern = comp_escapes.sub('', pattern)
        # Second rm remaining punctuation
        punctuation = set(string.punctuation)
        pattern = ''.join(ch for ch in pattern if ch not in punctuation)
        similar_vectors = _keyword_expander(pattern, lang, lemmatized=lemmatized, threshold=threshold)
        print("The following similar terms will be added to the '{0}' query: '{1}'.".format(pattern, similar_vectors))
        pattern = [pattern]
        if similar_vectors:
            pattern += similar_vectors
        else:
            pattern = pattern

    for path in paths:
        with open(path) as file_open:
            text = file_open.read()
        for one_pattern in pattern:
            _matches = match_regex(text, one_pattern, language=lang, context=context, case_insensitive=case_insensitive)
            for _match in _matches:
                _id = os.path.split(path)[1][:-4]
                author = index[_id]
                yield (author, _match)
Search for pattern in TLG or PHI5.
    TODO: Cleanup hyphenation.