Skip to content

Check your own OCR or TEI text against a printed edition

An OCR or TEI text of a classical book: check its passages against a printed edition with shamela_verify_quote. What the check can and cannot do.

On this page

If you have an OCR or TEI text of a classical book, you can check passages from it against a printed edition with shamela_verify_quote. The tool does not read your file, and it is not an OCR engine. It checks whether a passage’s words are printed on a page of a book in the Shamela library, and where.

What the check can and cannot do

  • It covers the Shamela library only. A printed edition the library does not hold cannot be checked against.
  • It does not read your file. You send it one passage at a time, as text.
  • It is not an OCR engine. It does not read scanned images or correct recognition errors.
  • Not found is about the scope. It means no page in the searched scope carries those words in that order. It never means the passage is false.
  • It is not a ruling. A found passage shows where the words are printed. It does not show that the passage is authentic or soundly attributed.

Check 20 passages

  1. Choose 20 passages from your text, each with at least three Arabic words, and save them in passages.txt, one per line.
  2. Find the edition’s bookId with shamela_find. If it finds no match, that is not proof the library lacks the book.
  3. Run the script below. It calls shamela_verify_quote once per passage and waits between calls.
  4. Read each result: verdict, then exact, matchedIn, volume, printedPage and sourceUrl. The sourceUrl opens the page in the Maktabah reader.

The script

The keyless limit is 10 calls a minute and 200 a day per IP address, so the script waits 7 seconds between calls. Twenty passages take about 140 seconds. For more passages, use a free key: see MCP API key and bearer token setup.

import json
import time
import urllib.request

URL = "https://qurangallery.com/mcp/shamela"
HEADERS = {"Content-Type": "application/json", "Accept": "application/json"}
BOOK_ID = 1681  # replace with your edition's bookId from shamela_find
passages = [line.strip() for line in open("passages.txt", encoding="utf-8") if line.strip()]

for n, quote in enumerate(passages, start=1):
    args = {"quote": quote, "bookId": BOOK_ID, "limit": 1}
    body = {"jsonrpc": "2.0", "id": n, "method": "tools/call", "params": {"name": "shamela_verify_quote", "arguments": args}}
    req = urllib.request.Request(URL, json.dumps(body).encode("utf-8"), HEADERS)
    with urllib.request.urlopen(req, timeout=40) as resp:
        reply = json.load(resp)["result"]
    data = reply.get("structuredContent") or json.loads(reply["content"][0]["text"])
    m = (data["matches"] or [{}])[0]
    print(n, data["verdict"], m.get("exact"), m.get("matchedIn"), m.get("volume"), m.get("printedPage"))
    time.sleep(7)  # keyless limit: 10 calls a minute

A tool error, such as a passage under three Arabic words or a bad bookId, names the fix; the script stops on it, so correct the passage and run again. If the server refuses calls for rate limits, wait a minute and run the script again.

What a reply looks like

Two passages from a test run, printed by the script above. The first was typed with diacritics; the second was typed without them.

1 found True body 1 6
2 found False body 1 6

Both are found on printed page 6 of volume 1 in book 1681 (صحيح البخاري - ط السلطانية). The second has exact set to false, because the page carries 30 more diacritic marks than the typed passage and its punctuation differs; the differences field says so. Found with exact false means the same words in another spelling, not a miss. Your OCR text may come out exact: false for the same reasons, so read differences before you decide.

When a passage is not found

This reply is for a passage searched in the hadith-primary scope, which holds no page with those words in that order. The normalisation list is shortened here.

{
	"verdict": "not_found",
	"matches": [],
	"searched": { "scope": "hadith-primary", "normalisation": ["…"] },
	"note": "Not found in the searched scope: the "hadith-primary" scope (The eight primary hadith collections, edition-pinned). This says only that no page there carries these words in this order; it does not mean the quotation is false, and it may be in a book, edition or wording outside that scope. Try another scope or a bookId, or a shorter distinctive part of the wording. This is not a ruling on the quotation."
}

For your own text, widen the scope, give a bookId, or search a shorter part of the passage that has no OCR error in it. A not-found result is a statement about the scope that was searched, not about your text.

Formats and sources people ask about

We do not integrate with any of these projects, and the server does not read their files. Each row gives one fact from the project’s own page, with the date we read it, and what our server does for someone who uses that tool.

Format or projectWhat its own page saysSource, read 2 December 2026What our server does
OpenITI“a multi-institutional effort to construct the first machine-actionable scholarly corpus of premodern Islamicate texts”, published as versioned releases on GitHub and Zenodoopeniti.org; release READMENothing with the file itself; check a passage with shamela_verify_quote.
TEI/XML“an international and interdisciplinary standard used by libraries, museums, publishers, and academics to represent all kinds of literary and linguistic texts”TEI on GitHubNothing with the file itself; check a passage with shamela_verify_quote.
Kraken“a turn-key OCR system optimized for historical and non-Latin script material”kraken on GitHubNothing with the file itself; check a passage with shamela_verify_quote.
eScriptorium“A Digital Text Production Pipeline for Print and Handwritten Texts using machine learning techniques”eScriptoriumNothing with the file itself; check a passage with shamela_verify_quote.
Transkribusdescribes itself as “the operating system for written heritage”, built and owned by a community of stakeholderstranskribus.orgNothing with the file itself; check a passage with shamela_verify_quote.
PyMuPDF“a layout-aware document engine for AI and a feature-rich Python toolkit for extracting, rendering and editing PDFs and other documents”PyMuPDF documentationNothing with the file itself; check a passage with shamela_verify_quote.
CAMeL Tools“A suite of Arabic natural language processing tools developed by the CAMeL Lab at New York University Abu Dhabi”CAMeL Tools on GitHubNothing with the file itself; check a passage with shamela_verify_quote.
Hugging Face vectors“The Hugging Face Hub hosts Git-based repositories, which are version-controlled folders that can contain all your files.”Hub documentationNothing with the file itself; check a passage with shamela_verify_quote.

Next steps

Questions

Can I upload my own books to the Shamela MCP server?

No. It searches a fixed library and cannot ingest your texts or files.

Can the server check my OCR text?

It checks passages one at a time against a printed edition that is in the Shamela library, with shamela_verify_quote. It does not read your file, and it is not an OCR engine.

What does not_found mean for a passage from my OCR text?

No page in the searched scope carries those words in that order. OCR errors can cause this, so try a shorter, clean part of the passage. It does not mean your text is false.

Is there a Hugging Face dataset of your books?

No. We publish no dataset of the books.

Does a found result prove my text is correct?

No. It shows where the words are printed in the edition the library holds, and whether they match exactly. It is not a ruling on the passage.

Which edition does the check use?

The edition the library holds for the bookId you give, or the whole library if you give none. If your printing is not in the library, the check cannot compare against it.

Edit this page on GitHub