Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
]
Expand Down
35 changes: 30 additions & 5 deletions src/quran_transcript/phonetics/error_explainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ..
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/test_explain_error_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_explain_error_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.