I built a deterministic engine to analyze 8th-century Arabic Poetry meters (Arud) with Python

Posted by chou404@reddit | Python | View on Reddit | 3 comments

Hi everyone,

I’ve just released PyArud v0.1.3, a Python library that digitizes the science of Arabic Prosody (ilm al-Arudh), originally founded by Al-Khalil bin Ahmed in the 8th century.

What My Project Does

Arabic poetry is built on a binary system of "Moving" (Mutaharrik) and "Still" (Sakin) sounds, forming 16 distinct meters (Buhur). Analyzing this computationally is hard because:

  1. Orthography vs. Phonetics: What is written isn't what is pronounced (e.g., "Allahu" has a hidden long vowel).
  2. Complexity: A single meter like Kamil has dozens of valid variations (Zihaf) where letters can be dropped or quieted.
  3. LLMs struggle: Asking ChatGPT to scan a poem usually results in hallucinations because it predicts tokens rather than strictly following the prosodic rules.

The Solution: PyArud

I built a deterministic engine that:

* Converts Text: Uses regex and lookaheads to handle deep phonetic rules (like Iltiqa al-Sakinayn - the meeting of two stills).

* Greedy Matching: Implements a greedy algorithm to segment verses into their component feet (Tafilas).

* Deep Analysis: Identifies not just the meter, but the specific defect (Ellah) used in every foot.

Example

from pyarud.processor import ArudhProcessor


# A verse from Al-Mutanabbi
verse = [("أَلا لا أُري الأحْداثَ حَمْدًا وَلا ذَمّا", "فَما بَطْشُها جَهْلًا وَلا كَفُّها حِلْما")]


processor = ArudhProcessor()
result = processor.process_poem(verse)


print(f"Meter: {result['meter']}")  # Output: 'taweel'
print(f"Score: {result['verses'][0]['score']}") # Output: 1.0

Target Audience
Developers building apps for arabic poetry

Comparison:
No alternative solutions exist for this problem

What's new in v0.1.3?

* Robustness: Improved handling of "Solar Lam" and implicit vowels.

* Architecture: A modular pipeline separating linguistic normalization from mathematical pattern matching.

Links

* Repo: https://github.com/cnemri/pyarud

* Docs: https://cnemri.github.io/pyarud

* PyPI: `pip install pyarud`