trueglyph 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.
- trueglyph-0.1.0/LICENSE +21 -0
- trueglyph-0.1.0/PKG-INFO +394 -0
- trueglyph-0.1.0/README.md +355 -0
- trueglyph-0.1.0/pyproject.toml +48 -0
- trueglyph-0.1.0/setup.cfg +4 -0
- trueglyph-0.1.0/src/trueglyph/__init__.py +8 -0
- trueglyph-0.1.0/src/trueglyph/assess.py +177 -0
- trueglyph-0.1.0/src/trueglyph/cli.py +115 -0
- trueglyph-0.1.0/src/trueglyph/data/demo.pdf +0 -0
- trueglyph-0.1.0/src/trueglyph/engines.py +245 -0
- trueglyph-0.1.0/src/trueglyph/guard.py +404 -0
- trueglyph-0.1.0/src/trueglyph/integrations.py +70 -0
- trueglyph-0.1.0/src/trueglyph/lexicon.py +154 -0
- trueglyph-0.1.0/src/trueglyph/mcp_server.py +62 -0
- trueglyph-0.1.0/src/trueglyph/repair.py +270 -0
- trueglyph-0.1.0/src/trueglyph/scripts.py +123 -0
- trueglyph-0.1.0/src/trueglyph/signals.py +300 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/NOTICE +5 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/am.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/as.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/gu.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/hy.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/ka.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/km.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/kn.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/lo.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/ml.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/mr.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/my.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/ne.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/or.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/pa.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/si.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/te.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph/wordlists/th.txt.xz +0 -0
- trueglyph-0.1.0/src/trueglyph.egg-info/PKG-INFO +394 -0
- trueglyph-0.1.0/src/trueglyph.egg-info/SOURCES.txt +42 -0
- trueglyph-0.1.0/src/trueglyph.egg-info/dependency_links.txt +1 -0
- trueglyph-0.1.0/src/trueglyph.egg-info/entry_points.txt +3 -0
- trueglyph-0.1.0/src/trueglyph.egg-info/requires.txt +19 -0
- trueglyph-0.1.0/src/trueglyph.egg-info/top_level.txt +1 -0
- trueglyph-0.1.0/tests/test_integrations.py +33 -0
- trueglyph-0.1.0/tests/test_mcp.py +37 -0
- trueglyph-0.1.0/tests/test_trueglyph.py +323 -0
trueglyph-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TrueGlyph contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
trueglyph-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: trueglyph
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Tells AI agents when text extracted from a PDF cannot be trusted - for every script, not just Latin - and repairs it.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/jishnucz/TrueGlyph
|
|
7
|
+
Project-URL: Repository, https://github.com/jishnucz/TrueGlyph
|
|
8
|
+
Project-URL: Issues, https://github.com/jishnucz/TrueGlyph/issues
|
|
9
|
+
Keywords: pdf,text-extraction,ocr,rag,unicode,multilingual,mcp,ai-agents,llm,indic,arabic,cjk,data-quality
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
15
|
+
Classifier: Natural Language :: Hindi
|
|
16
|
+
Classifier: Natural Language :: Bengali
|
|
17
|
+
Classifier: Natural Language :: Arabic
|
|
18
|
+
Classifier: Natural Language :: Chinese (Simplified)
|
|
19
|
+
Classifier: Natural Language :: Japanese
|
|
20
|
+
Classifier: Natural Language :: Thai
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: pymupdf>=1.24
|
|
25
|
+
Provides-Extra: engines
|
|
26
|
+
Requires-Dist: pypdf>=5; extra == "engines"
|
|
27
|
+
Requires-Dist: pdfminer.six>=20240706; extra == "engines"
|
|
28
|
+
Requires-Dist: docling-parse>=4; extra == "engines"
|
|
29
|
+
Provides-Extra: lexicon
|
|
30
|
+
Requires-Dist: wordfreq>=3.1; extra == "lexicon"
|
|
31
|
+
Provides-Extra: mcp
|
|
32
|
+
Requires-Dist: mcp>=1.2; extra == "mcp"
|
|
33
|
+
Provides-Extra: all
|
|
34
|
+
Requires-Dist: trueglyph[engines,lexicon,mcp]; extra == "all"
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: trueglyph[all]; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
# TrueGlyph
|
|
41
|
+
|
|
42
|
+
<!-- mcp-name: io.github.jishnucz/trueglyph -->
|
|
43
|
+
|
|
44
|
+
[](https://github.com/jishnucz/TrueGlyph/actions/workflows/ci.yml) [](https://github.com/jishnucz/TrueGlyph/blob/main/LICENSE) 
|
|
45
|
+
|
|
46
|
+
**Know when the text you pulled out of a PDF is wrong — in any script — and get the right text instead.**
|
|
47
|
+
|
|
48
|
+
AI agents and RAG pipelines read PDFs with extractors such as pypdf, PyMuPDF, pdfminer or docling. For English that
|
|
49
|
+
mostly works. For Hindi, Bengali, Tamil, Thai, Khmer, Burmese, Arabic, Urdu, Persian, Hebrew, Chinese or vertical
|
|
50
|
+
Japanese, those tools often return **damaged text without any error**: vowel signs in the wrong order, letters
|
|
51
|
+
doubled, words split, glyph codes instead of letters, right-to-left lines reversed, or nothing at all from a scanned
|
|
52
|
+
page. Even English PDFs come out with words broken by hyphenation and symbols lost. The agent then indexes, quotes
|
|
53
|
+
and reasons over text that is wrong, and nobody notices.
|
|
54
|
+
|
|
55
|
+
TrueGlyph checks every page, repairs what it safely can, switches extractor or falls back to OCR when it must, and
|
|
56
|
+
gives each page a **trust level** so your code or agent knows what it may use. It runs locally: no API keys, no
|
|
57
|
+
cloud, no LLM.
|
|
58
|
+
|
|
59
|
+
```text
|
|
60
|
+
$ trueglyph demo
|
|
61
|
+
Hindi
|
|
62
|
+
pypdf [BAD ] इसी घोषणा का सरकारी पाठ संयुक्त रा␀␀ों की इन पांच भाषाओं म␀ प्राप्य हैः—
|
|
63
|
+
TrueGlyph [OK ] इसी घोषणा का सरकारी पाठ संयुक्त राष्ट्रों की इन पांच भाषाओं में प्राप्य
|
|
64
|
+
Urdu
|
|
65
|
+
pypdf [BAD ] ﺗﻣﮩﯾد ﭼوﻧﮑہ ﮨر اﻧﺳﺎن ﮐﯽ ذاﺗﯽ ﻋزت اور ﺣرﻣت <- glyph codes, not letters
|
|
66
|
+
TrueGlyph [OK ] تمہید چونکہ ہر انسان کی ذاتی عزت اور حرمت
|
|
67
|
+
Thai
|
|
68
|
+
pypdf [BAD ] โดยที␀การยอมรับนับถือเกียรติศักดิ␀ประจําตัว <- tone marks lost
|
|
69
|
+
TrueGlyph [WARN] โดยที่การยอมรับนับถือเกียรติศักดิ์ประจำตัว
|
|
70
|
+
Japanese (vertical)
|
|
71
|
+
pypdf [BAD ] ︿ 前 ⽂ ﹀ ⼈ 類 社 会 の す べ て <- radicals (⼈ is not 人), one character at a time
|
|
72
|
+
TrueGlyph [OK ] 〈前文〉人類社会のすべての構成員の固有の尊厳と平等で
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**Contents:** [Quick start](#quick-start) · [Trust levels](#trust-levels) · [Use it from your tools](#use-it-from-your-tools)
|
|
76
|
+
· [How it works](#how-it-works) · [Results](#results) · [Limitations](#limitations) ·
|
|
77
|
+
[Configuration](#configuration) · [Development](#development) · [Contributing](#contributing)
|
|
78
|
+
|
|
79
|
+
## Quick start
|
|
80
|
+
|
|
81
|
+
Python 3.10 or newer.
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install "trueglyph[all] @ git+https://github.com/jishnucz/TrueGlyph" # PyMuPDF + other extractors, word lists, MCP server
|
|
85
|
+
trueglyph demo # see the problem and the fix, no files needed
|
|
86
|
+
trueglyph read report.pdf # check your own PDF
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Once the PyPI release is out this becomes `pip install "trueglyph[all]"`. Without git, download the wheel from
|
|
90
|
+
[Releases](https://github.com/jishnucz/TrueGlyph/releases) and run `pip install "trueglyph-0.1.0-py3-none-any.whl[all]"`.
|
|
91
|
+
Installing without `[all]` gives PyMuPDF only: fewer checks and no MCP server.
|
|
92
|
+
|
|
93
|
+
Nothing to install at all, with [uv](https://docs.astral.sh/uv/):
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
uvx --from "trueglyph[all] @ git+https://github.com/jishnucz/TrueGlyph" trueglyph demo
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Scanned pages need Tesseract** (optional; without it, scanned pages are reported as `none` instead of read):
|
|
100
|
+
|
|
101
|
+
| System | Install |
|
|
102
|
+
|---|---|
|
|
103
|
+
| Windows | `winget install UB-Mannheim.TesseractOCR` |
|
|
104
|
+
| macOS | `brew install tesseract tesseract-lang` |
|
|
105
|
+
| Debian / Ubuntu | `sudo apt install tesseract-ocr tesseract-ocr-hin tesseract-ocr-tha ...` (one package per language) |
|
|
106
|
+
|
|
107
|
+
For the best accuracy, download the models for your scripts from
|
|
108
|
+
[tessdata_best](https://github.com/tesseract-ocr/tessdata_best) into a `.tessdata` folder in your working directory,
|
|
109
|
+
or point `TRUEGLYPH_TESSDATA` at them.
|
|
110
|
+
|
|
111
|
+
## Trust levels
|
|
112
|
+
|
|
113
|
+
Every page gets one level. The document's level is its worst page.
|
|
114
|
+
|
|
115
|
+
| Trust | Meaning | What to do |
|
|
116
|
+
|---|---|---|
|
|
117
|
+
| `high` | no sign of damage | use the text |
|
|
118
|
+
| `medium` | minor issues, or checked by script rules only | usable; double-check exact quotes, names and numbers |
|
|
119
|
+
| `low` | damaged: letters lost, garbled, or OCR unsure | do not quote or index it as exact text; say the page could not be read reliably |
|
|
120
|
+
| `none` | no usable text (scan without OCR, or nothing readable) | do not guess |
|
|
121
|
+
|
|
122
|
+
What a reading looks like:
|
|
123
|
+
|
|
124
|
+
```text
|
|
125
|
+
$ trueglyph read demo.pdf
|
|
126
|
+
demo.pdf: document trust MEDIUM high=3 medium=1
|
|
127
|
+
page 1 OK high Devanagari via pymupdf repairs: collapsed_repeated_marks=8, merged_split_words=2
|
|
128
|
+
page 2 OK high Arabic via pypdf repairs: presentation_forms_to_letters=220
|
|
129
|
+
page 3 WARN medium Thai via pymupdf repairs: joined_wrapped_lines=5
|
|
130
|
+
- moderate: Line breaks inside words (script written without spaces).
|
|
131
|
+
page 4 OK high Kana via pymupdf repairs: joined_wrapped_lines=149
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Use it from your tools
|
|
135
|
+
|
|
136
|
+
### Command line
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
trueglyph read report.pdf # per-page trust, issues and repairs
|
|
140
|
+
trueglyph read report.pdf --text # only the best text
|
|
141
|
+
trueglyph read report.pdf --json # everything, machine-readable (add --no-text to omit the text)
|
|
142
|
+
trueglyph read report.pdf --pages 1,3-5 # some pages only
|
|
143
|
+
trueglyph read report.pdf --lang hi # language hint (ISO 639-1); helps OCR pick its model
|
|
144
|
+
trueglyph read report.pdf -v # show every decision: engines tried, OCR model contest, ...
|
|
145
|
+
echo "ﺍﻟﺴﻼﻡ ﻋﻠﻴﻜﻢ" | trueglyph check --repair # check text that came from ANY other tool
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Python
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from trueglyph import read, assess, repair
|
|
152
|
+
|
|
153
|
+
doc = read("report.pdf") # also: lang="hi", ocr=False, pages=[1, 2]
|
|
154
|
+
print(doc.trust, doc.summary) # 'medium', {'high': 3, 'medium': 1, 'low': 0, 'none': 0}
|
|
155
|
+
for page in doc.pages: # page.text, .trust, .script, .lang, .engine, .issues, .repairs
|
|
156
|
+
if page.trust in ("high", "medium"):
|
|
157
|
+
index(page.text)
|
|
158
|
+
else:
|
|
159
|
+
print(page.page, page.trust, [i["message"] for i in page.issues])
|
|
160
|
+
|
|
161
|
+
assess(chunk_from_any_tool).trust # check text you already have
|
|
162
|
+
repair(chunk_from_any_tool).text # and repair it (only what was detected)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### AI agents (MCP server)
|
|
166
|
+
|
|
167
|
+
Two tools: `read_pdf(path, lang?, pages?, ocr?)` and `check_text(text, lang?, repair_text?)`. The server tells the
|
|
168
|
+
agent what each trust level means.
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
claude mcp add trueglyph -- trueglyph-mcp # Claude Code, if you pip-installed it
|
|
172
|
+
# nothing installed? let uvx fetch it:
|
|
173
|
+
claude mcp add trueglyph -- uvx --from "trueglyph[all] @ git+https://github.com/jishnucz/TrueGlyph" trueglyph-mcp
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Claude Desktop, Cursor and other MCP clients (`mcpServers` config):
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{ "trueglyph": { "command": "uvx",
|
|
180
|
+
"args": ["--from", "trueglyph[all] @ git+https://github.com/jishnucz/TrueGlyph", "trueglyph-mcp"] } }
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
After the PyPI release, `"trueglyph[all]"` alone is enough in place of the `git+` form.
|
|
184
|
+
|
|
185
|
+
### RAG frameworks
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
from trueglyph.integrations import TrueGlyphLoader, TrueGlyphReader
|
|
189
|
+
|
|
190
|
+
docs = TrueGlyphLoader("report.pdf", min_trust="medium").load() # LangChain: one Document per page
|
|
191
|
+
docs = TrueGlyphReader(min_trust="medium").load_data("report.pdf") # LlamaIndex: one Document per page
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Pages below `min_trust` are skipped (or kept with `keep_untrusted=True`). Each document's metadata carries `trust`,
|
|
195
|
+
`script`, `lang`, `extractor`, `issues` and `repairs`, so you can filter or flag at query time.
|
|
196
|
+
|
|
197
|
+
### Elsewhere
|
|
198
|
+
|
|
199
|
+
| Where | How |
|
|
200
|
+
|---|---|
|
|
201
|
+
| Claude Code plugin | `/plugin marketplace add jishnucz/TrueGlyph`, then `/plugin install trueglyph@trueglyph` (MCP server + skill) |
|
|
202
|
+
| VS Code, Cursor | download `trueglyph-0.1.0.vsix` from [Releases](https://github.com/jishnucz/TrueGlyph/releases), then `code --install-extension trueglyph-0.1.0.vsix`. Right-click a PDF → *Check PDF*; select text → *Check Selected Text*; registers the MCP server for Copilot agent mode |
|
|
203
|
+
| Agent skill (Claude, OpenClaw/ClawHub, Codex) | `skills/read-pdf-faithfully/SKILL.md`: when to use TrueGlyph and how to act on trust levels |
|
|
204
|
+
| Browser | `pip install gradio && python space/app.py`: drop a PDF and compare plain extraction with TrueGlyph page by page |
|
|
205
|
+
|
|
206
|
+
## How it works
|
|
207
|
+
|
|
208
|
+
For each page TrueGlyph:
|
|
209
|
+
|
|
210
|
+
1. **Measures** reference-free signs of damage: patterns that correctly encoded text in that script never
|
|
211
|
+
contains (a Devanagari vowel sign before its consonant, a Thai tone mark with no letter under it, Arabic
|
|
212
|
+
presentation-form codes, one Chinese character per line, a hyphenated word that is one known word...).
|
|
213
|
+
2. **Repairs** only what it detected, and only in ways that are checked (a split word is joined only if the result
|
|
214
|
+
is a known word). It never hides what is lost: removed placeholders for missing letters keep the page `low`.
|
|
215
|
+
3. **Compares** the extractors and keeps the most faithful reading; for English, the first clean reading is enough.
|
|
216
|
+
4. **Falls back to OCR** when the text layer is missing or unusable. It picks the Tesseract model from the page's
|
|
217
|
+
own script, from Tesseract's script detection when a test read confirms it, or by a contest between models
|
|
218
|
+
scored on what they read. If layout analysis shreds a page (Burmese), the page is read again as one block.
|
|
219
|
+
5. **Reasons about the whole document:** a page whose text layer is only a typed title over a scan is OCR'd, and
|
|
220
|
+
when the font is broken on most pages, the remaining pages are OCR'd too.
|
|
221
|
+
6. **Reports** the trust level, the issues found and the repairs made.
|
|
222
|
+
|
|
223
|
+
### What it detects and repairs
|
|
224
|
+
|
|
225
|
+
| Issue | Typical source | Repair |
|
|
226
|
+
|---|---|---|
|
|
227
|
+
| `lost_glyphs`: NUL, U+FFFD, private-use or `(cid:N)` for unmapped glyphs | pypdf, pdfminer (Indic, Burmese, Khmer, math) | none possible: switch extractor or OCR; never hidden |
|
|
228
|
+
| `visual_order_vowels`: pre-base vowel signs (ि, ে, ெ…) before their consonant | pypdf, pdfminer | reorder into reading order |
|
|
229
|
+
| `doubled_vowel_signs`: a letter's marks repeated (ाा, ംം) | PyMuPDF | collapse the repeat |
|
|
230
|
+
| `orphan_marks`: vowel signs separated from their letter | docling-parse, pdfminer | rejoin |
|
|
231
|
+
| `presentation_forms`: Arabic/Hebrew glyph codes instead of letters | pypdf, pdfminer | map to letters |
|
|
232
|
+
| `reversed_rtl`: right-to-left lines in visual order | pdfminer | reverse, only if that makes real words |
|
|
233
|
+
| `cjk_fragmented`, `cjk_lookalikes`: one character per line, spaces between characters, Kangxi radicals (⼈ for 人) | vertical text, pypdf | rejoin; map to standard characters |
|
|
234
|
+
| `wrap_breaks`: line breaks inside words in scripts without spaces | all extractors | join full-width lines only |
|
|
235
|
+
| `split_words`: fragments that only form a word when joined | docling-parse | join into known words only |
|
|
236
|
+
| `impossible_clusters`: Thai/Lao vowels or tone marks without their consonant | pdfminer; an OCR model reading another script | rejoin split marks; otherwise switch OCR model |
|
|
237
|
+
| `mixed_script_garble`, `vowel_clash`, `symbol_garble`: broken font mappings | pre-Unicode fonts | none possible: OCR |
|
|
238
|
+
| `hyphen_breaks`, `glued_words`, `letter_spaced`: `infor- mation`, `Achainofthought`, `S U M M A R Y` | all extractors | join or split into known words only; compounds in German, Dutch or Finnish are never split |
|
|
239
|
+
| `ligatures`, `hidden_chars`: fi fl, soft hyphens, zero-width characters | many tools | expand / remove |
|
|
240
|
+
| `few_known_words`, `ocr_low_confidence`: garbled text or the wrong OCR model | legacy fonts, OCR | try other models; report |
|
|
241
|
+
| `no_text_layer`, `engine_returned_nothing` | scans; an extractor that fails silently | OCR; use another extractor |
|
|
242
|
+
|
|
243
|
+
Thresholds come from calibration: on clean text in **388 languages** (`bench/calibrate.py`) the structural signals
|
|
244
|
+
stay at zero.
|
|
245
|
+
|
|
246
|
+
## Results
|
|
247
|
+
|
|
248
|
+
Every number here is produced by the benchmark in `bench/` and can be reproduced ([Development](#development)).
|
|
249
|
+
Quality is the share of the text a search index would see intact: word F1 for scripts written with spaces,
|
|
250
|
+
adjacent-character F1 for scripts without (Thai, Lao, Khmer, Burmese, Chinese, Japanese).
|
|
251
|
+
|
|
252
|
+
### Real PDFs: 29 documents from the UN Human Rights Office
|
|
253
|
+
|
|
254
|
+
The Universal Declaration of Human Rights as published by OHCHR, in PDFs made over decades with about 20 different
|
|
255
|
+
tools; 11 are scans without a text layer and several use pre-Unicode fonts.
|
|
256
|
+
|
|
257
|
+
| Reader | Mean quality | Documents ≥ 0.90 |
|
|
258
|
+
|---|---|---|
|
|
259
|
+
| pypdf / pdfminer / docling-parse / PyMuPDF | 0.34–0.35 | 8/29 |
|
|
260
|
+
| the same, plus TrueGlyph's repairs | 0.37–0.38 | 9/29 |
|
|
261
|
+
| **TrueGlyph** (repair + extractor choice + OCR) | **0.782** | **14/29** |
|
|
262
|
+
|
|
263
|
+
| Document | Best plain extractor | **TrueGlyph** | Trust | How |
|
|
264
|
+
|---|---|---|---|---|
|
|
265
|
+
| Vietnamese (legacy font) | 0.004 | **0.998** | high | OCR with the Vietnamese model, chosen by contest |
|
|
266
|
+
| Chinese (a space between all characters) | 0.155 | **0.979** | high | text layer, spaces removed |
|
|
267
|
+
| Hebrew (dingbat font) | 0.000 | **0.976** | high | OCR |
|
|
268
|
+
| Georgian (legacy font) | 0.002 | **0.958** | high | OCR |
|
|
269
|
+
| Hindi | 0.000 | **0.957** | high | OCR |
|
|
270
|
+
| Marathi | 0.549 | **0.947** | high | OCR, checked against the bundled Marathi word list |
|
|
271
|
+
| Khmer (legacy font) | 0.000 | **0.837** | low | OCR with the Khmer model, chosen by contest |
|
|
272
|
+
| Bengali (typed title over a scanned page) | 0.000 | **0.795** | high | OCR under the title |
|
|
273
|
+
| Thai (scan) | 0.000 | **0.778** | medium | OCR |
|
|
274
|
+
| Burmese (pre-Unicode font) | 0.000 | **0.749** | low | OCR, page re-read as one block |
|
|
275
|
+
| English, French, German, Spanish, Russian, Greek, Japanese, Korean | 0.94–0.99 | unchanged | high | text layer, untouched |
|
|
276
|
+
|
|
277
|
+
Not recovered, and reported as such:
|
|
278
|
+
|
|
279
|
+
| Document | TrueGlyph | Trust | Why |
|
|
280
|
+
|---|---|---|---|
|
|
281
|
+
| Urdu (Nastaliq scan) | 0.083 | low | no Tesseract model reads Nastaliq at this quality |
|
|
282
|
+
| Malayalam | 0.259 | low | scanned at about 60 dpi in the old Malayalam script |
|
|
283
|
+
| Tamil | 0.327 | high | the OCR text is clean; the benchmark's reference is a different Tamil translation |
|
|
284
|
+
| Armenian | 0.640 | high | same for every reader; the reference is a different translation |
|
|
285
|
+
|
|
286
|
+
**Are the trust levels honest?** Each raw extractor reading (116) was judged without the reference: of 84 damaged
|
|
287
|
+
readings, **80 were flagged**, including all 73 badly damaged ones; the 4 misses are the Armenian translation
|
|
288
|
+
mismatch. 4 of 32 intact readings were flagged `medium` (Japanese with line breaks inside words).
|
|
289
|
+
|
|
290
|
+
### Synthetic set: known text, 30 documents, 24 scripts
|
|
291
|
+
|
|
292
|
+
The same declaration in 30 languages rendered to PDF by Chromium, including vertical Japanese and Chinese and four
|
|
293
|
+
right-to-left languages.
|
|
294
|
+
|
|
295
|
+
| Reader | Mean quality | Worst document | Documents ≥ 0.90 |
|
|
296
|
+
|---|---|---|---|
|
|
297
|
+
| pypdf | 0.673 | 0.000 | 13/30 |
|
|
298
|
+
| pdfminer | 0.610 | 0.000 | 11/30 |
|
|
299
|
+
| docling-parse | 0.814 | 0.000 | 16/30 |
|
|
300
|
+
| PyMuPDF (best single extractor) | 0.875 | 0.000 | 23/30 |
|
|
301
|
+
| **TrueGlyph** | **0.978** | **0.714** | **29/30** |
|
|
302
|
+
|
|
303
|
+
| Trust assigned (120 raw readings) | Readings | Mean true quality | Actually damaged (< 0.90) |
|
|
304
|
+
|---|---|---|---|
|
|
305
|
+
| high | 41 | 0.985 | 2% |
|
|
306
|
+
| medium | 15 | 0.925 | 27% |
|
|
307
|
+
| low | 64 | 0.545 | 81% |
|
|
308
|
+
|
|
309
|
+
All 24 badly damaged readings were flagged; 56 of 57 damaged readings were flagged.
|
|
310
|
+
|
|
311
|
+
### English: 24 recent arXiv papers (628 pages)
|
|
312
|
+
|
|
313
|
+
Every paper had words split by line-break hyphenation (about 119 per paper: `imple- mentation`), and PyMuPDF or
|
|
314
|
+
pdfminer left placeholders for unmapped symbols in 21–22 of them. TrueGlyph joins hyphenated words only into real
|
|
315
|
+
words (`well-known`, `k-means` stay as they are) and raises **no false alarms**: reference lists full of names and
|
|
316
|
+
code listings stay `high`; the 4 pages it flags really lost characters. A clean 26-page paper is checked in under a
|
|
317
|
+
second.
|
|
318
|
+
|
|
319
|
+
## Limitations
|
|
320
|
+
|
|
321
|
+
- **OCR quality is Tesseract's.** TrueGlyph reports OCR confidence and marks unsure pages `low`; it does not hide
|
|
322
|
+
OCR errors. Two scans are beyond it. Both were also tried with every available Tesseract model, other page
|
|
323
|
+
segmentations, image upscaling and a second OCR engine (EasyOCR: worse on the Urdu, no Malayalam model): Urdu
|
|
324
|
+
printed in Nastaliq, and Malayalam scanned at about 60 dpi in the old script. Both stay `low`: flagged, not
|
|
325
|
+
recovered.
|
|
326
|
+
- **Word lists.** Words are checked with frequency lists (wordfreq) for about 40 languages and with dictionaries
|
|
327
|
+
taken from Tesseract's models for 17 more: Marathi, Nepali, Malayalam, Kannada, Telugu, Sinhala, Gujarati,
|
|
328
|
+
Punjabi, Odia, Assamese, Amharic, Georgian and Armenian, plus Thai, Lao, Khmer and Burmese, whose text is first
|
|
329
|
+
split into dictionary words because they are written without spaces. Those dictionaries have no frequencies and
|
|
330
|
+
include word fragments, so they flag garbled text and split words but do not rank readings. Chinese, Japanese and
|
|
331
|
+
Korean are checked by script rules only (`checks: structural`).
|
|
332
|
+
- **Trust levels are calibrated heuristics, not probabilities.** Measured honesty is shown above.
|
|
333
|
+
- **Speed:** text-layer pages take milliseconds to a fraction of a second. OCR with Tesseract's best models takes
|
|
334
|
+
seconds per page (pages run in parallel). When the script of a scan is unclear, a model contest adds a one-off
|
|
335
|
+
cost per document; it tries the likeliest script first and stops at a clear winner.
|
|
336
|
+
- **Not a layout tool:** TrueGlyph checks and fixes text, not reading order of columns, tables or figures.
|
|
337
|
+
- Benchmark references are not perfect: some UDHR translations differ from the UN PDFs (Tamil, Armenian), and real
|
|
338
|
+
PDFs include headers and page numbers, so compare readers with each other rather than with 1.0.
|
|
339
|
+
|
|
340
|
+
## Configuration
|
|
341
|
+
|
|
342
|
+
| Setting | Purpose |
|
|
343
|
+
|---|---|
|
|
344
|
+
| `TRUEGLYPH_TESSDATA` | folder with Tesseract models (`*.traineddata`); default `./.tessdata`, then Tesseract's own |
|
|
345
|
+
| `TRUEGLYPH_TESSERACT` | path to the `tesseract` executable if it is not on `PATH` |
|
|
346
|
+
| `--lang` / `lang=` | ISO 639-1 language hint: picks the OCR model and word list directly |
|
|
347
|
+
| `--no-ocr` / `ocr=False` | never run OCR (scanned pages then come back as `none`) |
|
|
348
|
+
|
|
349
|
+
Bad input gets a plain message, not a stack trace: a missing, empty, damaged or password-protected PDF, or a page
|
|
350
|
+
number that does not exist (`trueglyph: error: report.pdf has 3 page(s); there is no page 5.`).
|
|
351
|
+
|
|
352
|
+
## Development
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
git clone https://github.com/jishnucz/TrueGlyph && cd TrueGlyph
|
|
356
|
+
pip install -e ".[dev]" # editable install with pytest
|
|
357
|
+
pytest # 47 tests, including an end-to-end MCP session and OCR when Tesseract is present
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
Reproduce the benchmark:
|
|
361
|
+
|
|
362
|
+
```bash
|
|
363
|
+
python bench/build.py # synthetic PDFs (needs Microsoft Edge to render)
|
|
364
|
+
python bench/realset.py # real PDFs from the UN Human Rights Office
|
|
365
|
+
python bench/extract_all.py && python bench/extract_all.py real
|
|
366
|
+
python bench/run.py # -> bench/results/RESULTS_synthetic.md
|
|
367
|
+
python bench/run.py real --ocr # -> bench/results/RESULTS_real.md
|
|
368
|
+
python bench/calibrate.py # signal behaviour on clean text in 388 languages
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
## Why this exists
|
|
372
|
+
|
|
373
|
+
| Evidence | Source |
|
|
374
|
+
|---|---|
|
|
375
|
+
| docling's own check for broken text layers "look[s] at Latin letters only, so text in other scripts cannot be flagged" | [docling PR #4654](https://github.com/docling-project/docling/pull/4654) |
|
|
376
|
+
| Open extraction bugs for Vietnamese, Thai, Hindi (words split at vowel signs) and vertical Japanese (a space between every character) | [docling #3170](https://github.com/docling-project/docling/issues/3170), [#4672](https://github.com/docling-project/docling/issues/4672) |
|
|
377
|
+
| A government problem statement: thousands of pages a day "in both English and Malayalam, sometimes in bilingual hybrids" | Smart India Hackathon 2025, SIH25080 (Kochi Metro) |
|
|
378
|
+
| Measured here: the same text through four extractors, 24 scripts | [Results](#results) |
|
|
379
|
+
|
|
380
|
+
TrueGlyph came out of a search for an unmet need in the AI-agent ecosystem across more than 60 candidate areas. This
|
|
381
|
+
one was found by testing extractors and measuring where they fail, then confirmed by the independent sources above.
|
|
382
|
+
|
|
383
|
+
## Contributing
|
|
384
|
+
|
|
385
|
+
The most useful contribution is a PDF that TrueGlyph reads wrong or rates wrongly: open an
|
|
386
|
+
[issue](https://github.com/jishnucz/TrueGlyph/issues) with the file (or a link), the language, and what the page
|
|
387
|
+
really says. Pull requests are welcome; run `pytest` first. Each new check needs calibration on clean text
|
|
388
|
+
(`bench/calibrate.py`) so it does not raise false alarms.
|
|
389
|
+
|
|
390
|
+
## License
|
|
391
|
+
|
|
392
|
+
MIT. The bundled word lists in `src/trueglyph/wordlists/` come from the Tesseract OCR models (Apache-2.0; see the
|
|
393
|
+
NOTICE file there). Benchmark PDFs are derived from the Universal Declaration of Human Rights (public domain / UN)
|
|
394
|
+
and OHCHR publications.
|