Example #1
0
def compare_nodes(ngrams, ref_trie, test_trie):
    # compare root
    compare_node([], ref_trie, test_trie)
    # compare random node, may not existe (check exception)
    compare_node([420001337] * 10, ref_trie, test_trie)
    # compare all ngrams
    for n in ngrams:
        for i in range(len(n)):
            compare_node(n[:i+1], ref_trie, test_trie)
            # try a non-existent node:  should raise exception in both case
            compare_node(n[:i] + [420001337], ref_trie, test_trie)
        compare_node(n + [420001337], ref_trie, test_trie) # try a non-existent node
Example #2
0
def compare_nodes(ngrams, ref_trie, test_trie):
    # compare root
    compare_node([], ref_trie, test_trie)
    # compare random node, may not existe (check exception)
    compare_node([420001337] * 10, ref_trie, test_trie)
    # compare all ngrams
    for n in ngrams:
        for i in range(len(n)):
            compare_node(n[:i + 1], ref_trie, test_trie)
            # try a non-existent node:  should raise exception in both case
            compare_node(n[:i] + [420001337], ref_trie, test_trie)
        compare_node(n + [420001337], ref_trie,
                     test_trie)  # try a non-existent node
Example #3
0
def test_storage_random(storage, ref_class=PyMemoryStorage):
    ref = ref_class(default_ngram_length=storage.default_ngram_length)
    ref.clear()
    storage.clear()

    testfile = open("tests/fixtures/btree.txt").read().split("\n")
    sentences = (re.findall(r"\w+", sentence) for sentence in testfile)
    for sentence in sentences:
        ref.add_sentence(sentence)
        storage.add_sentence(sentence)

    # compare of each ngram of each sentence
    for sentence in sentences:
        for start in range(len(sentence)):
            for length in range(ngram_length):
                ngram = sentence[start : start + length]
                compare_node(ngram, ref, storage)
Example #4
0
def test_storage_random(storage, ref_class=PyMemoryStorage):
    ref = ref_class(default_ngram_length=storage.default_ngram_length)
    ref.clear()
    storage.clear()

    testfile = open('tests/fixtures/btree.txt').read().split('\n')
    sentences = (re.findall(r'\w+', sentence) for sentence in testfile)
    for sentence in sentences:
        ref.add_sentence(sentence)
        storage.add_sentence(sentence)

    # compare of each ngram of each sentence
    for sentence in sentences:
        for start in range(len(sentence)):
            for length in range(ngram_length):
                ngram = sentence[start:start+length]
                compare_node(ngram, ref, storage)