|
| 1 | +import os |
| 2 | +import tempfile |
| 3 | +from typing import Optional |
| 4 | + |
| 5 | +from sisyphus import tk, setup_path |
| 6 | + |
| 7 | +from i6_core.tools.compile import MakeJob |
| 8 | +from i6_core.tools.git import CloneGitRepositoryJob |
| 9 | +from i6_core.recognition import ScliteJob |
| 10 | + |
| 11 | +rel_path = setup_path(__package__) |
| 12 | + |
| 13 | + |
| 14 | +def compile_sctk( |
| 15 | + branch: Optional[str] = None, |
| 16 | + commit: Optional[str] = None, |
| 17 | + sctk_git_repository: str = "https://github.com/usnistgov/SCTK.git", |
| 18 | +) -> tk.Path: |
| 19 | + """ |
| 20 | + :param branch: specify a specific branch |
| 21 | + :param commit: specify a specific commit |
| 22 | + :param sctk_git_repository: where to clone SCTK from, usually does not need to be altered |
| 23 | + :return: SCTK binary folder |
| 24 | + """ |
| 25 | + sctk_job = CloneGitRepositoryJob(url=sctk_git_repository, branch=branch, commit=commit) |
| 26 | + sctk_job.run() |
| 27 | + |
| 28 | + sctk_make = MakeJob( |
| 29 | + folder=sctk_job.out_repository, |
| 30 | + make_sequence=["config", "all", "check", "install", "doc"], |
| 31 | + link_outputs={"bin": "bin/"}, |
| 32 | + ) |
| 33 | + sctk_make.run() |
| 34 | + # This is needed for the compilation to work in the i6 environment, otherwise still untested |
| 35 | + return sctk_make.out_links["bin"] |
| 36 | + |
| 37 | + |
| 38 | +def test_sclite_job(): |
| 39 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 40 | + from sisyphus import gs |
| 41 | + |
| 42 | + gs.WORK_DIR = tmpdir |
| 43 | + sctk_binary = compile_sctk(branch="v2.4.12") |
| 44 | + hyp = rel_path("files/hyp.ctm") |
| 45 | + ref = rel_path("files/ref.stm") |
| 46 | + |
| 47 | + sclite_job = ScliteJob(ref=ref, hyp=hyp, sctk_binary_path=sctk_binary) |
| 48 | + sclite_job._sis_setup_directory() |
| 49 | + sclite_job.run() |
| 50 | + |
| 51 | + assert sclite_job.out_wer.get() == 58.8, "Wrong WER, %s instead of 58.8" % str(sclite_job.out_wer.get()) |
| 52 | + assert sclite_job.out_num_errors.get() == 10, "Wrong num errors, %s instead of 10" % str( |
| 53 | + sclite_job.out_num_errors.get() |
| 54 | + ) |
| 55 | + assert sclite_job.out_percent_correct.get() == 47.1, "Wrong percent correct, %s instead of 47.1" % str( |
| 56 | + sclite_job.out_percent_correct.get() |
| 57 | + ) |
| 58 | + assert sclite_job.out_num_correct.get() == 8, "Wrong num correct, %s instead of 8" % str( |
| 59 | + sclite_job.out_num_correct.get() |
| 60 | + ) |
| 61 | + assert ( |
| 62 | + sclite_job.out_percent_substitution.get() == 41.2 |
| 63 | + ), "Wrong percent substitution, %s instead of 41.2" % str(sclite_job.out_percent_substitution.get()) |
| 64 | + assert sclite_job.out_num_substitution.get() == 7, "Wrong num substitution, %s instead of 7" % str( |
| 65 | + sclite_job.out_num_substitution.get() |
| 66 | + ) |
| 67 | + assert sclite_job.out_percent_deletions.get() == 11.8, "Wrong percent deletions, %s instead of 11.8" % str( |
| 68 | + sclite_job.out_percent_deletions.get() |
| 69 | + ) |
| 70 | + assert sclite_job.out_num_deletions.get() == 2, "Wrong num deletions, %s instead of 2" % str( |
| 71 | + sclite_job.out_num_deletions.get() |
| 72 | + ) |
| 73 | + assert sclite_job.out_percent_insertions.get() == 5.9, "Wrong percent insertions, %s instead of 4.5" % str( |
| 74 | + sclite_job.out_percent_insertions.get() |
| 75 | + ) |
| 76 | + assert sclite_job.out_num_insertions.get() == 1, "Wrong num insertions, %s instead of 1" % str( |
| 77 | + sclite_job.out_num_insertions.get() |
| 78 | + ) |
| 79 | + assert ( |
| 80 | + sclite_job.out_percent_word_accuracy.get() == 41.2 |
| 81 | + ), "Wrong percent word accuracy, %s instead of 41.2" % str(sclite_job.out_percent_word_accuracy.get()) |
| 82 | + assert sclite_job.out_ref_words.get() == 17, "Wrong num ref words, %s instead of 17" % str( |
| 83 | + sclite_job.out_ref_words.get() |
| 84 | + ) |
| 85 | + assert sclite_job.out_hyp_words.get() == 16, "Wrong num hyp words, %s instead of 16" % str( |
| 86 | + sclite_job.out_hyp_words.get() |
| 87 | + ) |
| 88 | + assert sclite_job.out_aligned_words.get() == 18, "Wrong num aligned words, %s instead of 18" % str( |
| 89 | + sclite_job.out_aligned_words.get() |
| 90 | + ) |
0 commit comments