郵便番号から住所をオフライン変換できるようにする - #368
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c279f4da1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| guard let postalCode = normalizedPostalCode(matching: reading) else { | ||
| return [] | ||
| } | ||
| return addressIndex[postalCode] ?? [] |
There was a problem hiding this comment.
Move postal database parsing off the main actor
When any validly shaped seven-digit input first reaches updateRawCandidate—including an unknown code or a phone-number prefix—this lookup synchronously initializes addressIndex on the @MainActor, reading and parsing all 124,522 TSV rows before returning. Running this exact parser against the bundled file took about 0.43 seconds and constructed 120,717 dictionary entries, so the triggering keystroke can visibly freeze the input method; load the index asynchronously or ship a structure that supports direct lookup without parsing the complete dataset on the input path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🟡 Changes recommended
SegmentsManagerの候補生成ホットパスに不要なSet構築が入りパフォーマンス劣化が確認できるため。
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
日本郵便の全国町域データをアプリに同梱し、郵便番号(全角数字・複数の区切り記号を含む)から住所候補をオフラインで提示できるようにするPRです。入力時に通信を不要にしつつ、既存の入力候補(元の郵便番号)も保持する形で変換候補へ住所を追加します。
Changes:
- 郵便番号→住所のショートカット(TSV同梱・正規化・パース)をCoreに追加
- SegmentsManagerの候補生成に郵便番号住所候補を差し込み
- データ生成スクリプト/データ説明ドキュメント/テストを追加
File summaries
| File | Description |
|---|---|
| scripts/update-postal-addresses.py | 日本郵便CSV→同梱TSV/説明MDの生成スクリプトを追加 |
| Core/Sources/Core/Resources/postal-addresses.tsv | 郵便番号→住所TSVデータを同梱 |
| Core/Sources/Core/InputUtils/PostalAddressShortcuts.swift | 郵便番号入力の正規化とTSVパース・検索を実装 |
| Core/Sources/Core/InputUtils/SegmentsManager.swift | 変換候補に郵便番号住所候補を挿入 |
| Core/Package.swift | CoreターゲットにTSVリソースを追加 |
| Core/Tests/CoreTests/InputUtilsTests/PostalAddressShortcutsTests.swift | 正規化/パース/同梱データのテストを追加 |
| Core/Tests/CoreTests/InputUtilsTests/SegmentsManagerPostalAddressTests.swift | 候補表示・原文保持・確定動作のE2E寄りテストを追加 |
| docs/postal-address-data.md | 同梱データの出典・加工内容・更新方法を文書化 |
| README.md | 郵便番号から住所入力できる機能の説明を追加 |
Review details
- Files reviewed: 8/9 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| let postalAddresses = PostalAddressShortcuts.addresses(matching: self.composingText.convertTarget) | ||
| var postalTexts = Set(result.mainResults.map(\.text)) | ||
| let postalCandidates = postalAddresses.compactMap { address -> Candidate? in | ||
| guard postalTexts.insert(address).inserted else { | ||
| return nil | ||
| } | ||
| return Candidate( | ||
| text: address, value: -18, | ||
| composingCount: .surfaceCount(self.composingText.convertTarget.count), | ||
| lastMid: MIDData.一般.mid, | ||
| data: [.init(word: address, ruby: self.composingText.convertTarget, cid: CIDData.固有名詞.cid, mid: MIDData.一般.mid, value: -18)], | ||
| isLearningTarget: false | ||
| ) | ||
| } | ||
| result.mainResults.insert(contentsOf: postalCandidates, at: min(5, result.mainResults.count)) |
|
さすがにこの規模の変更はいきなりマージできないです。かつ、機能的にはAzooKeyKanaKanjiConverter側に入れたいです 🙏 |
240-0054や2400054から神奈川県横浜市保土ケ谷区西谷などの住所候補を追加します。全角数字と複数種の区切りに対応します。日本郵便の町域データを同梱するため入力時の通信は不要です。
検証
住所検索・入力表記・不正な番号・候補確定をテスト。約5.3MBのデータ同梱と更新スクリプトを含みます。大口事業所の個別番号は対象外です。
このブランチ単独で
swift test --package-path Core --jobs 4を実行し、Coreの82テストが成功しました。git diff --checkも成功しています。変換範囲と処理負荷
全国TSVはメモリマップし、ソート順を利用した二分探索で一致行だけを解析します。初回入力で全国の辞書を構築しません。全120,717郵便番号で旧パーサーの結果との一致を確認しました。ローカルのDebug相当の検索計測では、初回検索(ファイル読み込み込み)は約2.7msでした(参考値)。住所がない入力では重複チェックを省略し、文節編集中は全入力向けの住所候補を追加しません。