-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aggregate ○○町 pattern #152
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
町ありと町なし両方ある自治体あるか、確認してもらってもいいですか(japansese-addressesのデータでいいと思います)?もしあるとしたら、この処理を除外しないといけないかもしれないね。。
確認します。 それから実装について、当初正規表現で対応しようと考えたのですが、例えば |
ありがとうございます! |
あ、はい、そうですね。town に 「○○町」に加えて「○○」を追加して正規表現を作る方法で実装しています。当初は正規表現のパターン修正だけで対応できると考えていたのですができなかったので town を増やす方法にしました。 それから、ちょっと信じ難いのですが、「○○町」と「○○」が共存しているケースがかなりあります。本当に存在するのか、 japanese-addresses でデータが重複しているのか、調べ中です。 例:
japanese-addresses のデータの組み合わせのうち、 936 ペア検出。 |
さくっと確認したんだけどありますね。。なるほど。 |
ちなみにこういうのもありました。
|
84e677d
to
d97e6de
Compare
町丁目の組み合わせテストの結果はこちらにメモしておきました。 japanese-addresses は小字のデータを持っている場合があり、その場合は town カラムの重複が増えます。実質的に町丁目が重複しているケースは 223 件でした。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
確認お願いします
test/main.test.ts
Outdated
expect(res).toStrictEqual({"pref": "広島県", "city": "三原市", "town": "幸崎久和喜", "addr": "789-1234", "level": 3, "lat": 34.348481, "lng": 133.067756}) | ||
}) | ||
|
||
test('広島県三原市幸崎町久和喜789-1234', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これはどっちか町あり・町なしのはずなのかな?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このケースですが、幸崎久和喜
と 幸崎町久和喜
のどちらも存在します。
テストケースが適当すぎたので、番地だけ変えました。545492c
現時点では町あり・町なしの両方で別々に正規化されるべきかと思います。
例えばこの住所では、住居表示住所の導入段階によって便宜的に住所の表記が異なっているだけのため、番地はそれぞれの町丁目で重複していないはずです。なので、将来的に番地の情報を持てるようになったときに町あり・町なしでも寄せられるようにできるといいかと思いました。
src/lib/cacheRegexes.ts
Outdated
// 町丁目が「町」で終わるケースへの対応 | ||
// 通常は「○○町」のうち「町」の省略は許容し、同義語として扱うが、まれに自治体内に「○○町」と「○○」が共存しているケースがある。 | ||
// この場合は町の省略は許容せず、住所は書き分けられているものとして正規化を行う。 | ||
const townsEndWithCho = towns.filter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
towns[i].town
の Set をこの時点で作れば毎回のtowns[i].town ループを節約できるかな?
townSet = new Set(towns.map(x => x.town))
tows.filter(town => townSet.has(town.town.replace('/町$/')))
的な感じで
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
確かに。ありがとうざいます。こちらで修正しました。
867e3ee
src/lib/cacheRegexes.ts
Outdated
for (let i = 0; i < towns.length; i++) { | ||
const townName = towns[i].town | ||
if (townName.indexOf('町') === -1) continue | ||
if (targetTownName.replace(/町/g, '') === townName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは /町$/
にするか /町/g
にするか悩ましいと思うけど、どっちかにする理由をコメントで残してもらってもいいですか? 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ありがとうございます。こちらで対応しました 🙇
fe93e66
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あ、こちらもでした。町を含む町丁目の判定が直っていませんでした。
町で終わる -> 町を含む に一貫して修正しました。
e982f24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
テストで検出できていない時点で何か変な気がするのでもうちょっと確認します。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
テストを追加しました。
それから、 十六町1丁目などの漢数字と町を含むケースで壊れることがわかりましたので、対応しました。
acbc8b8
9d247ff
to
fe93e66
Compare
adb332c
to
9145a24
Compare
acbc8b8
to
fc98104
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これで行きましょうか
町丁目が町で終わるパターンへの対応。「○○町」の町が省略されていたとしても正規化する。