예제 #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)