Exemple #1
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)
Exemple #2
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)
Exemple #3
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())
Exemple #4
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)
Exemple #5
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)
Exemple #6
0
def test_attach_multi_omission():
    graph = Graph()
    pronunciations = [list("what"), list("wat")]
    graph.attach(pronunciations)
    assert sorted(graph.to_list()) == sorted(pronunciations)
Exemple #7
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)
Exemple #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)
Exemple #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)
Exemple #10
0
def test_attach_multi():
    graph = Graph()
    pronunciations = [list("hello"), list("halo")]
    graph.attach(pronunciations)
    assert sorted(graph.to_list()) == sorted(pronunciations)
Exemple #11
0
def test_attach_single():
    graph = Graph()
    pronunciations = [list("hey")]
    graph.attach(pronunciations)
    assert graph.to_list() == pronunciations
Exemple #12
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]))
Exemple #13
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)
Exemple #14
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)
Exemple #15
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"))
Exemple #16
0
def check_closest_phns(phns, pronunciations, expected_meta):
    graph = Graph()
    graph.attach(pronunciations)
    meta = closest(phns, graph)
    assert_closest(expected_meta, meta)