Пример #1
0
def test_graph_add_phn_to_root():
    graph = Graph()
    phn = "a"
    node = graph.__add_phn__(phn)

    assert graph.roots[0].value == phn
    assert graph.roots == [node]
Пример #2
0
def check_closest_tensor(tensor,
                         tensor_dict,
                         pronunciations,
                         expected_meta={},
                         **kwargs):
    graph = Graph()
    graph.attach(pronunciations)
    meta = closest(tensor, graph, tensor_dict=tensor_dict, **kwargs)
    assert_closest(expected_meta, meta)
Пример #3
0
def test_triples_empty_edges():
    graph = Graph()
    pronunciations = [list("wat"), list("what")]
    graph.attach(pronunciations)
    canonical = ["wa", "wh", "wha", "wat", "hat", "at"]
    strings = [
        "".join([node.value for node in triple if node]) for triple in graph.triples()
    ]
    assert sorted(canonical) == sorted(strings)
Пример #4
0
def test_triples():
    graph = Graph()
    pronunciations = [list("hello"), list("halo")]
    graph.attach(pronunciations)
    canonical = ["he", "ha", "hel", "hal", "ell", "llo", "alo", "lo"]
    strings = [
        "".join([node.value for node in triple if node]) for triple in graph.triples()
    ]
    assert sorted(canonical) == sorted(strings)
Пример #5
0
def create_graph_and_check(canonical, *changed):
    graph = Graph()
    canonical = deep_phn(canonical)
    changed = [deep_phn(it) for it in changed]
    for word in canonical:
        graph.attach([word])
    apply(graph)
    canonical = [flatten(canonical), *[flatten(it) for it in changed]]
    assert sorted(canonical) == sorted(graph.to_list())
Пример #6
0
def test_attach_multi_different_beginning_and_length():
    graph = Graph()
    pronunciations = [list("wat"), list("hwat")]
    graph.attach(pronunciations)
    assert sorted(graph.to_list()) == sorted(pronunciations)
Пример #7
0
def test_graph_init():
    graph = Graph()
    assert graph.roots == []
    assert graph.tails == []
Пример #8
0
def test_attach_multi_three():
    graph = Graph()
    pronunciations = [list("hi"), list("ho"), list("hu")]
    graph.attach(pronunciations)
    assert sorted(graph.to_list()) == sorted(pronunciations)
Пример #9
0
def test_attach_multi_different_ending():
    graph = Graph()
    pronunciations = [list("hi"), list("ho")]
    graph.attach(pronunciations)
    assert sorted(graph.to_list()) == sorted(pronunciations)
Пример #10
0
def test_attach_multi():
    graph = Graph()
    pronunciations = [list("hello"), list("halo")]
    graph.attach(pronunciations)
    assert sorted(graph.to_list()) == sorted(pronunciations)
Пример #11
0
def test_attach_single():
    graph = Graph()
    pronunciations = [list("hey")]
    graph.attach(pronunciations)
    assert graph.to_list() == pronunciations
Пример #12
0
def test_transition_matrix():
    graph = Graph()
    pronunciations = [list("wat"), list("what")]
    graph.attach(pronunciations)
    canonical = np.array([[1, 1, 1, 0.5], [0, 1, 1, 0.5], [0, 0, 1, 1], [0, 0, 0, 1]])
    np.testing.assert_equal(canonical, graph.transition_matrix)
Пример #13
0
def test_distance_matrix():
    graph = Graph()
    pronunciations = [list("wat"), list("what")]
    graph.attach(pronunciations)
    canonical = [[0, 1, 1, 2], [0, 0, 1, 2], [0, 0, 0, 1], [0, 0, 0, 0]]
    np.testing.assert_equal(canonical, graph.distance_matrix)
Пример #14
0
def test_iter():
    graph = Graph()
    pronunciations = [list("hello"), list("halo")]
    graph.attach(pronunciations)
    assert sorted([node.value for node in graph.nodes]) == sorted(list("helloa"))
Пример #15
0
def test_attach_multi_omission():
    graph = Graph()
    pronunciations = [list("what"), list("wat")]
    graph.attach(pronunciations)
    assert sorted(graph.to_list()) == sorted(pronunciations)
Пример #16
0
def test_initial_transitions():
    graph = Graph()
    pronunciations = [list("wat"), list("what")]
    graph.attach(pronunciations)
    np.testing.assert_equal(graph.initial_transitions, np.array([1, 0.5, 0.5, 0.25]))
Пример #17
0
def test_attach_multi_different_beginning_and_ending():
    graph = Graph()
    pronunciations = [list("am"), list("ofi")]
    graph.attach(pronunciations)
    assert sorted(graph.to_list()) == sorted(pronunciations)
Пример #18
0
def check_closest_phns(phns, pronunciations, expected_meta):
    graph = Graph()
    graph.attach(pronunciations)
    meta = closest(phns, graph)
    assert_closest(expected_meta, meta)