Check loanword

From ayutaz/piper-plus · View interactive version

Check loanword is an AI agent skill from the GitHub repository ayutaz/piper-plus. ZH-EN code-switching loanword の同期と forward-compat を 1 コマンドで検査。`docs/spec/loanword-mirrors.toml` に定義された runtime 10 mirror と fixture 8 mirror を確認する。

How to use this skill

Skill file

ZH-EN Loanword Consistency Check

ZH-EN code-switching (Issue #384) で使う loanword 辞書 (zh_en_loanword.json) の同期チェック。Python source を 唯一の真実 とし、docs/spec/loanword-mirrors.toml の 10 runtime mirror + 8 fixture mirror が一致することを保証する。

何をチェックするか

docs/reference/zh-en-loanword/README.md の不変条件:

  1. 10 mirror byte-for-byte sync — Python source と以下の mirror が SHA256 一致:
  1. Schema validation — Python の _load_loanword_data と同じ書式 ('<section>.<key>' must be list[str]) でエラーを出すこと
  2. 8 fixture mirror sync — tests/fixtures/g2p/zh_en_loanword_matrix.json と以下の mirror が一致:
  1. Forward-compat (YELLOW-5) — 各ランタイムの loader が schema_version: 2 未来の追加フィールドを silent ignore すること

実行ステップ

1. ローカルで sync 状態を確認

python scripts/check_loanword_consistency.py

期待: OK All 17 mirror(s) in sync across 2 group(s) で終了 (exit 0)。

2. drift 発見時は自動修復

Python source を canonical とした 一方向コピー で復元:

python scripts/check_loanword_consistency.py --diff   # 差分確認 (dry-run)
python scripts/check_loanword_consistency.py --fix    # 10 mirror + 8 fixture を Python source に揃える

注意: Mirror を直接編集しても --fix で上書きされる。JSON 変更を提案する場合は 必ず Python source (src/python/g2p/piper_plus_g2p/data/zh_en_loanword.json) を編集 すること。

3. Schema validation のみ確認 (CI 用)

python scripts/check_loanword_consistency.py --schema-only

4. 各ランタイムの forward-compat loader test を回す

各ランタイムに *Loader*Schema*V2* 系の test が存在し、未来の schema_version: 2 を受理することを pinning している:

# Rust (両 crate)
cd src/rust && cargo test test_zh_en_loader_accepts_unknown_fields_in_schema_v2

# Go
cd src/go && go test ./phonemize/... -run TestLoaderAcceptsUnknownFieldsInSchemaV2

# C#
cd src/csharp && dotnet test --filter "FullyQualifiedName~Loader_AcceptsUnknownFieldsInSchemaV2"

# WASM
node --test src/wasm/g2p/test/test-chinese-zh-en.js  # forward-compat assertion 含む

5. CI workflow が green か確認

gh workflow view "ZH-EN Loanword Sync Gate" --branch <branch>

json-sync job (5 分以内) が PASS していれば OK。

確認すべき事項

トラブルシューティング

| 症状 | 対処 |

|------|------|

| MISMATCH src/.../zh_en_loanword.json | --fix で復元、または Python source の意図しない変更を revert |

| MISSING src/.../zh_en_loanword.json | --fix で作成、または該当ランタイム実装が未着手 (Phase 6a 想定なら --allow-missing を一時利用) |

| 'acronyms.GPS' must be list[str] | Python source で値型が間違っている。["ji4", "pi4", "ai1", "si4"] の形式に修正 |

| FIXTURE OUT OF SYNC | tests/fixtures/g2p/zh_en_loanword_matrix.json を更新後 --fix で 8 fixture mirror に展開 |

| Windows で sha256 不一致が常時出る | .gitattributes の *.json text eol=lf で CRLF 強制 LF。再正規化: git rm --cached <file> && git add <file> |

関連ドキュメント

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.