예제 #1
0
def test_from_text_multiple_words():
    res = from_text("hello world abzug", apply_heuristics=False).to_list()
    assert len(res) == 4
    assert sorted(deep_str(res)) == sorted(
        [
            ["hh", "ah", "l", "ow", "w", "er", "l", "d", "ae", "b", "z", "ah", "g"],
            ["hh", "ah", "l", "ow", "w", "er", "l", "d", "ae", "b", "z", "uh", "g"],
            ["hh", "eh", "l", "ow", "w", "er", "l", "d", "ae", "b", "z", "ah", "g"],
            ["hh", "eh", "l", "ow", "w", "er", "l", "d", "ae", "b", "z", "uh", "g"],
        ]
    )
예제 #2
0
def test_from_text_multiple_words_with_heuristics():
    res = from_text("fat boy texts good girl", apply_heuristics=True).to_list()
    assert len(res) == 16

    # fmt: off
    assert sorted(deep_str(res)) == sorted([
        ['f', 'ae', 'p', 'b', 'oy', 't', 'eh', 'k', 's', 'g', 'ih', 'd', 'g', 'er', 'l'],
        ['f', 'ae', 'p', 'b', 'oy', 't', 'eh', 'k', 's', 'g', 'ih', 'g', 'er', 'l'],
        ['f', 'ae', 'p', 'b', 'oy', 't', 'eh', 'k', 's', 'g', 'uh', 'd', 'g', 'er', 'l'],
        ['f', 'ae', 'p', 'b', 'oy', 't', 'eh', 'k', 's', 'g', 'uh', 'g', 'er', 'l'],
        ['f', 'ae', 'p', 'b', 'oy', 't', 'eh', 'k', 's', 't', 's', 'g', 'ih', 'd', 'g', 'er', 'l'],
        ['f', 'ae', 'p', 'b', 'oy', 't', 'eh', 'k', 's', 't', 's', 'g', 'ih', 'g', 'er', 'l'],
        ['f', 'ae', 'p', 'b', 'oy', 't', 'eh', 'k', 's', 't', 's', 'g', 'uh', 'd', 'g', 'er', 'l'],
        ['f', 'ae', 'p', 'b', 'oy', 't', 'eh', 'k', 's', 't', 's', 'g', 'uh', 'g', 'er', 'l'],
        ['f', 'ae', 't', 'b', 'oy', 't', 'eh', 'k', 's', 'g', 'ih', 'd', 'g', 'er', 'l'],
        ['f', 'ae', 't', 'b', 'oy', 't', 'eh', 'k', 's', 'g', 'ih', 'g', 'er', 'l'],
        ['f', 'ae', 't', 'b', 'oy', 't', 'eh', 'k', 's', 'g', 'uh', 'd', 'g', 'er', 'l'],
        ['f', 'ae', 't', 'b', 'oy', 't', 'eh', 'k', 's', 'g', 'uh', 'g', 'er', 'l'],
        ['f', 'ae', 't', 'b', 'oy', 't', 'eh', 'k', 's', 't', 's', 'g', 'ih', 'd', 'g', 'er', 'l'],
        ['f', 'ae', 't', 'b', 'oy', 't', 'eh', 'k', 's', 't', 's', 'g', 'ih', 'g', 'er', 'l'],
        ['f', 'ae', 't', 'b', 'oy', 't', 'eh', 'k', 's', 't', 's', 'g', 'uh', 'd', 'g', 'er', 'l'],
        ['f', 'ae', 't', 'b', 'oy', 't', 'eh', 'k', 's', 't', 's', 'g', 'uh', 'g', 'er', 'l'],
    ])
예제 #3
0
#        "reupholstering",
#        "castorbeans"
#    ]

cers = []
cers_no_contractions = []
skipped = 0
missing = set()
for item in tqdm(data):
    # Preprocessing data
    _phns = phns.utils.timit_to_cmu(item["phns"])
    _phns = [phns.Phn(phn) for phn in _phns if phn != "sil"]

    graph = phns.from_text(
        item["text"],
        missing_handler=lambda word: missing.add(word),
        apply_confusion=True,
    )
    if graph:
        result = phns.closest(_phns, graph)
        cers.append(result["cmu_cer"])
        if result["cmu_cer"] > 0.3 and False:
            print(item["text"])
            print("phns", item["phns"])
            print("_phns", [phn.val for phn in _phns])
            print("targt", [phn.val for phn in result["target"]])
            print("match", [graph.nodes[m].value.val for m in result["match"]])
            print(result)
            import ipdb

            ipdb.set_trace()
예제 #4
0
def test_from_text_missing_handler_skip():
    res = from_text("foobar42", lambda _: False)
    assert res is None
예제 #5
0
def test_from_text_missing_handler():
    res = from_text("foobar42", lambda _: [["p"]]).to_list()
    assert deep_str(res) == [["p"]]
예제 #6
0
def test_from_text_single_word():
    res = from_text("hello", apply_heuristics=False).to_list()
    assert len(res) == 2
    assert sorted(deep_str(res)) == sorted(
        [["hh", "eh", "l", "ow"], ["hh", "ah", "l", "ow"]]
    )