Skip to content

Debugging Poetry with PyArud

PyArud's slot-level Viterbi DP aligner localizes metrical breaks down to individual feet and their exact Arudi text slices — never leaving you guessing where a verse went off-beat.


The 4 Foot Statuses (FootStatus)

Every FootAnalysis carries a status (FootStatus enum) and is_valid property:

Status (FootStatus) Icon Meaning Typical Cause / Repair
FootStatus.OK ("ok") ✓ Exact match to a permitted foot or Zihaf/'Ilah variation. None.
FootStatus.BROKEN ("broken") ✗ Syllables exist at this slot, but match no allowed variation. Check missing tashkeel/shaddah first via arudi_text, then adjust syllable weight to match expected_pattern.
FootStatus.MISSING ("missing") ? Hemistich ended before this foot could be formed. Line is too short (or belongs to a Majzoo sub-meter). Insert a word matching expected_pattern.
FootStatus.EXTRA_BITS ("extra_bits") + Leftover syllables remain after the final foot. Hemistich overflows by actual_segment; trim or compress wording.

Case Study 1: Checking Diacritization First

Missing Tashkeel Is the #1 False Break

Most apparent meter breaks in raw Arabic text come from missing short vowels (harakat), missing shaddah on solar ال or geminated roots, or unvocalized final letters. Always verify coverage with validate_tashkeel() (or pyarud scan --validate-tashkeel) before rewriting a verse.

from pyarud import ArudProcessor

processor = ArudProcessor()
text = "أَخِي جَاوَزَ الظَّالِمُونَ الْمَدَى"
print("Has enough tashkeel:", processor.validate_tashkeel(text, min_ratio=0.4))

Case Study 2: Pinpointing a Broken Foot

In this Al-Mutakareb draft, the first three feet of the Ajuz (وهاذا, كلامن, ثقيلن) match فعولن (11010), while the final foot جددا (1010) breaks the meter:

فَعُولُنْ 11010 وهاذا · OK
فَعُولُنْ 11010 كلامن · OK
فَعُولُنْ 11010 ثقيلن · OK
جددا 1010 BROKEN · expected 11010
from pyarud import ArudProcessor, FootStatus, format_verse_report

processor = ArudProcessor()
res = processor.analyze_verse(
    "أَخِي جَاوَزَ الظَّالِمُونَ الْمَدَى",
    "وَهَذَا كَلامٌ ثَقِيلٌ جِدًّا",
    forced_meter="mutakareb",
)

assert not res.is_valid
if res.ajuz:
    for foot in res.ajuz.feet:
        if foot.status != FootStatus.OK:
            print(
                f"Defect at Ajuz foot {foot.foot_index + 1} ({foot.status}): "
                f"expected {foot.expected_pattern}, got {foot.actual_segment} «{foot.arudi_text}»"
            )

print(format_verse_report(res, lang="en", style="compact", color=False))

Case Study 3: Missing Feet on a Truncated Line

When a hemistich ends prematurely, PyArud flags every absent foot as FootStatus.MISSING with its expected binary weight:

from pyarud import ArudProcessor, FootStatus

processor = ArudProcessor()
truncated = processor.analyze_verse(
    "طَوِيلٌ لَهُ دُونَ البُحُورِ فَضَائِلُ",
    "فَعُولُنْ مَفَاعِيلُنْ",
    forced_meter="taweel",
)

assert not truncated.is_valid
if truncated.ajuz:
    missing = [f for f in truncated.ajuz.feet if f.status == FootStatus.MISSING]
    assert len(missing) >= 1
    print(f"Missing {len(missing)} foot/feet in Ajuz.")