Skip to content

Commit 6bb893f

Browse files
authored
Add test for sclite (#443)
1 parent de25e89 commit 6bb893f

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed

tests/job_tests/recognition/__init__.py

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
;; <name> <track> <start> <duration> <word> <confidence> [<n-best>]
2+
;; TestCorpus/File/1 (00.00-04.00)
3+
File 1 00.00 01.00 this 1.0000
4+
File 1 01.00 01.00 one 1.0000
5+
File 1 02.00 01.00 is 1.0000
6+
File 1 03.00 01.00 correct 1.0000
7+
;; TestCorpus/File/2 (06.00-12.00)
8+
File 1 06.00 01.00 this 1.0000
9+
File 1 07.00 01.00 one 1.0000
10+
File 1 08.00 01.00 is 1.0000
11+
File 1 09.00 01.00 not 1.0000
12+
File 1 10.00 01.00 really 1.0000
13+
File 1 11.00 01.00 good 1.0000
14+
;; TestCorpus/File/3 (13.00-19.00)
15+
File 1 13.00 01.00 no 1.0000
16+
File 1 14.00 01.00 clue 1.0000
17+
File 1 15.00 01.00 what 1.0000
18+
File 1 16.00 03.00 was 1.0000
19+
;; TestCorpus/File/4 (20.00-22.00)
20+
File 1 20.00 01.00 insertion 1.0000
21+
File 1 21.00 01.00 case 1.0000
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
File 1 Test 00.00 04.00 <d0> this one is correct
2+
File 1 Test 06.00 12.00 <d0> this one is a bit longer
3+
File 1 Test 13.00 19.00 <d0> this one is also quite long
4+
File 1 Test 20.00 22.00 <d0> case
5+
;; LABEL "d0" "default0" "all other segments of category 0"
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

Comments
 (0)