easyr-ar 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.
- easyr_ar-0.1.0/PKG-INFO +145 -0
- easyr_ar-0.1.0/README.md +101 -0
- easyr_ar-0.1.0/pyproject.toml +61 -0
- easyr_ar-0.1.0/setup.cfg +4 -0
- easyr_ar-0.1.0/src/easyr_ar.egg-info/PKG-INFO +145 -0
- easyr_ar-0.1.0/src/easyr_ar.egg-info/SOURCES.txt +53 -0
- easyr_ar-0.1.0/src/easyr_ar.egg-info/dependency_links.txt +1 -0
- easyr_ar-0.1.0/src/easyr_ar.egg-info/requires.txt +41 -0
- easyr_ar-0.1.0/src/easyr_ar.egg-info/top_level.txt +1 -0
- easyr_ar-0.1.0/src/easyre/__init__.py +65 -0
- easyr_ar-0.1.0/src/easyre/_arabic.py +190 -0
- easyr_ar-0.1.0/src/easyre/chunking/__init__.py +8 -0
- easyr_ar-0.1.0/src/easyre/chunking/headers.py +46 -0
- easyr_ar-0.1.0/src/easyre/chunking/separators.py +6 -0
- easyr_ar-0.1.0/src/easyre/chunking/splitters.py +185 -0
- easyr_ar-0.1.0/src/easyre/core.py +237 -0
- easyr_ar-0.1.0/src/easyre/extract/__init__.py +52 -0
- easyr_ar-0.1.0/src/easyre/extract/datetimes.py +223 -0
- easyr_ar-0.1.0/src/easyre/extract/numbers.py +160 -0
- easyr_ar-0.1.0/src/easyre/extract/phones.py +153 -0
- easyr_ar-0.1.0/src/easyre/extract/simple.py +113 -0
- easyr_ar-0.1.0/src/easyre/extract/structure.py +58 -0
- easyr_ar-0.1.0/src/easyre/llm/__init__.py +16 -0
- easyr_ar-0.1.0/src/easyre/llm/budget.py +45 -0
- easyr_ar-0.1.0/src/easyre/llm/cost.py +82 -0
- easyr_ar-0.1.0/src/easyre/llm/jsontools.py +222 -0
- easyr_ar-0.1.0/src/easyre/llm/prices.json +101 -0
- easyr_ar-0.1.0/src/easyre/llm/tokens.py +58 -0
- easyr_ar-0.1.0/src/easyre/loaders/__init__.py +9 -0
- easyr_ar-0.1.0/src/easyre/loaders/arabic_pdf.py +64 -0
- easyr_ar-0.1.0/src/easyre/loaders/artifacts.py +104 -0
- easyr_ar-0.1.0/src/easyre/loaders/docx.py +99 -0
- easyr_ar-0.1.0/src/easyre/loaders/pdf.py +88 -0
- easyr_ar-0.1.0/src/easyre/normalize/__init__.py +17 -0
- easyr_ar-0.1.0/src/easyre/normalize/_util.py +35 -0
- easyr_ar-0.1.0/src/easyre/normalize/arabic.py +64 -0
- easyr_ar-0.1.0/src/easyre/normalize/digits.py +33 -0
- easyr_ar-0.1.0/src/easyre/normalize/punctuation.py +76 -0
- easyr_ar-0.1.0/src/easyre/normalize/whitespace.py +136 -0
- easyr_ar-0.1.0/src/easyre/privacy/__init__.py +13 -0
- easyr_ar-0.1.0/src/easyre/privacy/data/__init__.py +2 -0
- easyr_ar-0.1.0/src/easyre/privacy/data/governorates.py +15 -0
- easyr_ar-0.1.0/src/easyre/privacy/masking.py +101 -0
- easyr_ar-0.1.0/src/easyre/privacy/pii.py +103 -0
- easyr_ar-0.1.0/src/easyre/privacy/secrets.py +96 -0
- easyr_ar-0.1.0/tests/test_chunking.py +220 -0
- easyr_ar-0.1.0/tests/test_core.py +134 -0
- easyr_ar-0.1.0/tests/test_extract.py +405 -0
- easyr_ar-0.1.0/tests/test_llm.py +298 -0
- easyr_ar-0.1.0/tests/test_loaders.py +344 -0
- easyr_ar-0.1.0/tests/test_no_extras.py +73 -0
- easyr_ar-0.1.0/tests/test_normalize.py +186 -0
- easyr_ar-0.1.0/tests/test_privacy.py +207 -0
- easyr_ar-0.1.0/tests/test_public_api.py +74 -0
- easyr_ar-0.1.0/tests/test_security.py +87 -0
easyr_ar-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: easyr-ar
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Arabic / English text preparation for parsing, LLM pipelines and RAG
|
|
5
|
+
Author-email: Your Name <you@example.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ismail-ashraf/easyre-ar
|
|
8
|
+
Project-URL: Issues, https://github.com/ismail-ashraf/easyre-ar/issues
|
|
9
|
+
Keywords: arabic,nlp,rag,text-processing,regex
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Natural Language :: Arabic
|
|
12
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
Provides-Extra: phones
|
|
16
|
+
Requires-Dist: phonenumbers>=8.12; extra == "phones"
|
|
17
|
+
Provides-Extra: pdf
|
|
18
|
+
Requires-Dist: pypdf>=4.0; extra == "pdf"
|
|
19
|
+
Provides-Extra: pdf-mupdf
|
|
20
|
+
Requires-Dist: pymupdf>=1.23; extra == "pdf-mupdf"
|
|
21
|
+
Provides-Extra: docx
|
|
22
|
+
Requires-Dist: python-docx>=1.0; extra == "docx"
|
|
23
|
+
Provides-Extra: chunking
|
|
24
|
+
Requires-Dist: langchain-text-splitters>=0.2; extra == "chunking"
|
|
25
|
+
Provides-Extra: tokens
|
|
26
|
+
Requires-Dist: tiktoken>=0.5; extra == "tokens"
|
|
27
|
+
Provides-Extra: html
|
|
28
|
+
Requires-Dist: langchain-text-splitters>=0.2; extra == "html"
|
|
29
|
+
Requires-Dist: beautifulsoup4; extra == "html"
|
|
30
|
+
Requires-Dist: lxml; extra == "html"
|
|
31
|
+
Provides-Extra: semantic
|
|
32
|
+
Requires-Dist: langchain-text-splitters>=0.2; extra == "semantic"
|
|
33
|
+
Requires-Dist: langchain-experimental; extra == "semantic"
|
|
34
|
+
Provides-Extra: pydantic
|
|
35
|
+
Requires-Dist: pydantic>=2.0; extra == "pydantic"
|
|
36
|
+
Provides-Extra: litellm
|
|
37
|
+
Requires-Dist: litellm; extra == "litellm"
|
|
38
|
+
Provides-Extra: all
|
|
39
|
+
Requires-Dist: easyr-ar[chunking,docx,html,litellm,pdf,phones,pydantic,tokens]; extra == "all"
|
|
40
|
+
Provides-Extra: dev
|
|
41
|
+
Requires-Dist: pytest; extra == "dev"
|
|
42
|
+
Requires-Dist: ruff; extra == "dev"
|
|
43
|
+
Requires-Dist: reportlab; extra == "dev"
|
|
44
|
+
|
|
45
|
+
# easyre
|
|
46
|
+
|
|
47
|
+
Arabic / English text preparation for parsing, LLM pipelines and RAG.
|
|
48
|
+
`easyre` sits on top of `re` and a few optional libraries, so you call `extract.emails(text)`
|
|
49
|
+
instead of writing regular expressions. The core install has **no third-party dependencies**;
|
|
50
|
+
heavier features import their library lazily and tell you which extra to install.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install easyre # core: normalize, extract, privacy, llm (text only)
|
|
54
|
+
pip install "easyre[pdf,docx,chunking,tokens,phones,pydantic]" # or: easyre[all]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
| Extra | Enables |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `phones` | validated phone numbers (`phonenumbers`) |
|
|
60
|
+
| `pdf` / `pdf-mupdf` | `read_pdf` with pypdf / PyMuPDF (**PyMuPDF is AGPL-licensed**) |
|
|
61
|
+
| `docx` | `read_docx` |
|
|
62
|
+
| `chunking`, `html`, `semantic` | `chunk` strategies (`recursive`, `markdown`, `code` / `html` / `semantic`) |
|
|
63
|
+
| `tokens` | exact token counts and `chunk(strategy="tokens")` |
|
|
64
|
+
| `pydantic` | `parse_to_model` |
|
|
65
|
+
| `litellm` | extra token / price fallbacks |
|
|
66
|
+
|
|
67
|
+
A function whose extra is missing raises `MissingDependencyError` (an `ImportError`):
|
|
68
|
+
`read_pdf() requires the optional dependency 'pypdf'. Install it with: pip install easyre[pdf]`.
|
|
69
|
+
|
|
70
|
+
## One example per module
|
|
71
|
+
|
|
72
|
+
Every public function is importable from its module and from the top-level package.
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
import easyre
|
|
76
|
+
from easyre import extract, normalize, privacy, loaders, chunking, llm
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**normalize** - remove diacritics, unify letters, digits, spaces (all support `return_map=True`):
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
normalize.strip_tashkeel("\u0645\u064E\u0631\u062D\u0628\u0627") # '\u0645\u0631\u062D\u0628\u0627'
|
|
83
|
+
normalize.normalize_digits("\u0662\u0660\u0662\u0666") # '2026'
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**extract** - every extractor returns `list[Match]` with exact offsets (`text[m.start:m.end] == m.text`):
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
extract.emails("write to a.b@example.com")[0].value # 'a.b@example.com'
|
|
90
|
+
extract.dates("5 \u062F\u064A\u0633\u0645\u0628\u0631 2026")[0].value # datetime.date(2026, 12, 5)
|
|
91
|
+
extract.currencies("\u0665\u0660\u0660 \u062C\u0646\u064A\u0647")[0].value # {'amount': Decimal('500'), 'currency': 'EGP'}
|
|
92
|
+
easyre.register("invoice_no", r"INV-\d{4}-\d{3}") # your own extractor
|
|
93
|
+
extract.invoice_no("see INV-2026-004")[0].text # 'INV-2026-004'
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**privacy** - mask, replace and redact (best-effort, not a substitute for human review):
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
privacy.mask("mail a.b@example.com", type="emails", keep_start=2) # 'mail a.*************'
|
|
100
|
+
privacy.replace("see https://x.io", type="urls") # 'see [URL]'
|
|
101
|
+
privacy.redact_secrets("key=AKIAIOSFODNN7EXAMPLE") # 'key=[REDACTED_SECRET]'
|
|
102
|
+
privacy.detect_pii("card 4111 1111 1111 1111") # [Match(type='credit_card', ...)]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**loaders** - read files and repair the extracted text:
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
pages = loaders.read_pdf("report.pdf") # list[Page]; needs easyre[pdf]
|
|
109
|
+
pages = loaders.fix_pdf_artifacts(pages) # drop headers / footers / page numbers
|
|
110
|
+
text = loaders.fix_arabic_pdf(pages[0].text) # presentation forms, bidi marks, reversed text
|
|
111
|
+
doc = loaders.read_docx("memo.docx")[0].text # Markdown-style text; needs easyre[docx]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**chunking** - sentence-aware (Arabic and English) chunks with exact offsets:
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
chunks = chunking.chunk(pages[0].text, strategy="recursive", size=500, overlap=50)
|
|
118
|
+
chunks = chunking.add_context_header(chunks, doc_title="Annual report")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**llm** - tokens, cost, budget, and parsing of model output:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
llm.count_tokens(chunks[0].text, model="gpt-4o") # TokenCount(tokens=..., exact=True)
|
|
125
|
+
llm.estimate_cost(1000, 500, model="gpt-4o") # USD, from the packaged prices.json
|
|
126
|
+
llm.fit_to_budget(chunks, max_tokens=3000) # longest prefix that fits
|
|
127
|
+
llm.extract_json('```json\n{"a": 1,}\n```') # {'a': 1}
|
|
128
|
+
llm.extract_tag("<answer>42</answer>", "answer") # '42'
|
|
129
|
+
llm.parse_to_model(reply, MyPydanticModel) # validated instance
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Notes
|
|
133
|
+
|
|
134
|
+
* `llm/prices.json` holds prices copied from the providers' official pricing pages (date in
|
|
135
|
+
`_meta`). Prices change: pass `prices=` to `estimate_cost` to use your own.
|
|
136
|
+
* `count_tokens` returns `exact=True` only when the model's own tokenizer was used.
|
|
137
|
+
* Arabic needs more tokens than English for the same meaning.
|
|
138
|
+
* System diagram: `docs/system-diagram.md`.
|
|
139
|
+
|
|
140
|
+
## Development
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
pip install -e ".[dev,all]"
|
|
144
|
+
pytest -q && ruff check .
|
|
145
|
+
```
|
easyr_ar-0.1.0/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# easyre
|
|
2
|
+
|
|
3
|
+
Arabic / English text preparation for parsing, LLM pipelines and RAG.
|
|
4
|
+
`easyre` sits on top of `re` and a few optional libraries, so you call `extract.emails(text)`
|
|
5
|
+
instead of writing regular expressions. The core install has **no third-party dependencies**;
|
|
6
|
+
heavier features import their library lazily and tell you which extra to install.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install easyre # core: normalize, extract, privacy, llm (text only)
|
|
10
|
+
pip install "easyre[pdf,docx,chunking,tokens,phones,pydantic]" # or: easyre[all]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
| Extra | Enables |
|
|
14
|
+
|---|---|
|
|
15
|
+
| `phones` | validated phone numbers (`phonenumbers`) |
|
|
16
|
+
| `pdf` / `pdf-mupdf` | `read_pdf` with pypdf / PyMuPDF (**PyMuPDF is AGPL-licensed**) |
|
|
17
|
+
| `docx` | `read_docx` |
|
|
18
|
+
| `chunking`, `html`, `semantic` | `chunk` strategies (`recursive`, `markdown`, `code` / `html` / `semantic`) |
|
|
19
|
+
| `tokens` | exact token counts and `chunk(strategy="tokens")` |
|
|
20
|
+
| `pydantic` | `parse_to_model` |
|
|
21
|
+
| `litellm` | extra token / price fallbacks |
|
|
22
|
+
|
|
23
|
+
A function whose extra is missing raises `MissingDependencyError` (an `ImportError`):
|
|
24
|
+
`read_pdf() requires the optional dependency 'pypdf'. Install it with: pip install easyre[pdf]`.
|
|
25
|
+
|
|
26
|
+
## One example per module
|
|
27
|
+
|
|
28
|
+
Every public function is importable from its module and from the top-level package.
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import easyre
|
|
32
|
+
from easyre import extract, normalize, privacy, loaders, chunking, llm
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**normalize** - remove diacritics, unify letters, digits, spaces (all support `return_map=True`):
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
normalize.strip_tashkeel("\u0645\u064E\u0631\u062D\u0628\u0627") # '\u0645\u0631\u062D\u0628\u0627'
|
|
39
|
+
normalize.normalize_digits("\u0662\u0660\u0662\u0666") # '2026'
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**extract** - every extractor returns `list[Match]` with exact offsets (`text[m.start:m.end] == m.text`):
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
extract.emails("write to a.b@example.com")[0].value # 'a.b@example.com'
|
|
46
|
+
extract.dates("5 \u062F\u064A\u0633\u0645\u0628\u0631 2026")[0].value # datetime.date(2026, 12, 5)
|
|
47
|
+
extract.currencies("\u0665\u0660\u0660 \u062C\u0646\u064A\u0647")[0].value # {'amount': Decimal('500'), 'currency': 'EGP'}
|
|
48
|
+
easyre.register("invoice_no", r"INV-\d{4}-\d{3}") # your own extractor
|
|
49
|
+
extract.invoice_no("see INV-2026-004")[0].text # 'INV-2026-004'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**privacy** - mask, replace and redact (best-effort, not a substitute for human review):
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
privacy.mask("mail a.b@example.com", type="emails", keep_start=2) # 'mail a.*************'
|
|
56
|
+
privacy.replace("see https://x.io", type="urls") # 'see [URL]'
|
|
57
|
+
privacy.redact_secrets("key=AKIAIOSFODNN7EXAMPLE") # 'key=[REDACTED_SECRET]'
|
|
58
|
+
privacy.detect_pii("card 4111 1111 1111 1111") # [Match(type='credit_card', ...)]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**loaders** - read files and repair the extracted text:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
pages = loaders.read_pdf("report.pdf") # list[Page]; needs easyre[pdf]
|
|
65
|
+
pages = loaders.fix_pdf_artifacts(pages) # drop headers / footers / page numbers
|
|
66
|
+
text = loaders.fix_arabic_pdf(pages[0].text) # presentation forms, bidi marks, reversed text
|
|
67
|
+
doc = loaders.read_docx("memo.docx")[0].text # Markdown-style text; needs easyre[docx]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**chunking** - sentence-aware (Arabic and English) chunks with exact offsets:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
chunks = chunking.chunk(pages[0].text, strategy="recursive", size=500, overlap=50)
|
|
74
|
+
chunks = chunking.add_context_header(chunks, doc_title="Annual report")
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**llm** - tokens, cost, budget, and parsing of model output:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
llm.count_tokens(chunks[0].text, model="gpt-4o") # TokenCount(tokens=..., exact=True)
|
|
81
|
+
llm.estimate_cost(1000, 500, model="gpt-4o") # USD, from the packaged prices.json
|
|
82
|
+
llm.fit_to_budget(chunks, max_tokens=3000) # longest prefix that fits
|
|
83
|
+
llm.extract_json('```json\n{"a": 1,}\n```') # {'a': 1}
|
|
84
|
+
llm.extract_tag("<answer>42</answer>", "answer") # '42'
|
|
85
|
+
llm.parse_to_model(reply, MyPydanticModel) # validated instance
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Notes
|
|
89
|
+
|
|
90
|
+
* `llm/prices.json` holds prices copied from the providers' official pricing pages (date in
|
|
91
|
+
`_meta`). Prices change: pass `prices=` to `estimate_cost` to use your own.
|
|
92
|
+
* `count_tokens` returns `exact=True` only when the model's own tokenizer was used.
|
|
93
|
+
* Arabic needs more tokens than English for the same meaning.
|
|
94
|
+
* System diagram: `docs/system-diagram.md`.
|
|
95
|
+
|
|
96
|
+
## Development
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pip install -e ".[dev,all]"
|
|
100
|
+
pytest -q && ruff check .
|
|
101
|
+
```
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "easyr-ar"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
description = "Arabic / English text preparation for parsing, LLM pipelines and RAG"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
license = "MIT"
|
|
13
|
+
license-files = ["LICENSE"]
|
|
14
|
+
authors = [{ name = "Your Name", email = "you@example.com" }]
|
|
15
|
+
keywords = ["arabic", "nlp", "rag", "text-processing", "regex"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Natural Language :: Arabic",
|
|
19
|
+
"Topic :: Text Processing :: Linguistic",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
dependencies = [] # core is standard-library only
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://github.com/ismail-ashraf/easyre-ar"
|
|
26
|
+
Issues = "https://github.com/ismail-ashraf/easyre-ar/issues"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
phones = ["phonenumbers>=8.12"]
|
|
31
|
+
pdf = ["pypdf>=4.0"]
|
|
32
|
+
pdf-mupdf = ["pymupdf>=1.23"] # AGPL licensed; mention in docs
|
|
33
|
+
docx = ["python-docx>=1.0"]
|
|
34
|
+
chunking = ["langchain-text-splitters>=0.2"]
|
|
35
|
+
tokens = ["tiktoken>=0.5"]
|
|
36
|
+
html = ["langchain-text-splitters>=0.2", "beautifulsoup4", "lxml"]
|
|
37
|
+
semantic = ["langchain-text-splitters>=0.2", "langchain-experimental"]
|
|
38
|
+
pydantic = ["pydantic>=2.0"]
|
|
39
|
+
litellm = ["litellm"]
|
|
40
|
+
all = ["easyr-ar[phones,pdf,docx,chunking,tokens,html,pydantic,litellm]"]
|
|
41
|
+
dev = ["pytest", "ruff", "reportlab"]
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["src"]
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.package-data]
|
|
47
|
+
easyre = ["llm/prices.json"]
|
|
48
|
+
|
|
49
|
+
[tool.pytest.ini_options]
|
|
50
|
+
testpaths = ["tests"]
|
|
51
|
+
addopts = "-q"
|
|
52
|
+
|
|
53
|
+
[tool.ruff]
|
|
54
|
+
line-length = 100
|
|
55
|
+
target-version = "py310"
|
|
56
|
+
|
|
57
|
+
[tool.ruff.lint]
|
|
58
|
+
select = ["E", "F", "W", "I"]
|
|
59
|
+
|
|
60
|
+
[tool.ruff.lint.per-file-ignores]
|
|
61
|
+
"tests/*" = ["E501"] # tests spell Arabic strings with long \uXXXX escapes
|
easyr_ar-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: easyr-ar
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Arabic / English text preparation for parsing, LLM pipelines and RAG
|
|
5
|
+
Author-email: Your Name <you@example.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ismail-ashraf/easyre-ar
|
|
8
|
+
Project-URL: Issues, https://github.com/ismail-ashraf/easyre-ar/issues
|
|
9
|
+
Keywords: arabic,nlp,rag,text-processing,regex
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Natural Language :: Arabic
|
|
12
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
Provides-Extra: phones
|
|
16
|
+
Requires-Dist: phonenumbers>=8.12; extra == "phones"
|
|
17
|
+
Provides-Extra: pdf
|
|
18
|
+
Requires-Dist: pypdf>=4.0; extra == "pdf"
|
|
19
|
+
Provides-Extra: pdf-mupdf
|
|
20
|
+
Requires-Dist: pymupdf>=1.23; extra == "pdf-mupdf"
|
|
21
|
+
Provides-Extra: docx
|
|
22
|
+
Requires-Dist: python-docx>=1.0; extra == "docx"
|
|
23
|
+
Provides-Extra: chunking
|
|
24
|
+
Requires-Dist: langchain-text-splitters>=0.2; extra == "chunking"
|
|
25
|
+
Provides-Extra: tokens
|
|
26
|
+
Requires-Dist: tiktoken>=0.5; extra == "tokens"
|
|
27
|
+
Provides-Extra: html
|
|
28
|
+
Requires-Dist: langchain-text-splitters>=0.2; extra == "html"
|
|
29
|
+
Requires-Dist: beautifulsoup4; extra == "html"
|
|
30
|
+
Requires-Dist: lxml; extra == "html"
|
|
31
|
+
Provides-Extra: semantic
|
|
32
|
+
Requires-Dist: langchain-text-splitters>=0.2; extra == "semantic"
|
|
33
|
+
Requires-Dist: langchain-experimental; extra == "semantic"
|
|
34
|
+
Provides-Extra: pydantic
|
|
35
|
+
Requires-Dist: pydantic>=2.0; extra == "pydantic"
|
|
36
|
+
Provides-Extra: litellm
|
|
37
|
+
Requires-Dist: litellm; extra == "litellm"
|
|
38
|
+
Provides-Extra: all
|
|
39
|
+
Requires-Dist: easyr-ar[chunking,docx,html,litellm,pdf,phones,pydantic,tokens]; extra == "all"
|
|
40
|
+
Provides-Extra: dev
|
|
41
|
+
Requires-Dist: pytest; extra == "dev"
|
|
42
|
+
Requires-Dist: ruff; extra == "dev"
|
|
43
|
+
Requires-Dist: reportlab; extra == "dev"
|
|
44
|
+
|
|
45
|
+
# easyre
|
|
46
|
+
|
|
47
|
+
Arabic / English text preparation for parsing, LLM pipelines and RAG.
|
|
48
|
+
`easyre` sits on top of `re` and a few optional libraries, so you call `extract.emails(text)`
|
|
49
|
+
instead of writing regular expressions. The core install has **no third-party dependencies**;
|
|
50
|
+
heavier features import their library lazily and tell you which extra to install.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install easyre # core: normalize, extract, privacy, llm (text only)
|
|
54
|
+
pip install "easyre[pdf,docx,chunking,tokens,phones,pydantic]" # or: easyre[all]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
| Extra | Enables |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `phones` | validated phone numbers (`phonenumbers`) |
|
|
60
|
+
| `pdf` / `pdf-mupdf` | `read_pdf` with pypdf / PyMuPDF (**PyMuPDF is AGPL-licensed**) |
|
|
61
|
+
| `docx` | `read_docx` |
|
|
62
|
+
| `chunking`, `html`, `semantic` | `chunk` strategies (`recursive`, `markdown`, `code` / `html` / `semantic`) |
|
|
63
|
+
| `tokens` | exact token counts and `chunk(strategy="tokens")` |
|
|
64
|
+
| `pydantic` | `parse_to_model` |
|
|
65
|
+
| `litellm` | extra token / price fallbacks |
|
|
66
|
+
|
|
67
|
+
A function whose extra is missing raises `MissingDependencyError` (an `ImportError`):
|
|
68
|
+
`read_pdf() requires the optional dependency 'pypdf'. Install it with: pip install easyre[pdf]`.
|
|
69
|
+
|
|
70
|
+
## One example per module
|
|
71
|
+
|
|
72
|
+
Every public function is importable from its module and from the top-level package.
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
import easyre
|
|
76
|
+
from easyre import extract, normalize, privacy, loaders, chunking, llm
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**normalize** - remove diacritics, unify letters, digits, spaces (all support `return_map=True`):
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
normalize.strip_tashkeel("\u0645\u064E\u0631\u062D\u0628\u0627") # '\u0645\u0631\u062D\u0628\u0627'
|
|
83
|
+
normalize.normalize_digits("\u0662\u0660\u0662\u0666") # '2026'
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**extract** - every extractor returns `list[Match]` with exact offsets (`text[m.start:m.end] == m.text`):
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
extract.emails("write to a.b@example.com")[0].value # 'a.b@example.com'
|
|
90
|
+
extract.dates("5 \u062F\u064A\u0633\u0645\u0628\u0631 2026")[0].value # datetime.date(2026, 12, 5)
|
|
91
|
+
extract.currencies("\u0665\u0660\u0660 \u062C\u0646\u064A\u0647")[0].value # {'amount': Decimal('500'), 'currency': 'EGP'}
|
|
92
|
+
easyre.register("invoice_no", r"INV-\d{4}-\d{3}") # your own extractor
|
|
93
|
+
extract.invoice_no("see INV-2026-004")[0].text # 'INV-2026-004'
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**privacy** - mask, replace and redact (best-effort, not a substitute for human review):
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
privacy.mask("mail a.b@example.com", type="emails", keep_start=2) # 'mail a.*************'
|
|
100
|
+
privacy.replace("see https://x.io", type="urls") # 'see [URL]'
|
|
101
|
+
privacy.redact_secrets("key=AKIAIOSFODNN7EXAMPLE") # 'key=[REDACTED_SECRET]'
|
|
102
|
+
privacy.detect_pii("card 4111 1111 1111 1111") # [Match(type='credit_card', ...)]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**loaders** - read files and repair the extracted text:
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
pages = loaders.read_pdf("report.pdf") # list[Page]; needs easyre[pdf]
|
|
109
|
+
pages = loaders.fix_pdf_artifacts(pages) # drop headers / footers / page numbers
|
|
110
|
+
text = loaders.fix_arabic_pdf(pages[0].text) # presentation forms, bidi marks, reversed text
|
|
111
|
+
doc = loaders.read_docx("memo.docx")[0].text # Markdown-style text; needs easyre[docx]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**chunking** - sentence-aware (Arabic and English) chunks with exact offsets:
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
chunks = chunking.chunk(pages[0].text, strategy="recursive", size=500, overlap=50)
|
|
118
|
+
chunks = chunking.add_context_header(chunks, doc_title="Annual report")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**llm** - tokens, cost, budget, and parsing of model output:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
llm.count_tokens(chunks[0].text, model="gpt-4o") # TokenCount(tokens=..., exact=True)
|
|
125
|
+
llm.estimate_cost(1000, 500, model="gpt-4o") # USD, from the packaged prices.json
|
|
126
|
+
llm.fit_to_budget(chunks, max_tokens=3000) # longest prefix that fits
|
|
127
|
+
llm.extract_json('```json\n{"a": 1,}\n```') # {'a': 1}
|
|
128
|
+
llm.extract_tag("<answer>42</answer>", "answer") # '42'
|
|
129
|
+
llm.parse_to_model(reply, MyPydanticModel) # validated instance
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Notes
|
|
133
|
+
|
|
134
|
+
* `llm/prices.json` holds prices copied from the providers' official pricing pages (date in
|
|
135
|
+
`_meta`). Prices change: pass `prices=` to `estimate_cost` to use your own.
|
|
136
|
+
* `count_tokens` returns `exact=True` only when the model's own tokenizer was used.
|
|
137
|
+
* Arabic needs more tokens than English for the same meaning.
|
|
138
|
+
* System diagram: `docs/system-diagram.md`.
|
|
139
|
+
|
|
140
|
+
## Development
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
pip install -e ".[dev,all]"
|
|
144
|
+
pytest -q && ruff check .
|
|
145
|
+
```
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/easyr_ar.egg-info/PKG-INFO
|
|
4
|
+
src/easyr_ar.egg-info/SOURCES.txt
|
|
5
|
+
src/easyr_ar.egg-info/dependency_links.txt
|
|
6
|
+
src/easyr_ar.egg-info/requires.txt
|
|
7
|
+
src/easyr_ar.egg-info/top_level.txt
|
|
8
|
+
src/easyre/__init__.py
|
|
9
|
+
src/easyre/_arabic.py
|
|
10
|
+
src/easyre/core.py
|
|
11
|
+
src/easyre/chunking/__init__.py
|
|
12
|
+
src/easyre/chunking/headers.py
|
|
13
|
+
src/easyre/chunking/separators.py
|
|
14
|
+
src/easyre/chunking/splitters.py
|
|
15
|
+
src/easyre/extract/__init__.py
|
|
16
|
+
src/easyre/extract/datetimes.py
|
|
17
|
+
src/easyre/extract/numbers.py
|
|
18
|
+
src/easyre/extract/phones.py
|
|
19
|
+
src/easyre/extract/simple.py
|
|
20
|
+
src/easyre/extract/structure.py
|
|
21
|
+
src/easyre/llm/__init__.py
|
|
22
|
+
src/easyre/llm/budget.py
|
|
23
|
+
src/easyre/llm/cost.py
|
|
24
|
+
src/easyre/llm/jsontools.py
|
|
25
|
+
src/easyre/llm/prices.json
|
|
26
|
+
src/easyre/llm/tokens.py
|
|
27
|
+
src/easyre/loaders/__init__.py
|
|
28
|
+
src/easyre/loaders/arabic_pdf.py
|
|
29
|
+
src/easyre/loaders/artifacts.py
|
|
30
|
+
src/easyre/loaders/docx.py
|
|
31
|
+
src/easyre/loaders/pdf.py
|
|
32
|
+
src/easyre/normalize/__init__.py
|
|
33
|
+
src/easyre/normalize/_util.py
|
|
34
|
+
src/easyre/normalize/arabic.py
|
|
35
|
+
src/easyre/normalize/digits.py
|
|
36
|
+
src/easyre/normalize/punctuation.py
|
|
37
|
+
src/easyre/normalize/whitespace.py
|
|
38
|
+
src/easyre/privacy/__init__.py
|
|
39
|
+
src/easyre/privacy/masking.py
|
|
40
|
+
src/easyre/privacy/pii.py
|
|
41
|
+
src/easyre/privacy/secrets.py
|
|
42
|
+
src/easyre/privacy/data/__init__.py
|
|
43
|
+
src/easyre/privacy/data/governorates.py
|
|
44
|
+
tests/test_chunking.py
|
|
45
|
+
tests/test_core.py
|
|
46
|
+
tests/test_extract.py
|
|
47
|
+
tests/test_llm.py
|
|
48
|
+
tests/test_loaders.py
|
|
49
|
+
tests/test_no_extras.py
|
|
50
|
+
tests/test_normalize.py
|
|
51
|
+
tests/test_privacy.py
|
|
52
|
+
tests/test_public_api.py
|
|
53
|
+
tests/test_security.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
[all]
|
|
3
|
+
easyr-ar[chunking,docx,html,litellm,pdf,phones,pydantic,tokens]
|
|
4
|
+
|
|
5
|
+
[chunking]
|
|
6
|
+
langchain-text-splitters>=0.2
|
|
7
|
+
|
|
8
|
+
[dev]
|
|
9
|
+
pytest
|
|
10
|
+
ruff
|
|
11
|
+
reportlab
|
|
12
|
+
|
|
13
|
+
[docx]
|
|
14
|
+
python-docx>=1.0
|
|
15
|
+
|
|
16
|
+
[html]
|
|
17
|
+
langchain-text-splitters>=0.2
|
|
18
|
+
beautifulsoup4
|
|
19
|
+
lxml
|
|
20
|
+
|
|
21
|
+
[litellm]
|
|
22
|
+
litellm
|
|
23
|
+
|
|
24
|
+
[pdf]
|
|
25
|
+
pypdf>=4.0
|
|
26
|
+
|
|
27
|
+
[pdf-mupdf]
|
|
28
|
+
pymupdf>=1.23
|
|
29
|
+
|
|
30
|
+
[phones]
|
|
31
|
+
phonenumbers>=8.12
|
|
32
|
+
|
|
33
|
+
[pydantic]
|
|
34
|
+
pydantic>=2.0
|
|
35
|
+
|
|
36
|
+
[semantic]
|
|
37
|
+
langchain-text-splitters>=0.2
|
|
38
|
+
langchain-experimental
|
|
39
|
+
|
|
40
|
+
[tokens]
|
|
41
|
+
tiktoken>=0.5
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
easyre
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""easyre - Arabic / English text preparation for parsing, LLM pipelines and RAG."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from . import chunking, extract, llm, loaders, normalize, privacy
|
|
5
|
+
from .chunking import add_context_header, chunk
|
|
6
|
+
from .core import (
|
|
7
|
+
Chunk,
|
|
8
|
+
EasyreError,
|
|
9
|
+
ExtractionError,
|
|
10
|
+
Match,
|
|
11
|
+
MissingDependencyError,
|
|
12
|
+
Page,
|
|
13
|
+
ParseError,
|
|
14
|
+
TokenCount,
|
|
15
|
+
UnknownModelError,
|
|
16
|
+
register,
|
|
17
|
+
)
|
|
18
|
+
from .extract import (
|
|
19
|
+
bullet_points,
|
|
20
|
+
codes,
|
|
21
|
+
currencies,
|
|
22
|
+
dates,
|
|
23
|
+
emails,
|
|
24
|
+
hashtags,
|
|
25
|
+
links_with_titles,
|
|
26
|
+
mentions,
|
|
27
|
+
percentages,
|
|
28
|
+
phones,
|
|
29
|
+
times,
|
|
30
|
+
urls,
|
|
31
|
+
)
|
|
32
|
+
from .llm import (
|
|
33
|
+
count_tokens,
|
|
34
|
+
estimate_cost,
|
|
35
|
+
extract_json,
|
|
36
|
+
extract_tag,
|
|
37
|
+
fit_to_budget,
|
|
38
|
+
parse_to_model,
|
|
39
|
+
)
|
|
40
|
+
from .loaders import fix_arabic_pdf, fix_pdf_artifacts, read_docx, read_pdf
|
|
41
|
+
from .normalize import (
|
|
42
|
+
clean_whitespace,
|
|
43
|
+
collapse_repeats,
|
|
44
|
+
normalize_arabic,
|
|
45
|
+
normalize_digits,
|
|
46
|
+
normalize_punctuation,
|
|
47
|
+
remove_tatweel,
|
|
48
|
+
strip_tashkeel,
|
|
49
|
+
)
|
|
50
|
+
from .privacy import detect_pii, mask, national_id, redact_secrets, replace
|
|
51
|
+
|
|
52
|
+
__version__ = "0.1.0"
|
|
53
|
+
__all__ = [
|
|
54
|
+
"extract", "normalize", "privacy", "llm", "loaders", "chunking",
|
|
55
|
+
"chunk", "add_context_header", "read_pdf", "read_docx", "fix_pdf_artifacts", "fix_arabic_pdf",
|
|
56
|
+
"count_tokens", "estimate_cost", "fit_to_budget",
|
|
57
|
+
"extract_json", "extract_tag", "parse_to_model",
|
|
58
|
+
"mask", "replace", "detect_pii", "national_id", "redact_secrets",
|
|
59
|
+
"Match", "Chunk", "Page", "TokenCount", "register",
|
|
60
|
+
"EasyreError", "MissingDependencyError", "ExtractionError", "ParseError", "UnknownModelError",
|
|
61
|
+
"normalize_arabic", "normalize_digits", "strip_tashkeel", "remove_tatweel",
|
|
62
|
+
"clean_whitespace", "collapse_repeats", "normalize_punctuation",
|
|
63
|
+
"emails", "urls", "hashtags", "mentions", "percentages", "codes", "bullet_points",
|
|
64
|
+
"links_with_titles", "phones", "dates", "times", "currencies",
|
|
65
|
+
] # fmt: skip
|