diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 04ace83..65b4859 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -44,3 +44,4 @@ jobs: pytest -vv tests/aya_pytest.py pytest -vv tests/test_sub_with_mapping_pytest.py pytest -vv tests/test_phonemes_search_pytest.py + pytest -vv tests/test_explain_error_pytest.py diff --git a/pyproject.toml b/pyproject.toml index 298216f..c829469 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta" [project] license = "MIT" name = "quran-transcript" -version = "0.5.1" +version = "0.5.2" authors = [ { name="Abdullah", email="abdullahamlyossef@gmail.com" }, ] diff --git a/src/quran_transcript/phonetics/error_explainer.py b/src/quran_transcript/phonetics/error_explainer.py index 3b3974a..bdefca7 100644 --- a/src/quran_transcript/phonetics/error_explainer.py +++ b/src/quran_transcript/phonetics/error_explainer.py @@ -272,10 +272,17 @@ def explain_error( ph_pos = (ref_ph_start, ref_ph_end) else: # TODO: Make the uthmani posision more precise. Now we bound it to the aligments - uthmani_pos = ( - ref_ph_to_uthmani[ref_ph_start], - ref_ph_to_uthmani[ref_ph_start], - ) + if ref_ph_start in ref_ph_to_uthmani: + uthmani_pos = ( + ref_ph_to_uthmani[ref_ph_start], + ref_ph_to_uthmani[ref_ph_start], + ) + else: + uthmani_pos = ( + ref_ph_to_uthmani[ref_ph_start - 1], + ref_ph_to_uthmani[ref_ph_start - 1], + ) + ph_pos = (ref_ph_start, ref_ph_start) # TODO: for insert and replace try to make explanation for special phoneme like madd, ikhfaa, iqlab, .. @@ -418,8 +425,26 @@ def explain_error( elif ref_ph_groups[align.ref_idx][-1] in alph.phonetic_groups.residuals: ... + # Sakin Letter else: - raise ValueError("Uncaptured Error Explanation") + error_type = ( + "tashkeel" + if pred_ph[-1] in alph.phonetic_groups.harakat + else "normal" + ) + + errors.append( + ReciterError( + uthmani_pos=uthmani_pos, + ph_pos=ph_pos, + error_type=error_type, # TODO: try to estimate what is the Tajweed rule associated with this error type + speech_error_type="insert", + expected_ph=ref_ph, + preditected_ph=pred_ph, + ) + ) + + # raise ValueError("Uncaptured Error Explanation") pred_ph_start = pred_ph_end ref_ph_start = ref_ph_end diff --git a/tests/test_explain_error_api.py b/tests/test_explain_error_api.py index d2345a7..76b9291 100644 --- a/tests/test_explain_error_api.py +++ b/tests/test_explain_error_api.py @@ -29,6 +29,9 @@ # predicted_text = "ءَلِف لَااااااممممِۦۦۦۦۦۦم" # predicted_text = "ءَلِف لَاااااممممِۦۦۦۦۦۦم" + uthmani_text = "لَكَ" + predicted_text = "لَكَا" + ref_ph_out = quran_phonetizer(uthmani_text, moshaf) print(ref_ph_out.phonemes) print(predicted_text) diff --git a/tests/test_explain_error_pytest.py b/tests/test_explain_error_pytest.py index 8eb5d48..cb4d3de 100644 --- a/tests/test_explain_error_pytest.py +++ b/tests/test_explain_error_pytest.py @@ -29,6 +29,8 @@ def moshaf(): ) def test_explain_error_cases(uthmani_text, predicted_text, moshaf): ref_ph_out = quran_phonetizer(uthmani_text, moshaf) + print(uthmani_text) + print(predicted_text) errors = explain_error( uthmani_text=uthmani_text, ref_ph_text=ref_ph_out.phonemes, @@ -42,4 +44,3 @@ def test_explain_error_cases(uthmani_text, predicted_text, moshaf): for err in errors: assert 0 <= err.uthmani_pos[0] <= err.uthmani_pos[1] <= len(uthmani_text) assert 0 <= err.ph_pos[0] <= err.ph_pos[1] <= len(ref_ph_out.phonemes) - diff --git a/uv.lock b/uv.lock index f7d108f..a0091b3 100644 --- a/uv.lock +++ b/uv.lock @@ -557,7 +557,7 @@ wheels = [ [[package]] name = "quran-transcript" -version = "0.5.1" +version = "0.5.2" source = { editable = "." } dependencies = [ { name = "fuzzysearch" },