Skip to main content

JP OCR Date Fix

Repair Japanese dates that OCR broke (今和6年3月15曰 → 令和6年3月15日), and only when the calendar confirms the result.

OCR often misreads the era name 令和 as 今和 or 合和, 日 as 曰, and 0/1 as O/l. One public test of a document parser on Japanese PDFs found the 令→今 error on roughly all OCR-processed pages (source). An AI that reads that text then extracts a date that does not exist, or guesses.

This tool fixes those spans with fixed rules and checks each result:

  • the span must have a full date shape: era + year + 年 + month + 月 (+ day + 日), or YYYY年M月(D日)
  • characters are mapped through a fixed look-alike table (今合命冷→令, 戒威→成, 照→昭, 曰目→日, O→0, l|→1, …)
  • the repaired date must exist and fall inside its era (平成31年4月30日 is valid, 平成31年5月1日 is not)
  • if it cannot be confirmed, the text is left as it is and the span is returned in flags

Python standard library only. No network. MIT.

Use

python -m jpocrdate scan.txt            # repaired text to stdout, changes to stderr
python -m jpocrdate scan.txt --json     # {"text", "changes", "flags"}
from jpocrdate import fix_text, check_date
check_date("平戒31年4月30日")
# {'input': '平戒31年4月30日', 'status': 'fixed', 'date': '平成31年4月30日', 'iso': '2019-04-30'}
check_date("平成31年5月1日")
# {'input': '平成31年5月1日', 'status': 'invalid', 'reason': 'date is outside 平成'}

As an MCP server (for AI agents)

{"mcpServers": {"jp-ocr-date-fix": {"command": "python", "args": ["-m", "jpocrdate.server"], "cwd": "/path/to/jp-ocr-date-fix"}}}

Tools (read-only):

Tool Input Returns
jp_ocr_fix_dates text repaired text, changes (start/end/before/after/iso), flags
jp_ocr_check_date date status: ok / fixed / invalid / not_a_date, date, iso

Scope and limits

  • Eras: 明治, 大正, 昭和, 平成, 令和. Abbreviations such as R6.3.15 or H31/4/30 are not handled yet
  • Only dates are repaired. Company names and amounts are out of scope (see JaPOC for company-name correction)
  • The look-alike table is hand-made from common OCR confusions. It is not learned from data, and it will miss some errors
  • Tests: python -m unittest discover -s tests (18 tests)

日本語

OCRで崩れた日本の日付(今和6年3月15曰 など)を、決まったルールで直します。直した結果が暦に実在し、元号の期間内にあるときだけ直します。確かめられないものは直さずに flags で知らせます(推測しません)。

  • 対応: 明治・大正・昭和・平成・令和、元年、全角数字、年月だけの日付
  • 外部通信なし・Python標準ライブラリのみ・MIT
  • AIエージェントからは MCP サーバー(python -m jpocrdate.server)として使えます

Metadata

Release files for jp-ocr-date-fix 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jp-ocr-date-fix 0.1.0
File Size Uploaded Provenance Actions
jp_ocr_date_fix-0.1.0.tar.gz 10.7 kB Without provenance Details for jp_ocr_date_fix-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jp-ocr-date-fix 0.1.0
File Interpreter ABI Platform Actions
jp_ocr_date_fix-0.1.0-py3-none-any.whl Python 3 none any Details for jp_ocr_date_fix-0.1.0-py3-none-any.whl

Total release size: 21.1 kB

Release files / jp_ocr_date_fix-0.1.0.tar.gz

Download URL jp_ocr_date_fix-0.1.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
036475797124840f5f04353aa7010dcb077c8d157d9275f4a4683c4d0842cf12
BLAKE2b-256 checksum
How to use checksums
3f41d69d6e2b02b790bb529b27268a720bf9b0f48eac34dae3f850a303b03162
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / jp_ocr_date_fix-0.1.0-py3-none-any.whl

Download URL jp_ocr_date_fix-0.1.0-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3aa43654ca239c38a7938f553688e81cf538b59ccbefe8067b80676db0864bed
BLAKE2b-256 checksum
How to use checksums
e753129ab08d088a827c0175f427b8d1c8f63e289405262686646f525317bf43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for jp-ocr-date-fix 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page