Skip to main content

JP Kansuji Guard

Turn kanji numerals in Japanese text into digits (三億五千万円 → 350000000円) without breaking names, places and idioms (一宮市, 五十嵐, 三菱, 一石二鳥 stay as they are).

A numeral normalizer that converts every kanji numeral also converts the ones inside proper nouns and words: 一宮市 becomes 1宮市, 統一 becomes 統1. Search indexes, RAG chunks and extracted fields then carry the damage. One normalizer's own documentation warns that a name like 加藤一二三 can be misconverted (jpnorm).

This package converts a numeral only where the text says it is a number:

  • it is followed by a unit or counter (円, 人, 年, 条, 階, %, …), or it is a 万/億/兆 amount
  • it is not part of a known name, place, company, word or idiom (252 entries, hand-written)
  • if the meaning depends on the reading (十分 = "enough" or "10 minutes", 一時, 一番, 二三人 = "2 or 3 people") or the amount is approximate (数万円), the text is kept and the span is returned in flags

It also reads formal numerals (金壱萬円也 → 金10000円也) and mixed forms (1億2,300万円 → 123000000円).

Python standard library only. No network. MIT.

Bench

data/kansuji_guard_bench_v1.jsonl has 126 cases: 48 to convert, 69 to keep (places, names, companies, words, idioms) and 9 ambiguous spans to leave alone. Scoring is exact match of the whole output. The cases were written for this repository by its authors (no third-party text) and are released under the same MIT license.

Converter Score Convert Keep Ambiguous
naive baseline in this repo (convert every numeral) 47/126 (37.3%) 44/48 2/69 1/9
kansujiguard 0.1.0 126/126 (100%) 48/48 69/69 9/9

Read the second row with care: the rules and the cases were written together, so 100% here says the rules match this bench, not that they are complete. New failing cases are the most useful contribution (open an issue with the sentence and the output you expected).

Score your own converter (a function str -> str):

python -m kansujiguard.bench --module yourpkg.yourmodule:convert

Use

python -m kansujiguard notes.txt          # converted text to stdout, flags to stderr
python -m kansujiguard notes.txt --json   # {"text", "changes", "kept", "flags"}
from kansujiguard import convert, parse_number
convert("三菱の売上は三億円、十分な利益")["text"]
# '三菱の売上は300000000円、十分な利益'   (十分 is flagged, not converted)
parse_number("1億2,300万")
# 123000000

As an MCP server (for AI agents)

{"mcpServers": {"jp-kansuji-guard": {"command": "python", "args": ["-m", "kansujiguard.server"], "cwd": "/path/to/jp-kansuji-guard"}}}
Tool Input Returns
jp_kansuji_convert text text, changes (start/end/before/after/value/reason), kept, flags
jp_kansuji_parse numeral value (int) or null with error

Both tools are read-only.

Limits

  • The word list is hand-written. Names and places not on it can still be converted when a counter follows them
  • Decimals (三・五, 三点五) and ranges (三〜五人) are not converted
  • Output digits have no thousands separators
  • Tests: python -m unittest discover -s tests (13 tests)

日本語

文中の漢数字を数字に直します。ただし、単位・助数詞が続くときや 万/億/兆 の金額など、数だと分かる所だけ。地名・人名・社名・熟語(一宮市・五十嵐・三菱・統一・一石二鳥)は直しません。読み方で意味が変わるもの(十分・一時・一番・二三人)やおおよその数(数万円)は直さずに flags で知らせます。

  • 大字(壱・弐・参・拾・萬)、全角数字、1億2,300万 のような混ざった書き方にも対応
  • 判定テスト集126問つき。自分の変換関数も採点できます
  • 外部通信なし・Python標準ライブラリのみ・MIT。AIエージェントからは MCP サーバー(python -m kansujiguard.server)で使えます

Metadata

Release files for jp-kansuji-guard 0.1.1

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-kansuji-guard 0.1.1
File Size Uploaded Provenance Actions
jp_kansuji_guard-0.1.1.tar.gz 16.5 kB Without provenance Details for jp_kansuji_guard-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jp-kansuji-guard 0.1.1
File Interpreter ABI Platform Actions
jp_kansuji_guard-0.1.1-py3-none-any.whl Python 3 none any Details for jp_kansuji_guard-0.1.1-py3-none-any.whl

Total release size: 34.0 kB

Release files / jp_kansuji_guard-0.1.1.tar.gz

Download URL jp_kansuji_guard-0.1.1.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2413e14955fd8f4b4dd5b8ef3ee3ac5f0892002c1c4fd89c6ee9738e6af8abb0
BLAKE2b-256 checksum
How to use checksums
f02266b349e2343f8307fd230075fd8befb488299272f4a9b4a6e1dff3215cdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / jp_kansuji_guard-0.1.1-py3-none-any.whl

Download URL jp_kansuji_guard-0.1.1-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ea16570a39f45da877a55307af88ea330a090becc6c9ba896046e2d855e9059
BLAKE2b-256 checksum
How to use checksums
829567374d8d41686c3087363dbe3fce2f10533ae54e5980c54dc45715ad258c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for jp-kansuji-guard 0.1.1

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.1 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