GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - cnemri/pyarud: Arabic Arud (prosody) toolkit for Python. Features meter detection, tafeela analysis, and support for all 16 poetic meters with strict type safety.

BranchesTags
Open more actions menu

Latest commit

 

History

22 Commits
22 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
docs
docs
 
 
examples
examples
 
 
pyarud
pyarud
 
 
skills/arud
skills/arud
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
mkdocs.yml
mkdocs.yml
 
 
pyproject.toml
pyproject.toml
 
 
uv.lock
uv.lock
 
 

Repository files navigation

PyArud (پَايْعَرُوضْ)

PyArud is a deterministic, high-performance, zero-dependency Python engine for Classical & Modern Arabic Prosody (علم العروض والقافية). It delivers formal Farahidian grammar scansion across all 16 classical meters (البحور الستة عشر) and their authentic sub-meters (التام، المجزوء، المشطور، المنهوك، المخلّع), opt-in support for the 6 neglected Farahidian circle meters (البحور المهملة), an extensible API for custom user-defined & modern free-verse (التفعيلة) meters, foot-by-foot Zihaf & 'Ilal diagnosis, and complete rhyme (القافية) & rhyme-fault (عيوب القافية) analysis.

PyPI License Python 3.12+ Zero Dependencies


✨ Features

  • 🚀 Zero Runtime Dependencies: 100% pure Python 3.12+ standard library. No pyarabic or heavy C extensions.
  • ⚡ High Throughput:
    • Phonetic Arudi Alignment (1:1 letter-to-bit bijection): ~10,000 hemistichs/second
    • Full Deterministic Multi-Meter Verse Scansion: >2,200 verses/second
  • 🎼 Full 16-Meter Farahidian Coverage + Opt-In Muhmal Pack: All 16 classical meters (29 authentic forms across Tam, Majzoo, Mashtoor, Manhook, Mukhalla'), enforcing المراقبة (Muraqabah), المعاقبة (Mu'aqabah), الاعتماد (I'timad), and التصريع (Tasri'), plus an opt-in pack (include_muhmal=True) for the 6 neglected circle meters (المستطيل، الممتد، المتوفر، المتئد، المنسرد، المطرد).
  • 🧩 Custom User-Defined & Free-Verse Meters: Declarative, immutable MeterSpec, TafeelaSpec, ProsodicRule, fluent MeterBuilder, JSON/TOML loading, and persistent non-mutating MeterRegistry for modern التفعيلة free verse, asymmetric Andalusian الموشحات, and personal meters.
  • 🔬 Granular Slot-Viterbi Foot Scansion: Exact per-foot status (ok, broken, missing, extra_bits), real surface Arabic foot forms (actual_tafeela vs base_tafeela), per-foot Arudi text slices (foot.arudi_text), and exact Arabic & English Zihaf/'Ilal diagnosis.
  • 📜 Complete Qafiyah & Rhyme-Fault Analysis: Identifies Rawi (الروي), Wasl (الوصل), Khuruj (الخروج), Ridf (الردف), Ta'sees (التأسيس), Dakhil (الدخيل), all 6 classical movements (المجرى، النفاذ، الحذو، الإشباع، الرس، التوجيه), rhythmic & structural types, opening-verse Tasri', and poem-level rhyme faults (الإقواء، الإصراف، الإكفاء، الإجازة، السناد، الإيطاء).
  • 🎨 Bilingual Formatters, CLI & Agent Skill: format_verse_report / format_poem_report (ar/en, pretty/compact/markdown), zero-dep pyarud / arud CLI, .to_dict() / .to_json(), plus a bundled AI Agent Skill at skills/arud/SKILL.md.
  • 🛡️ Strict Typing (PEP 561): Verified with mypy --strict across the entire package.

🚀 Installation

Requires Python 3.12+.

pip install pyarud

Or with uv:

uv add pyarud

⚡ Quick Start

from pyarud import ArudProcessor, format_verse_report

processor = ArudProcessor()

# 1. Analyze a classical verse (Sadr & Ajuz)
verse = ("أَخِي جَاوَزَ الظَّالِمُونَ الْمَدَى", "فَحَقَّ الْجِهَادُ وَحَقَّ الْفِدَا")
analysis = processor.analyze_verse(*verse)

print(f"Meter: {analysis.meter_name_ar} ({analysis.meter_key}, {analysis.bahr_type})")
print(f"Score: {analysis.score:.2%} | Valid: {analysis.is_valid} | Tasri': {analysis.is_tasri}")

# Foot-by-foot breakdown with Arudi slices
if analysis.sadr:
    print(f"Sadr Arudi: {analysis.sadr.arudi_text}  [{analysis.sadr.pattern}]")
    for foot in analysis.sadr.feet:
        print(
            f"  [{foot.status.upper()}] {foot.actual_tafeela} ({foot.actual_segment}) "
            f"«{foot.arudi_text}» — {foot.zihaf_name_ar}"
        )

# Rhyme (Qafiyah)
if analysis.qafiyah:
    print(f"Rawi: {analysis.qafiyah.rawi} | Type: {analysis.qafiyah.qafiyah_type_ar}")

# Rich terminal or Markdown report (Arabic or English)
print(format_verse_report(analysis, lang="ar", style="pretty"))

Analyzing Complete Poems & Rhyme Faults

from pyarud import ArudProcessor

processor = ArudProcessor()
verses = [
    ("قِفَا نَبْكِ مِنْ ذِكْرَى حَبِيبٍ وَمَنْزِلِ", "بِسِقْطِ اللِّوَى بَيْنَ الدَّخُولِ فَحَوْمَلِ"),
    ("فَتُوضِحَ فَالْمِقْرَاةِ لَمْ يَعْفُ رَسْمُهَا", "لِمَا نَسَجَتْهَا مِنْ جَنُوبٍ وَشَمْأَلِ"),
]

