pyarud 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyarud-0.1.0/.github/workflows/ci.yml +38 -0
- pyarud-0.1.0/.github/workflows/docs.yml +38 -0
- pyarud-0.1.0/.github/workflows/publish.yml +33 -0
- pyarud-0.1.0/.gitignore +60 -0
- pyarud-0.1.0/CONTRIBUTING.md +60 -0
- pyarud-0.1.0/LICENSE +22 -0
- pyarud-0.1.0/PKG-INFO +96 -0
- pyarud-0.1.0/README.md +56 -0
- pyarud-0.1.0/docs/api.md +25 -0
- pyarud-0.1.0/docs/concepts.md +84 -0
- pyarud-0.1.0/docs/cookbook.md +62 -0
- pyarud-0.1.0/docs/index.md +40 -0
- pyarud-0.1.0/docs/installation.md +59 -0
- pyarud-0.1.0/docs/quickstart.md +77 -0
- pyarud-0.1.0/docs/tutorials/debugging.md +48 -0
- pyarud-0.1.0/docs/tutorials/first_analysis.md +76 -0
- pyarud-0.1.0/examples/basic_usage.py +141 -0
- pyarud-0.1.0/mkdocs.yml +53 -0
- pyarud-0.1.0/pyarud/__init__.py +0 -0
- pyarud-0.1.0/pyarud/arudi.py +343 -0
- pyarud-0.1.0/pyarud/bahr.py +561 -0
- pyarud-0.1.0/pyarud/processor.py +329 -0
- pyarud-0.1.0/pyarud/tafeela.py +136 -0
- pyarud-0.1.0/pyarud/zihaf.py +280 -0
- pyarud-0.1.0/pyproject.toml +50 -0
- pyarud-0.1.0/tests/test_meters.py +114 -0
- pyarud-0.1.0/uv.lock +696 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.12"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Install uv
|
|
20
|
+
uses: astral-sh/setup-uv@v3
|
|
21
|
+
with:
|
|
22
|
+
enable-cache: true
|
|
23
|
+
cache-dependency-glob: "uv.lock"
|
|
24
|
+
|
|
25
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
26
|
+
run: uv python install ${{ matrix.python-version }}
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: uv sync --all-extras --dev
|
|
30
|
+
|
|
31
|
+
- name: Lint with Ruff
|
|
32
|
+
run: uv run ruff check .
|
|
33
|
+
|
|
34
|
+
- name: Type check with mypy
|
|
35
|
+
run: uv run mypy .
|
|
36
|
+
|
|
37
|
+
- name: Run tests
|
|
38
|
+
run: uv run pytest
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: Deploy Docs
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: write
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
deploy:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Configure Git Credentials
|
|
17
|
+
run: |
|
|
18
|
+
git config user.name github-actions[bot]
|
|
19
|
+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
|
20
|
+
|
|
21
|
+
- uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: 3.x
|
|
24
|
+
|
|
25
|
+
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
|
|
26
|
+
|
|
27
|
+
- uses: actions/cache@v4
|
|
28
|
+
with:
|
|
29
|
+
key: mkdocs-material-${{ env.cache_id }}
|
|
30
|
+
path: .cache
|
|
31
|
+
restore-keys: |
|
|
32
|
+
mkdocs-material-
|
|
33
|
+
|
|
34
|
+
- name: Install dependencies
|
|
35
|
+
run: pip install ".[docs]"
|
|
36
|
+
|
|
37
|
+
- name: Deploy to GitHub Pages
|
|
38
|
+
run: mkdocs gh-deploy --force
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build-and-publish:
|
|
9
|
+
name: Build and publish to PyPI
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
# IMPORTANT: this permission is mandatory for trusted publishing
|
|
13
|
+
id-token: write
|
|
14
|
+
contents: read
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
|
|
24
|
+
- name: Install build tools
|
|
25
|
+
run: pip install build
|
|
26
|
+
|
|
27
|
+
- name: Build package
|
|
28
|
+
run: python -m build
|
|
29
|
+
|
|
30
|
+
- name: Publish to PyPI
|
|
31
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
32
|
+
with:
|
|
33
|
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
pyarud-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# General
|
|
2
|
+
.DS_Store
|
|
3
|
+
.AppleDouble
|
|
4
|
+
.LSOverride
|
|
5
|
+
|
|
6
|
+
# Python
|
|
7
|
+
__pycache__/
|
|
8
|
+
*.py[cod]
|
|
9
|
+
*$py.class
|
|
10
|
+
*.so
|
|
11
|
+
.Python
|
|
12
|
+
build/
|
|
13
|
+
develop-eggs/
|
|
14
|
+
dist/
|
|
15
|
+
downloads/
|
|
16
|
+
eggs/
|
|
17
|
+
.eggs/
|
|
18
|
+
lib/
|
|
19
|
+
lib64/
|
|
20
|
+
parts/
|
|
21
|
+
sdist/
|
|
22
|
+
var/
|
|
23
|
+
wheels/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# Virtual Environments
|
|
31
|
+
.env
|
|
32
|
+
.venv/
|
|
33
|
+
env/
|
|
34
|
+
venv/
|
|
35
|
+
ENV/
|
|
36
|
+
env.bak/
|
|
37
|
+
venv.bak/
|
|
38
|
+
|
|
39
|
+
# Testing and Quality
|
|
40
|
+
.pytest_cache/
|
|
41
|
+
.ruff_cache/
|
|
42
|
+
.mypy_cache/
|
|
43
|
+
.coverage
|
|
44
|
+
htmlcov/
|
|
45
|
+
.tox/
|
|
46
|
+
.nox/
|
|
47
|
+
|
|
48
|
+
# IDEs and Editors
|
|
49
|
+
.vscode/
|
|
50
|
+
.idea/
|
|
51
|
+
*.swp
|
|
52
|
+
*.swo
|
|
53
|
+
|
|
54
|
+
# Logs
|
|
55
|
+
*.log
|
|
56
|
+
server.log
|
|
57
|
+
|
|
58
|
+
# Local configuration
|
|
59
|
+
.python-version
|
|
60
|
+
site/
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Contributing to Pyarud
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to Pyarud! We welcome contributions from the community to help improve this library for Arabic prosody (Arud) analysis.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
1. **Fork the repository** on GitHub.
|
|
8
|
+
2. **Clone your fork** locally:
|
|
9
|
+
```bash
|
|
10
|
+
git clone https://github.com/cnemri/pyarud.git
|
|
11
|
+
cd pyarud
|
|
12
|
+
```
|
|
13
|
+
3. **Set up a development environment**:
|
|
14
|
+
We recommend using `uv` or `venv`:
|
|
15
|
+
```bash
|
|
16
|
+
# Using uv
|
|
17
|
+
uv sync
|
|
18
|
+
|
|
19
|
+
# Or using standard venv
|
|
20
|
+
python -m venv .venv
|
|
21
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
22
|
+
pip install -e .[dev]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Development Workflow
|
|
26
|
+
|
|
27
|
+
1. **Create a branch** for your feature or bugfix:
|
|
28
|
+
```bash
|
|
29
|
+
git checkout -b feature/my-new-feature
|
|
30
|
+
```
|
|
31
|
+
2. **Make your changes**. Ensure your code follows the project's style.
|
|
32
|
+
3. **Run tests** to ensure you haven't broken anything:
|
|
33
|
+
```bash
|
|
34
|
+
pytest
|
|
35
|
+
```
|
|
36
|
+
4. **Run linting and type checking**:
|
|
37
|
+
```bash
|
|
38
|
+
ruff check .
|
|
39
|
+
mypy .
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Code Style
|
|
43
|
+
|
|
44
|
+
- We use **Ruff** for linting and formatting.
|
|
45
|
+
- We use **Mypy** for static type checking.
|
|
46
|
+
- Please add type hints to new functions and classes.
|
|
47
|
+
- Follow PEP 8 guidelines (Ruff will help you with this).
|
|
48
|
+
|
|
49
|
+
## Pull Requests
|
|
50
|
+
|
|
51
|
+
1. Push your branch to your fork.
|
|
52
|
+
2. Open a Pull Request (PR) against the `main` branch.
|
|
53
|
+
3. Describe your changes clearly in the PR description.
|
|
54
|
+
4. Ensure all tests and checks pass.
|
|
55
|
+
|
|
56
|
+
## Reporting Issues
|
|
57
|
+
|
|
58
|
+
If you find a bug or have a feature request, please open an issue on the GitHub repository with details about the problem or suggestion.
|
|
59
|
+
|
|
60
|
+
Thank you for contributing!
|
pyarud-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Maged Saeed
|
|
4
|
+
Copyright (c) 2025 Chouaieb Nemri
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
pyarud-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyarud
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python library for Arabic prosody (Arud) analysis.
|
|
5
|
+
Author-email: Chouaieb Nemri <chouaib.nemri@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2022 Maged Saeed
|
|
9
|
+
Copyright (c) 2025 Chouaieb Nemri
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Python: >=3.12
|
|
30
|
+
Requires-Dist: pyarabic>=0.6.15
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: mypy>=1.9.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: ruff>=0.3.0; extra == 'dev'
|
|
35
|
+
Provides-Extra: docs
|
|
36
|
+
Requires-Dist: mkdocs-material>=9.5.0; extra == 'docs'
|
|
37
|
+
Requires-Dist: mkdocs>=1.5.0; extra == 'docs'
|
|
38
|
+
Requires-Dist: mkdocstrings[python]>=0.24.0; extra == 'docs'
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
|
|
41
|
+
# PyArud (بيعروض)
|
|
42
|
+
|
|
43
|
+
**PyArud** is a robust Python library for Arabic prosody (Arud) analysis. It detects poetic meters (Buhur), analyzes verses foot-by-foot, and identifies variations (Zihaf) and defects (Ellah) with granular precision.
|
|
44
|
+
|
|
45
|
+
[](https://pypi.org/project/pyarud/)
|
|
46
|
+
[](https://cnemri.github.io/pyarud/)
|
|
47
|
+
[](LICENSE)
|
|
48
|
+
|
|
49
|
+
## 📚 Documentation
|
|
50
|
+
|
|
51
|
+
Full documentation is available at **[cnemri.github.io/pyarud](https://cnemri.github.io/pyarud/)**.
|
|
52
|
+
|
|
53
|
+
## ✨ Features
|
|
54
|
+
|
|
55
|
+
- **Smart Meter Detection**: Automatically identifies the 16 standard meters.
|
|
56
|
+
- **Granular Analysis**: Detailed breakdown of each foot (Tafeela) with status codes (`ok`, `broken`, `missing`, `extra_bits`).
|
|
57
|
+
- **Arudi Conversion**: Built-in text processing to handle Arabic diacritics and phonetic writing.
|
|
58
|
+
- **Robust**: Handles common poetic variations (Zihaf) and obligatory endings (Ellah).
|
|
59
|
+
|
|
60
|
+
## 🚀 Installation
|
|
61
|
+
|
|
62
|
+
Requires Python 3.12+.
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install pyarud
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## ⚡ Quick Start
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from pyarud.processor import ArudhProcessor
|
|
72
|
+
|
|
73
|
+
# Initialize the processor
|
|
74
|
+
processor = ArudhProcessor()
|
|
75
|
+
|
|
76
|
+
# Define a verse (Sadr, Ajuz)
|
|
77
|
+
verse = ("أَخِي جَاوَزَ الظَّالِمُونَ الْمَدَى", "فَحَقَّ الْجِهَادُ وَحَقَّ الْفِدَا")
|
|
78
|
+
|
|
79
|
+
# Process the poem
|
|
80
|
+
result = processor.process_poem([verse])
|
|
81
|
+
|
|
82
|
+
print(f"Detected Meter: {result['meter']}")
|
|
83
|
+
# Output: mutakareb
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## 🛠️ Advanced Usage
|
|
87
|
+
|
|
88
|
+
For detailed tutorials, debugging guides, and API reference, please visit the [Documentation](https://cnemri.github.io/pyarud/).
|
|
89
|
+
|
|
90
|
+
## 🤝 Contributing
|
|
91
|
+
|
|
92
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
93
|
+
|
|
94
|
+
## 📄 License
|
|
95
|
+
|
|
96
|
+
This project is licensed under the [MIT License](LICENSE).
|
pyarud-0.1.0/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# PyArud (بيعروض)
|
|
2
|
+
|
|
3
|
+
**PyArud** is a robust Python library for Arabic prosody (Arud) analysis. It detects poetic meters (Buhur), analyzes verses foot-by-foot, and identifies variations (Zihaf) and defects (Ellah) with granular precision.
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/pyarud/)
|
|
6
|
+
[](https://cnemri.github.io/pyarud/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
## 📚 Documentation
|
|
10
|
+
|
|
11
|
+
Full documentation is available at **[cnemri.github.io/pyarud](https://cnemri.github.io/pyarud/)**.
|
|
12
|
+
|
|
13
|
+
## ✨ Features
|
|
14
|
+
|
|
15
|
+
- **Smart Meter Detection**: Automatically identifies the 16 standard meters.
|
|
16
|
+
- **Granular Analysis**: Detailed breakdown of each foot (Tafeela) with status codes (`ok`, `broken`, `missing`, `extra_bits`).
|
|
17
|
+
- **Arudi Conversion**: Built-in text processing to handle Arabic diacritics and phonetic writing.
|
|
18
|
+
- **Robust**: Handles common poetic variations (Zihaf) and obligatory endings (Ellah).
|
|
19
|
+
|
|
20
|
+
## 🚀 Installation
|
|
21
|
+
|
|
22
|
+
Requires Python 3.12+.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install pyarud
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## ⚡ Quick Start
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from pyarud.processor import ArudhProcessor
|
|
32
|
+
|
|
33
|
+
# Initialize the processor
|
|
34
|
+
processor = ArudhProcessor()
|
|
35
|
+
|
|
36
|
+
# Define a verse (Sadr, Ajuz)
|
|
37
|
+
verse = ("أَخِي جَاوَزَ الظَّالِمُونَ الْمَدَى", "فَحَقَّ الْجِهَادُ وَحَقَّ الْفِدَا")
|
|
38
|
+
|
|
39
|
+
# Process the poem
|
|
40
|
+
result = processor.process_poem([verse])
|
|
41
|
+
|
|
42
|
+
print(f"Detected Meter: {result['meter']}")
|
|
43
|
+
# Output: mutakareb
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 🛠️ Advanced Usage
|
|
47
|
+
|
|
48
|
+
For detailed tutorials, debugging guides, and API reference, please visit the [Documentation](https://cnemri.github.io/pyarud/).
|
|
49
|
+
|
|
50
|
+
## 🤝 Contributing
|
|
51
|
+
|
|
52
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
53
|
+
|
|
54
|
+
## 📄 License
|
|
55
|
+
|
|
56
|
+
This project is licensed under the [MIT License](LICENSE).
|
pyarud-0.1.0/docs/api.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
This reference is automatically generated from the source code docstrings.
|
|
4
|
+
|
|
5
|
+
## Arudh Processor
|
|
6
|
+
|
|
7
|
+
::: pyarud.processor.ArudhProcessor
|
|
8
|
+
options:
|
|
9
|
+
members:
|
|
10
|
+
- process_poem
|
|
11
|
+
|
|
12
|
+
## Bahr (Meters)
|
|
13
|
+
|
|
14
|
+
::: pyarud.bahr.Bahr
|
|
15
|
+
options:
|
|
16
|
+
members:
|
|
17
|
+
- detailed_patterns
|
|
18
|
+
- get_allowed_feet_patterns
|
|
19
|
+
|
|
20
|
+
## Arudi Converter
|
|
21
|
+
|
|
22
|
+
::: pyarud.arudi.ArudiConverter
|
|
23
|
+
options:
|
|
24
|
+
members:
|
|
25
|
+
- prepare_text
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Core Concepts
|
|
2
|
+
|
|
3
|
+
Understanding how PyArud (بيعروض) analyzes poetry requires familiarity with a few key concepts from Arabic prosody (Arud).
|
|
4
|
+
|
|
5
|
+
## 1. The Arudi Pattern
|
|
6
|
+
|
|
7
|
+
At its core, Arud is binary. Every letter in a spoken poem is either:
|
|
8
|
+
- **Mutaharrik (Moved)**: Has a vowel (Fatha, Damma, Kasra). Represented as `1`.
|
|
9
|
+
- **Sakin (Still)**: Has a Sukun or is a long vowel (Alif, Waw, Ya). Represented as `0`.
|
|
10
|
+
|
|
11
|
+
PyArud converts your text into this binary string.
|
|
12
|
+
**Example:**
|
|
13
|
+
`فَعُولُنْ` (Fa-u-lun) -> `11010`
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 2. Meters (Buhur)
|
|
18
|
+
|
|
19
|
+
Arabic poetry is classified into 16 standard meters (Buhur), each defined by a specific rhythm of feet (Tafila).
|
|
20
|
+
|
|
21
|
+
Below is the list of meters supported by PyArud, along with their standard mnemonic (Meftah) and feet.
|
|
22
|
+
|
|
23
|
+
| Meter (Bahr) | Mnemonic (Meftah) | Standard Feet |
|
|
24
|
+
| :--- | :--- | :--- |
|
|
25
|
+
| **Tawil** | طَوِيلٌ لَهُ دُونَ الْبُحُورِ فَضَائِلُ | `Fa'ulun Mafa'ilun Fa'ulun Mafa'ilun` |
|
|
26
|
+
| **Madid** | لِمَدِيدِ الشِّعْرِ عِنْدِي صِفَاتُ | `Fa'ilatun Fa'ilun Fa'ilatun` |
|
|
27
|
+
| **Basit** | إِنَّ الْبَسِيطَ لَدَيْهِ يُبْسَطُ الْأَمَلُ | `Mustaf'ilun Fa'ilun Mustaf'ilun Fa'ilun` |
|
|
28
|
+
| **Wafir** | بُحُورُ الشِّعْرِ وَافِرُهَا جَمِيلُ | `Mufa'alatun Mufa'alatun Fa'ulun` |
|
|
29
|
+
| **Kamil** | كَمُلَ الْجَمَالُ مِنَ الْبُحُورِ الْكَامِلُ | `Mutafa'ilun Mutafa'ilun Mutafa'ilun` |
|
|
30
|
+
| **Hazaj** | عَلَى الْأَهْزَاجِ تَسْهِيلُ | `Mafa'ilun Mafa'ilun` |
|
|
31
|
+
| **Rajaz** | فِي أَبْحُرِ الْأَرْجَازِ بَحْرٌ يَسْهُلُ | `Mustaf'ilun Mustaf'ilun Mustaf'ilun` |
|
|
32
|
+
| **Ramal** | رَمَلُ الْأَبْحُرِ يَرْوِيهِ الثِّقَاتُ | `Fa'ilatun Fa'ilatun Fa'ilatun` |
|
|
33
|
+
| **Saree** | بَحْرٌ سَرِيعٌ مَا لَهُ سَاحِلُ | `Mustaf'ilun Mustaf'ilun Fa'ilun` |
|
|
34
|
+
| **Munsarih** | مُنْسَرِحٌ فِيهِ يُضْرَبُ الْمَثَلُ | `Mustaf'ilun Maf'ulatu Mufta'ilun` |
|
|
35
|
+
| **Khafif** | يَا خَفِيفاً خَفَّتْ بِهِ الْحَرَكَاتُ | `Fa'ilatun Mustaf'ilun Fa'ilatun` |
|
|
36
|
+
| **Mudhari** | تَعَدَّ مَعَ الْعَوَاقِلْ | `Mafa'ilun Fa'ilatun` |
|
|
37
|
+
| **Muqtadhib** | اقْتَضِبْ كَمَا سَأَلُوا | `Maf'ulatu Mufta'ilun` |
|
|
38
|
+
| **Mujtath** | إِنْ جُثَّتِ الْحَرَكَاتُ | `Mustaf'ilun Fa'ilatun` |
|
|
39
|
+
| **Mutakarib** | عَنِ الْمُتَقَارِبِ قَالَ الْخَلِيلُ | `Fa'ulun Fa'ulun Fa'ulun Fa'ulun` |
|
|
40
|
+
| **Mutadarak** | حَرَكَاتُ الْمُحْدَثِ تَنْتَقِلُ | `Fa'ilun Fa'ilun Fa'ilun Fa'ilun` |
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 3. Variations (Zihaf & Ellah)
|
|
45
|
+
|
|
46
|
+
Poets often deviate from the standard pattern. These deviations are strictly categorized.
|
|
47
|
+
|
|
48
|
+
### Zihaf (Relaxation)
|
|
49
|
+
Changes that occur in the "Hashw" (internal feet) of the verse. They are usually optional and do not have to be consistent throughout the poem.
|
|
50
|
+
|
|
51
|
+
| Name | Description | Example |
|
|
52
|
+
| :--- | :--- | :--- |
|
|
53
|
+
| **Khaban** | Deletion of the 2nd letter. | `Mustaf'ilun` -> `Mutaf'ilun` |
|
|
54
|
+
| **Tay** | Deletion of the 4th letter. | `Mustaf'ilun` -> `Musta'ilun` |
|
|
55
|
+
| **Qabadh** | Deletion of the 5th letter. | `Fa'ulun` -> `Fa'ulu` |
|
|
56
|
+
| **Kaff** | Deletion of the 7th letter. | `Fa'ilatun` -> `Fa'ilatu` |
|
|
57
|
+
| **Idmar** | Quieting the 2nd moved letter. | `Mutafa'ilun` -> `Mutfa'ilun` (becomes `Mustaf'ilun`) |
|
|
58
|
+
| **Asab** | Quieting the 5th moved letter. | `Mufa'alatun` -> `Mufa'altun` |
|
|
59
|
+
|
|
60
|
+
### Ellah (Defect/Cause)
|
|
61
|
+
Changes that usually occur in the "Arudh" (end of first hemistich) or "Dharb" (end of second hemistich). Once applied, they often must be consistent throughout the poem.
|
|
62
|
+
|
|
63
|
+
| Name | Description |
|
|
64
|
+
| :--- | :--- |
|
|
65
|
+
| **Hadhf** | Removal of the last light syllable (Sabab Khafif). |
|
|
66
|
+
| **Qataa** | Cutting the end of a Watad Majmu' and quieting the previous letter. |
|
|
67
|
+
| **Batr** | A combination of Hadhf and Qataa (severe reduction). |
|
|
68
|
+
| **Tatheel** | Adding a letter to the end (increasing length). |
|
|
69
|
+
| **Tarfeel** | Adding a syllable to the end. |
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## 4. Pattern Matching Strategy
|
|
74
|
+
|
|
75
|
+
PyArud uses a **Greedy Matching** strategy to analyze verses.
|
|
76
|
+
|
|
77
|
+
1. **Identification**: It first detects the meter that best fits the overall line.
|
|
78
|
+
2. **Segmentation**: It tries to map the binary string of your verse to the valid feet of that meter.
|
|
79
|
+
3. **Optimization**: If a perfect match isn't found, it looks for the longest valid foot (standard or modified by Zihaf) that matches the current position.
|
|
80
|
+
4. **Error Reporting**:
|
|
81
|
+
* If it finds text that matches a foot, it marks it `ok`.
|
|
82
|
+
* If it finds text but it doesn't match any valid variation, it marks it `broken`.
|
|
83
|
+
* If the verse ends prematurely, it marks the remaining feet as `missing`.
|
|
84
|
+
* If there are leftover syllables after the verse is complete, it marks them as `extra_bits`.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Cookbook: Common Recipes
|
|
2
|
+
|
|
3
|
+
This section contains code snippets for common tasks.
|
|
4
|
+
|
|
5
|
+
## 1. Analyzing a Text File of Poems
|
|
6
|
+
|
|
7
|
+
If you have a file `poems.txt` where each line is `Sadr | Ajuz`:
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from pyarud.processor import ArudhProcessor
|
|
11
|
+
|
|
12
|
+
processor = ArudhProcessor()
|
|
13
|
+
verses = []
|
|
14
|
+
|
|
15
|
+
with open("poems.txt", "r", encoding="utf-8") as f:
|
|
16
|
+
for line in f:
|
|
17
|
+
if "|" in line:
|
|
18
|
+
parts = line.split("|")
|
|
19
|
+
verses.append((parts[0].strip(), parts[1].strip()))
|
|
20
|
+
|
|
21
|
+
result = processor.process_poem(verses)
|
|
22
|
+
print(f"Detected Meter for file: {result['meter']}")
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 2. Filtering by Meter
|
|
26
|
+
|
|
27
|
+
How to find only lines that match the "Wafir" meter from a list.
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
all_verses = [...] # Large list of verses
|
|
31
|
+
wafir_verses = []
|
|
32
|
+
|
|
33
|
+
for s, a in all_verses:
|
|
34
|
+
res = processor.process_poem([(s, a)])
|
|
35
|
+
if res['meter'] == 'wafer':
|
|
36
|
+
wafir_verses.append((s, a))
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 3. Getting Raw Binary Patterns
|
|
40
|
+
|
|
41
|
+
Sometimes you just want the `10110` string for your own machine learning model or analysis.
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from pyarud.arudi import ArudiConverter
|
|
45
|
+
|
|
46
|
+
converter = ArudiConverter()
|
|
47
|
+
text = "مُسْتَفْعِلُنْ"
|
|
48
|
+
_, pattern = converter.prepare_text(text)
|
|
49
|
+
print(pattern) # 1010110
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 4. Handling Single-Hemistich Lines (Mashtoor)
|
|
53
|
+
|
|
54
|
+
Some poems or educational texts only have one hemistich.
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
# Pass an empty string for the Ajuz
|
|
58
|
+
result = processor.process_poem([("شَطْرٌ وَاحِدٌ فَقَطْ", "")])
|
|
59
|
+
|
|
60
|
+
# The result will contain analysis for Sadr, and Ajuz will be None/Empty
|
|
61
|
+
print(result['verses'][0]['ajuz_analysis']) # None
|
|
62
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Welcome to PyArud (بيعروض)
|
|
2
|
+
|
|
3
|
+
**PyArud** is a robust Python library for Arabic prosody (Arud) analysis. It detects poetic meters, analyzes verses foot-by-foot, and identifies variations (Zihaf) and defects (Ellah).
|
|
4
|
+
|
|
5
|
+
## Why PyArud?
|
|
6
|
+
|
|
7
|
+
Arabic prosody is complex. A single meter can have dozens of valid variations (Zihaf) and obligatory endings (Ellah). Most tools give a simple "Pass/Fail" or struggle with common variations.
|
|
8
|
+
|
|
9
|
+
**PyArud is designed for precision:**
|
|
10
|
+
- **It doesn't just guess:** It uses a deterministic, exhaustive map of valid meter variations.
|
|
11
|
+
- **It explains itself:** Instead of just saying "Invalid", it tells you *exactly* which foot broke the rhythm.
|
|
12
|
+
- **It handles the edge cases:** From *Idmar* in Kamil to *Batr* in Mutakarib, the library supports deep prosodic rules.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **Smart Meter Detection**: Automatically identifies the 16 Khalil meters (Buhur), differentiating between similar rhythms (e.g., Rajaz vs. Kamil).
|
|
17
|
+
- **Granular Analysis**: Breaks down every verse into its component feet (Tafila), validating each one individually.
|
|
18
|
+
- **Defect Diagnosis**: Explicitly flags:
|
|
19
|
+
- `broken`: Text that violates the meter.
|
|
20
|
+
- `missing`: Feet that are absent from the line.
|
|
21
|
+
- `extra_bits`: Syllables that overflow the meter.
|
|
22
|
+
- **Arudi Conversion**: Built-in text processing to handle Arabic diacritics, silent letters (e.g., Solar Lam), and phonetic pronunciation.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install pyarud
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from pyarud.processor import ArudhProcessor
|
|
34
|
+
|
|
35
|
+
processor = ArudhProcessor()
|
|
36
|
+
verse = [("أَخِي جَاوَزَ الظَّالِمُونَ الْمَدَى", "فَحَقَّ الْجِهَادُ وَحَقَّ الْفِدَا")]
|
|
37
|
+
|
|
38
|
+
result = processor.process_poem(verse)
|
|
39
|
+
print(f"Detected Meter: {result['meter']}")
|
|
40
|
+
```
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Installation Guide
|
|
2
|
+
|
|
3
|
+
## Prerequisites
|
|
4
|
+
|
|
5
|
+
PyArud requires **Python 3.12** or newer.
|
|
6
|
+
|
|
7
|
+
## Standard Installation
|
|
8
|
+
|
|
9
|
+
You can install PyArud directly from PyPI using pip:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install pyarud
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Development Setup
|
|
16
|
+
|
|
17
|
+
If you want to contribute to PyArud or run the tests locally, follow these steps.
|
|
18
|
+
|
|
19
|
+
### Using standard venv
|
|
20
|
+
|
|
21
|
+
1. **Clone the repository:**
|
|
22
|
+
```bash
|
|
23
|
+
git clone https://github.com/yourusername/pyarud.git
|
|
24
|
+
cd pyarud
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
2. **Create a virtual environment:**
|
|
28
|
+
```bash
|
|
29
|
+
python3.12 -m venv .venv
|
|
30
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
3. **Install in editable mode with dev dependencies:**
|
|
34
|
+
```bash
|
|
35
|
+
pip install -e ".[dev,docs]"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Using uv (Recommended)
|
|
39
|
+
|
|
40
|
+
If you use [uv](https://github.com/astral-sh/uv), it handles Python versions and virtual environments automatically.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
uv venv
|
|
44
|
+
source .venv/bin/activate
|
|
45
|
+
uv pip install -e ".[dev,docs]"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Verifying Installation
|
|
49
|
+
|
|
50
|
+
To verify that PyArud is installed correctly, run this simple one-liner in your terminal:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
python -c "from pyarud.processor import ArudhProcessor; print(ArudhProcessor().process_poem([('أَخِي جَاوَزَ الظَّالِمُونَ الْمَدَى', '')])['meter'])"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
It should output:
|
|
57
|
+
```text
|
|
58
|
+
mutakareb
|
|
59
|
+
```
|