Datasets:
File size: 5,339 Bytes
abb3239 1cf3883 abb3239 1cf3883 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | ---
language:
- ar
- ary # Moroccan Darija
license: cc-by-nc-sa-4.0
size_categories:
- 50K<n<100K
task_categories:
- text-generation
- fill-mask
- question-answering
- text-classification
multilinguality: monolingual
pretty_name: Moroccan Cultural Books OCR Dataset
tags:
- morocco
- arabic
- darija
- history
- culture
- religion
- ocr
- books
- north-africa
---
# Moroccan Cultural Books OCR Dataset
## Dataset Description
This dataset contains **85,600+ page-level records** extracted from PDF books covering the multifaceted cultural heritage of Morocco. The corpus spans historical chronicles, religious texts, Islamic scholarship, and social commentary, reflecting Morocco's complex identity across Arab, Amazigh, Andalusian, and Mediterranean influences.
The texts were extracted using a hybrid **PDF-to-text + OCR pipeline** designed to handle both digital-born PDFs and scanned historical documents written in Arabic script (with extensive diacritics and occasional Latin transliterations).
### Languages
- **Primary**: Classical Arabic (Modern Standard Arabic)
- **Secondary**: Moroccan Darija (Arabic dialect with Amazigh and French loanwords)
- **Tertiary**: Occasional French and Latin terms in historical/anthropological passages
---
## Dataset Details
| Split | Records | Unique Books | Categories |
|--------|---------|--------------|------------|
| train | 85,600 | 299 | 8 |
### Data Fields
| Field | Type | Description |
|------------|--------|-------------|
| `name` | string | Source PDF filename (e.g., `مجمل تاريخ المغرب.pdf`) |
| `page` | int64 | Page number within the source document |
| `content` | string | Extracted text content (UTF-8 Arabic script) |
| `category` | string | Thematic category assigned to the book |
| `char` | int64 | Character count of the extracted page text |
### Categories
The dataset covers **8 thematic categories**, including but not limited to:
- **Historique** — Moroccan history, pre-colonial and colonial periods, historiography
- **Religion** — Islamic theology, Sufism, religious practice in Morocco
- **Muslim** — Islamic civilization, jurisprudence, and scholarly works
- *(Additional categories present in the full corpus)*
---
## Source Data
The source material consists of digitized books and manuscripts stored in a categorized folder structure (`/Category/Book.pdf`). The corpus prioritizes works that document:
- Pre-Islamic and Amazigh history of the Maghreb
- Islamic dynasties (Idrisid, Almoravid, Almohad, Marinid, Saadi, Alaouite)
- Colonial and post-colonial historiography
- Religious and legal scholarship (fiqh, hadith, tafsir)
- Cultural anthropology and social structures
---
## Data Generation Pipeline
The extraction pipeline was implemented in Python using a **multiprocessing architecture** for scalability.
### 1. Text Extraction (Primary)
- **Library**: `pypdf` (`PdfReader`)
- Each page is processed sequentially; text is extracted natively from PDF content streams.
- **Cleaning**: Aggressive whitespace normalization (`re.sub(r'\s+', ' ', text)`).
### 2. OCR Fallback (Secondary)
When native extraction yields fewer than **30 characters** (indicating a scanned/image-based page):
- **PDF Rendering**: `pdf2image.convert_from_path()` (Poppler backend)
- **OCR Engine**: Tesseract v5.x
- **Language Pack**: `ara+eng` (Arabic + English)
- The OCR output undergoes the same whitespace normalization before storage.
### 3. Parallelization
- **Worker Pool**: `multiprocessing.Pool` using `N = CPU_COUNT - 1` workers
- **Incremental Persistence**: Results are appended to a CSV in real-time to prevent data loss during long-running extractions.
### 4. Deduplication & Resumption
- A `processed_set` tracks `(category, filename)` tuples.
- The pipeline skips already-ingested books upon restart.
### Code Snippet
```python
def clean_text(text):
text = re.sub(r'\s+', ' ', text)
return text.strip()
# Primary extraction
text = page.extract_text()
text = "" if text is None else clean_text(text)
# OCR fallback for scanned pages
if len(text) < 30:
images = convert_from_path(pdf_path, first_page=page_num+1, last_page=page_num+1)
ocr_text = pytesseract.image_to_string(images[0], lang="ara+eng")
text = clean_text(ocr_text)
```
## License
This dataset is licensed under [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)](https://creativecommons.org/licenses/by-nc-sa/4.0/).
**Summary:**
- ✅ Free to use and share
- ✅ Attribution required
- ❌ Non-commercial use only
- ✅ ShareAlike (derivative works must be under same license)
## Citation
```latex
@dataset{mawdoo3_arabic_articles_2026,
author = {Ouail LAAMIRI},
title = {Mawdoo3 Arabic Articles Dataset - 96K+ Educational Articles from Mawdoo3.com},
year = 2026,
month = february,
note = {Complete dataset of 96,983 articles from Mawdoo3.com, the largest Arabic encyclopedia. Covers 18 categories including education, Islam, cooking, health, self-care, world geography, animals, family, business, technology, sports, arts, stories, wisdom, and fitness. Suitable for Arabic language modeling, QA systems, information retrieval, and NLP research.}
}
``` |