poem = processor.analyze_poem(verses)
print(f"Global Meter: {poem.meter_name_ar} ({poem.bahr_type})")
print(f"Homogeneous: {poem.is_homogeneous} | Tasri': {poem.has_tasri}")
print(f"Dominant Rawi: {poem.dominant_rawi} | Rhyme Faults: {len(poem.rhyme_faults)}")
print(f"Average Confidence: {poem.average_score:.2%}")

Custom User-Defined & Free-Verse Meters

from pyarud import ArudProcessor, MeterSpec
from pyarud.meters.specs import EDMAAR, HATHATH, MUTAFAELON, QATAA, SALIM

# 1. Opt-in 6 neglected Farahidian meters (البحور المهملة)
muhmal_proc = ArudProcessor(include_muhmal=True)
res = muhmal_proc.analyze_verse(
    "لَقَدْ هَاجَ اشْتِيَاقِي غَزَالٌ فِي المَرَاعِي",
    "أَمِيرُ الحُسْنِ يَزْهُو عَلَى كُلِّ البِقَاعِ",
)
print(res.meter_name_ar, res.meter_key, res.is_valid)  # بحر المستطيل mustateel True

# 2. Modern Arabic free-verse (شعر التفعيلة) with variable foot count
free_kamel = MeterSpec.free_verse(
    key="tafeela_kamel",
    name_ar="تفعيلة الكامل",
    name_en="Free-Verse Kamel",
    foot=MUTAFAELON,
    min_feet=1,
    max_feet=8,
    ending_rules=(SALIM, EDMAAR, QATAA, HATHATH),
)
free_proc = ArudProcessor().with_meters(free_kamel, prefer_custom=True)
line = free_proc.analyze_verse("مُتَفَاعِلُنْ مُتَفَاعِلُنْ مُتَفَاعِلُنْ مُتَفَاعِلُنْ مُتَفَاعِلُنْ")
print(line.meter_name_ar, len(line.sadr.feet) if line.sadr else 0, line.is_valid)

💻 Command-Line Interface (pyarud / arud)

PyArud includes a zero-dependency CLI (pyarud, arud, or python -m pyarud) with UTF-8 JSON stdout, stderr error reporting, and CI-friendly --strict exit codes (0 valid, 1 broken/rhyme fault, 2 error):

# Scan a classical verse (pretty, compact, markdown, or json)
pyarud scan "قِفَا نَبْكِ مِنْ ذِكْرَى حَبِيبٍ وَمَنْزِلِ ... بِسِقْطِ اللِّوَى بَيْنَ الدَّخُولِ فَحَوْمَلِ" --format json --strict

# Phonetic Kitabah 'Arudiyyah & classical //0 scansion
pyarud arudi "أَخِي جَاوَزَ الظَّالِمُونَ الْمَدَى" --notation classical

# Rhyme (Qafiyah) & poem-level rhyme-fault analysis
pyarud qafiyah -f poem.txt --format json

# Inspect meters (with opt-in Muhmal or custom TOML/JSON) & zihafs
pyarud meters --show taweel
pyarud zihafs --tafeela "فَعُولُنْ"

# Step-by-step pedagogical explanation
pyarud explain "أَخِي جَاوَزَ الظَّالِمُونَ الْمَدَى ... فَحَقَّ الْجِهَادُ وَحَقَّ الْفِدَا" --lang en

🤖 Arud AI Agent Skill (skills/arud/)

LLMs struggle with deterministic Arabic syllable counting and Kitabah 'Arudiyyah natively. This repository ships an open-standard Arud Agent Skill at skills/arud/SKILL.md (with concise prosody, phonetics/Qafiyah, and custom-meter reference sheets under skills/arud/references/) that pairs any coding/writing agent with the pyarud CLI for a verified Compose → Diacritize → Scan (--strict --format json) → Repair loop.

Installable directly from this repo with Agent Skills tooling (excluded from the PyPI wheel to keep runtime packaging lean).


📊 Benchmarks & Test Coverage

Verified across 234 unit, classical, custom-meter, Qafiyah, CLI, Agent Skill, and real-world benchmark tests (including 27 curated classical meter/sub-meter entries and 80 real diacritized poems from Al-Diwan across all 16 meters):

Metric Result
Full Test Suite 234 / 234 passed (~1.2s)
Classical & Unseen Meter Benchmarks 100.0% (27/27 curated + 80/80 unseen)
Arudi ↔ Binary 1:1 Alignment Invariant 100.0% (0 mismatches)
Phonetic Conversion Throughput ~10,000 hemistichs / sec
Full Verse Scansion Throughput >2,200 verses / sec
External Runtime Dependencies 0 (Zero)

🛠️ Testing & Development

git clone https://github.com/cnemri/pyarud.git
cd pyarud

# Install dev dependencies (PEP 735 dependency-groups)
uv sync --group dev

# Run complete test suite
uv run pytest

# Lint & strict type check
uv run ruff check .
uv run mypy .

📄 Changelog & License

See CHANGELOG.md for full release notes (latest: v2.0.0).

This project is licensed under the MIT License.

About

Arabic Arud (prosody) toolkit for Python. Features meter detection, tafeela analysis, and support for all 16 poetic meters with strict type safety.

github.com/cnemri/pyarud

Resources

Readme
MIT license

Contributing

Contributing
Activity

Stars

57 stars

Watchers

0 watching

Forks

12 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.