Skip to main content
Glama
jp-ocr-date-fix

jp-ocr-date-fix

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

MCP protocol: the stdio server speaks both the classic initialize flow (2025-06-18 and earlier) and the stateless 2026-07-28 revision (server/discover, per-request _meta). Tested in tests/test_mcp_2026.py. MCP の新しい版(2026-07-28・server/discover)と従来の initialize の両方で動きます。

Related MCP server: Torify — Japanese Locale APIs for AI Agents

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)として使えます

Available Tools

2 tools
jp_ocr_check_dateCheck one Japanese dateA
Read-onlyIdempotent

Check one date string. status: ok (already correct), fixed (OCR look-alikes repaired; see date/iso), invalid (the date does not exist, e.g. 平成31年5月1日; nothing is guessed), not_a_date.

Inputs: date (required).

jp_ocr_fix_datesRepair Japanese dates in OCR textA
Read-onlyIdempotent

Find Japanese dates in OCR output (e.g. '今和6年3月15曰', '2O24年l月5日') and repair OCR look-alike characters. A fix is applied only when the repaired date exists on the calendar and inside the era (令和/平成/昭和/大正/明治). Returns the repaired text, every change with its ISO date, and flags for spans that look like dates but cannot be confirmed. Use it before extracting dates from scanned Japanese invoices, forms or PDFs. OCRで崩れた和暦・日付を暦で確かめて直す。

Inputs: text (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4/5.0

    Scored across 2 tools

    Disambiguation4/5

    The two tools have related but distinguishable purposes: jp_ocr_fix_dates repairs dates in bulk text, while jp_ocr_check_date validates a single date string. There is some conceptual overlap because checking is a subset of fixing, but the descriptions make the batch-vs-single distinction fairly clear.

    Naming Consistency5/5

    Both tools follow the same predictable pattern: a shared jp_ocr_ prefix followed by a verb_noun phrase (fix_dates, check_date). The convention is consistent and readable.

    Tool Count4/5

    Two tools is a small surface, but the server has a narrow, well-defined purpose: repairing and checking Japanese OCR dates. The pair covers bulk and single-date use cases without obvious bloat, though it is on the thin side.

    Completeness4/5

    The surface covers the core workflow of finding/repairing dates and validating individual date strings, including edge cases like nonexistent calendar dates. Minor gaps exist, such as no dedicated pure-extraction or era-conversion tool, but these are not serious for the stated scope.

    Maintenance

    ActivityMaintained
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Japan-specific utilities for AI agents — era ↔ Western year conversion, kanji-to-romaji, postal code lookup, national holidays, kana conversion, and Japanese name splitting. 9 tools, MIT licensed, install via uvx.
      9
      29 PyPI
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Torify gives AI agents the Japanese locale primitives that standard libraries lack — imperial era date conversion (wareki), qualified invoice number validation with NTA registry lookup, corporate number lookup (法人番号), postal code resolution, name romanization (Hepburn), and kanji-to-kana conversion via Yahoo! JLP. 31 endpoints total. No authentication required for MCP. Pay-per-call $0.02/call via
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to perform Japanese business calendar calculations including holiday detection, business day arithmetic, payment date settlement, and deadline management using local data.
      6
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      MCP server for Japanese business days, public holidays, wareki dates, and tax arithmetic, helping AI agents avoid common Japanese date and tax errors.
      7
      MIT