Пример #1
0
def test_isin():
    for n in range(1, 200):
        words = make_words(n)
        ms = MultiSearch(words)
        assert ms.isin(text) == True

    ms = MultiSearch(["XXXX", "YYYY"])
    assert ms.isin(text) == False
Пример #2
0
def test_search_twice():
    for n in range(1, 200):
        words = make_words(n)
        ms = MultiSearch(words)
        res1 = multi_search(None, text, ms)
        res2 = multi_search(None, text, ms)
        assert res1 == res2
Пример #3
0
def multi_iter_search_with_keep(words, texts, ms=None):
    from itertools import chain
    if ms is None:
        ms = MultiSearch(words)

    results = []
    for text in texts:
        results.extend(ms.iter_search(text, keep=True))
    results.sort()
    return results
Пример #4
0
def multi_search(words, text, ms=None):
    if ms is None:
        ms = MultiSearch(words)
    results = []

    def callback(pos, word):
        results.append((pos, word))
        return False

    ms.search(text, callback)
    results.sort()
    return results
Пример #5
0
def multi_iter_search(words, text, ms=None):
    if ms is None:
        ms = MultiSearch(words)
    results = list(ms.iter_search(text))
    results.sort()
    return results