diff --git a/.github/workflows/test-pip-install.yaml b/.github/workflows/test-pip-install.yaml index e90b836..6f1f082 100644 --- a/.github/workflows/test-pip-install.yaml +++ b/.github/workflows/test-pip-install.yaml @@ -51,7 +51,7 @@ jobs: - name: Install kaldialign shell: bash run: | - pip3 install --verbose kaldialign + pip3 install --verbose 'kaldialign[test]' - name: Run test shell: bash @@ -59,5 +59,5 @@ jobs: cd tests python3 -c "import kaldialign; print(kaldialign.__file__)" python3 -c "import kaldialign; print(kaldialign.__version__)" + pytest . - python3 ./test_align.py diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 421bcf8..8993d5a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -43,4 +43,4 @@ jobs: - name: Test shell: bash run: | - python3 ./tests/test_align.py + pytest -vv ./tests/test_align.py diff --git a/CMakeLists.txt b/CMakeLists.txt index cc59d5d..12454d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ cmake_minimum_required(VERSION 3.8 FATAL_ERROR) project(kaldialign CXX) # Please remember to also change line 3 of ./scripts/conda/kaldialign/meta.yaml -set(KALDIALIGN_VERSION "0.9") +set(KALDIALIGN_VERSION "0.9.1") if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) diff --git a/kaldialign/__init__.py b/kaldialign/__init__.py index 3d725cb..08ff18d 100644 --- a/kaldialign/__init__.py +++ b/kaldialign/__init__.py @@ -38,7 +38,13 @@ def edit_distance( ans = _kaldialign.edit_distance(refi, hypi, sclite_mode) ans["ref_len"] = len(refi) - ans["err_rate"] = ans["total"] / len(refi) + try: + ans["err_rate"] = ans["total"] / len(refi) + except ZeroDivisionError: + if ans["total"] == 0: + ans["err_rate"] = 0.0 + else: + ans["err_rate"] = float("inf") return ans diff --git a/scripts/conda/kaldialign/meta.yaml b/scripts/conda/kaldialign/meta.yaml index 33b04e0..f89f663 100644 --- a/scripts/conda/kaldialign/meta.yaml +++ b/scripts/conda/kaldialign/meta.yaml @@ -1,6 +1,6 @@ package: name: kaldialign - version: "0.9" + version: "0.9.1" source: path: "{{ environ.get('KALDIALIGN_ROOT_DIR') }}" diff --git a/tests/test_align.py b/tests/test_align.py index 1832874..8e7766b 100644 --- a/tests/test_align.py +++ b/tests/test_align.py @@ -86,6 +86,34 @@ def test_edit_distance(): } +def test_edit_distance_zero_len_ref_zero_err(): + a = [] + b = [] + results = edit_distance(a, b) + assert results == { + "ins": 0, + "del": 0, + "sub": 0, + "total": 0, + "ref_len": 0, + "err_rate": 0, + } + + +def test_edit_distance_zero_len_ref_with_err(): + a = [] + b = ["a"] + results = edit_distance(a, b) + assert results == { + "ins": 1, + "del": 0, + "sub": 0, + "total": 1, + "ref_len": 0, + "err_rate": float("inf"), + } + + def test_edit_distance_sclite(): a = ["a", "b"] b = ["b", "c"] @@ -156,10 +184,3 @@ def test_bootstrap_wer_ci_2system(): assert ans["p_s2_improv_over_s1"] == 1.0 - -if __name__ == "__main__": - test_align() - test_edit_distance() - test_edit_distance_sclite() - test_bootstrap_wer_ci_1system() - test_bootstrap_wer_ci_2system()