Skip to content
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

Merged
merged 9 commits into from
Feb 2, 2022
Merged

Conversation

kamataryo
Copy link
Contributor

町丁目が町で終わるパターンへの対応。「○○町」の町が省略されていたとしても正規化する。

Copy link
Member

@keichan34 keichan34 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

町ありと町なし両方ある自治体あるか、確認してもらってもいいですか(japansese-addressesのデータでいいと思います)?もしあるとしたら、この処理を除外しないといけないかもしれないね。。

@kamataryo
Copy link
Contributor Author

確認します。

それから実装について、当初正規表現で対応しようと考えたのですが、例えば 京都府京都市東山区大和大路1丁目123-456京都府京都市東山区大和町123-456 が区別がつかないのでこうしました。

@keichan34
Copy link
Member

ありがとうございます!
あー。なるほど。今は確か、townを長い順で正規表現マッチしているので、新しいtownとして配列に追加すると大和大路一丁目大和町区別できるはずですよね?

@kamataryo
Copy link
Contributor Author

あ、はい、そうですね。town に 「○○町」に加えて「○○」を追加して正規表現を作る方法で実装しています。当初は正規表現のパターン修正だけで対応できると考えていたのですができなかったので town を増やす方法にしました。

それから、ちょっと信じ難いのですが、「○○町」と「○○」が共存しているケースがかなりあります。本当に存在するのか、 japanese-addresses でデータが重複しているのか、調べ中です。

例:

  • 福島県須賀川市西川町 vs. 福島県須賀川市西川
  • 茨城県古河市長谷 vs. 茨城県古河市長谷町
  • 茨城県古河市原 vs. 茨城県古河市原町
  • 茨城県石岡市柏原 vs. 茨城県石岡市柏原町
  • 茨城県龍ヶ崎市姫宮 vs. 茨城県龍ヶ崎市姫宮町
  • 茨城県龍ヶ崎市野原 vs. 茨城県龍ヶ崎市野原町
  • 茨城県ひたちなか市相金 vs. 茨城県ひたちなか市相金町
  • 栃木県那須塩原市豊浦 vs. 栃木県那須塩原市豊浦町

japanese-addresses のデータの組み合わせのうち、 936 ペア検出。

@keichan34
Copy link
Member

さくっと確認したんだけどありますね。。なるほど。
両方存在するときは「町なし」の補充をやめたほうがいいですね

@kamataryo
Copy link
Contributor Author

ちなみにこういうのもありました。

  • 広島県三原市幸崎久和喜
  • 広島県三原市幸崎町久和喜

@kamataryo
Copy link
Contributor Author

kamataryo commented Jan 31, 2022

広島県三原市幸崎久和喜 vs. 広島県三原市幸崎町久和喜 のように間に町が入る場合もテストケースとして追加し、ロジックを修正しました。

町丁目の組み合わせテストの結果はこちらにメモしておきました。
https://gist.github.com/kamataryo/57aa11a43fa22f943cb582a17a4fcb14

japanese-addresses は小字のデータを持っている場合があり、その場合は town カラムの重複が増えます。実質的に町丁目が重複しているケースは 223 件でした。

Copy link
Member

@keichan34 keichan34 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確認お願いします

expect(res).toStrictEqual({"pref": "広島県", "city": "三原市", "town": "幸崎久和喜", "addr": "789-1234", "level": 3, "lat": 34.348481, "lng": 133.067756})
})

test('広島県三原市幸崎町久和喜789-1234', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これはどっちか町あり・町なしのはずなのかな?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このケースですが、幸崎久和喜幸崎町久和喜 のどちらも存在します。
テストケースが適当すぎたので、番地だけ変えました。545492c

現時点では町あり・町なしの両方で別々に正規化されるべきかと思います。
例えばこの住所では、住居表示住所の導入段階によって便宜的に住所の表記が異なっているだけのため、番地はそれぞれの町丁目で重複していないはずです。なので、将来的に番地の情報を持てるようになったときに町あり・町なしでも寄せられるようにできるといいかと思いました。

// 町丁目が「町」で終わるケースへの対応
// 通常は「○○町」のうち「町」の省略は許容し、同義語として扱うが、まれに自治体内に「○○町」と「○○」が共存しているケースがある。
// この場合は町の省略は許容せず、住所は書き分けられているものとして正規化を行う。
const townsEndWithCho = towns.filter(
Copy link
Member

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('/町$/')))

的な感じで

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かに。ありがとうざいます。こちらで修正しました。
867e3ee

for (let i = 0; i < towns.length; i++) {
const townName = towns[i].town
if (townName.indexOf('町') === -1) continue
if (targetTownName.replace(/町/g, '') === townName) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これは /町$/ にするか /町/g にするか悩ましいと思うけど、どっちかにする理由をコメントで残してもらってもいいですか? 🙇

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。こちらで対応しました 🙇
fe93e66

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あ、こちらもでした。町を含む町丁目の判定が直っていませんでした。
町で終わる -> 町を含む に一貫して修正しました。
e982f24

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストで検出できていない時点で何か変な気がするのでもうちょっと確認します。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストを追加しました。

それから、 十六町1丁目などの漢数字と町を含むケースで壊れることがわかりましたので、対応しました。
acbc8b8

kamataryo added a commit that referenced this pull request Feb 1, 2022
Copy link
Member

@keichan34 keichan34 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これで行きましょうか

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants