# AraNorm

> Production-grade, dependency-free Arabic text normalization for Python: orthographic unification, dialect handling, Arabizi conversion, stop words, a 110-name analysis toolkit (45+ analyzers), built-in lemmatization and stemming with optional dictionary backends (Alma/SinaTools Qabas, CAMeL Tools, Farasa, Tashaphyne, ARLSTem), CLI, and an optional HTTP server — one import, `process()`, done.

AraNorm (`pip install aranorm`, `import aranorm`) replaces the usual pile of incompatible Arabic tools with a single typed, tested library. It normalizes MSA and dialectal Arabic, converts Arabizi (Franco-Arabic) to Arabic script, identifies dialects (EGY/GLF/LEV/IRQ/NOR/TUN/YEM/MSA), converts them to CODA or MSA, removes or extracts stop words with per-dialect attribution, and ships a 110-name `aranorm.analysis` toolkit — 34 analyzer engines + 19 one-shot `analyze_*` functions covering sentiment, emotion, readability, quality, keywords, similarity, corpus profiling and classical rhetoric (jinās, sajʿ, ṭibāq, anaphora) — plus built-in **lemmatization** (`lemmatize("يكتبون") → "كتب"`) and **stemming** (`stem_word("المدارس") → "مدارس"`) with optional dictionary backends (Alma via SinaTools/Qabas, CAMeL Tools MLE, Farasa, Tashaphyne, ARLSTem/ARLSTem2), 47 CLI subcommands and a streaming/checkpointed batch engine. Zero required dependencies (Python >= 3.9), MIT license, deterministic output, 2300+ tests.

Quick start (verified):

```python
# pip install aranorm
import aranorm

pipeline = aranorm.ArabicNormalizationPipeline.from_preset("standard")
result = pipeline.process("الســـلامُ عليكم كيف حالكم اليوم؟")
result.normalized_text   # 'السلام عليكم كيف حالكم اليوم?'

# Dialect → MSA rewrite
cfg = aranorm.PipelineConfig.from_preset("standard", dialect_target="msa")
r = aranorm.ArabicNormalizationPipeline(cfg).process("شلونك اليوم؟ وين رايح")
r.dialect        # 'GLF'
r.msa_text      # 'كيف حالك اليوم? أين ذاهب'

# Lemmatization & stemming (zero dependencies, verified)
aranorm.lemmatize("يكتبون")          # 'كتب'
aranorm.stem_word("المدارس")         # 'مدارس'
aranorm.lemmatize("يقول")            # 'قال' (suppletive table)
```

Presets: `light` (minimal touch), `standard` (default), `deep` (search indexing), `social_media` (URLs/mentions/emojis/repetition). CLI: `aranorm normalize|stopwords|analyze|dialect|batch|serve|...` (47 subcommands; `aranorm version` is a subcommand). Server: `aranorm serve` then `POST /v1/normalize`.

Docs are bilingual: English in `docs/`, full Arabic mirror in `docs/ar/`. A flattened single-file version of this documentation is at [llms-full.txt](llms-full.txt).

## Getting started

- [Quick start](docs/getting-started.md): install, first pipeline, presets, result fields, batch basics
- [Configuration](docs/configuration.md): every `PipelineConfig` field, preset tables, validation, serialization
- [Examples](docs/examples.md): 20 runnable examples in `examples/`
- [Cookbook](docs/cookbook.md): 101 verified recipes for real-world scenarios
- [FAQ](docs/faq.md): common questions, both languages

## Core references

- [API reference](docs/api.md): all 90 top-level public exports plus the complete 110-name `aranorm.analysis` namespace, verified signatures and outputs
- [Processors reference](docs/processors-reference.md): every processor class — options, verified examples, edge cases, ordering rules
- [Processors & presets](docs/processors.md): the processor catalogue grouped by stage
- [Analysis toolkit](docs/analysis.md): 45+ analyzers — sentiment, quality, readability, keywords, comparison, corpus, rhetoric; every analyzer class + result dataclass + one-shot `analyze_*` function importable from `aranorm.analysis` directly; every result has `to_dict()` + `to_json()`
- [Lemmatization & stemming](docs/lemmatization-stemming.md): `aranorm.lemmatization` / `aranorm.stemming` — built-in zero-dep lemma+stem, optional Alma/SinaTools (Qabas), CAMeL Tools, Farasa, Tashaphyne, ARLSTem/ARLSTem2 backends; CLI `aranorm lemmatize` / `aranorm stem`; every documented output executed
- [Utilities toolbox](docs/utils.md): `aranorm.utils` — tokenization, stemming/roots, language detection, quick helpers, stats, chunking for LLM/RAG, n-grams, fuzzy matching, keyboard-layout repair, cache, exporters, progress, validation
- [Error handling](docs/error-handling.md): every exception in the hierarchy with its real message, the three batch policies (default fail_fast), recovery patterns, CLI exit codes, HTTP error envelopes, anti-patterns — all execution-verified
- [CLI reference](docs/cli.md): all 47 subcommands, options, JSON output, error messages
- [Architecture](docs/architecture.md): stages, contracts, exception hierarchy

## Scenario guides

- [Dialects & codafication](docs/dialects.md): identification, EGY/GLF/LEV/.../MSA, CODA and MSA conversion
- [Arabizi](docs/arabizi.md): Franco-Arabic detection and conversion, full mapping tables
- [Stop words](docs/stopwords.md): 4 modes × 4 scopes, per-dialect and per-category lists, customization
- [Streaming](docs/streaming.md): resumable file-to-file sessions, checkpoints, locking, fingerprinting
- [Server](docs/server.md): HTTP API, batching, auth, hardening, deployment
- [Models (optional ML)](docs/models.md): HuggingFace backends for CODA/MSA/dialect-ID
- [For AI assistants & agents](docs/ai-assistants.md): normalization as an agent tool, sidecar service, RAG/fine-tuning presets, anti-patterns

## Operations

- [Performance](docs/performance.md): throughput numbers, caching, workers
- [Deployment](docs/deployment.md): containers, configs, rollout
- [Integrations](docs/integrations.md): pandas, scikit-learn, spaCy, NLTK, HF
- [Security & hardening](docs/security.md): input limits, PII, supply chain
- [Data files](docs/data-files.md): bundled lists and their formats
- [Testing](docs/testing.md): test philosophy, running, extending

## For developers

- [Developer guide](docs/development.md): repo layout, custom processors, plugin entry points
- [Style guide](docs/style-guide.md), [Migration](docs/migration.md), [Troubleshooting](docs/troubleshooting.md), [Glossary](docs/glossary.md) (159 terms, bilingual)

## Arabic documentation

- [الفهرس العربي](docs/ar/index.md): الدليل الكامل بالعربية — 33 ملفاً تطابق الإنجليزية بنيةً وأمثلة
