Skip to content

Commit

Permalink
Fix for 大字 & 町 conflict (#159)
Browse files Browse the repository at this point in the history
Co-authored-by: kamataryo <[email protected]>
  • Loading branch information
Kamata, Ryo and kamataryo authored Feb 3, 2022
1 parent 61deeb3 commit 234e55d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/lib/cacheRegexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ export const getTownRegexPatterns = async (pref: string, city: string) => {
const originalTown = town.town
if (originalTown.indexOf('町') === -1) continue
const townAbbr = originalTown.replace(/(?!^町)町/g, '') // NOTE: 冒頭の「町」は明らかに省略するべきではないので、除外
if (!townSet.has(townAbbr) && !isKanjiNumberFollewedByCho(originalTown)) {
if (
!townSet.has(townAbbr) &&
!townSet.has(`大字${townAbbr}`) && // 大字は省略されるため、大字〇〇と〇〇町がコンフリクトする。このケースを除外
!isKanjiNumberFollewedByCho(originalTown)
) {
// エイリアスとして町なしのパターンを登録
towns.push({
...town,
Expand Down
24 changes: 23 additions & 1 deletion test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,29 @@ for (const [runtime, normalize] of cases) {
// 漢数字を含む町丁目については、後続の丁目や番地が壊れるので町の省略を許容しない
test('愛知県名古屋市瑞穂区十六町1丁目123-4', async () => {
const res = await normalize('愛知県名古屋市瑞穂区十六町1丁目123-4')
expect(res).toStrictEqual({"pref": "愛知県", "city": "名古屋市瑞穂区", "town": "十六町一丁目", "addr": "123-4", "level": 3, "lat": 35.128862, "lng": 136.936585})
expect(res).toStrictEqual({"pref": "愛知県", "city": "名古屋市瑞穂区", "town": "十六町一丁目", "addr": "123-4", "level": 3, "lat": 35.128862, "lng": 136.936585})
})

describe('大字◯◯と◯◯町が共存するケース', () => {
test('埼玉県川口市新堀999-888', async () => {
const res = await normalize('埼玉県川口市新堀999-888')
expect(res).toStrictEqual({"pref": "埼玉県", "city": "川口市", "town": "大字新堀", "addr": "999-888", "level": 3, "lat": 35.827425, "lng": 139.783579})
})

test('埼玉県川口市大字新堀999-888', async () => {
const res = await normalize('埼玉県川口市大字新堀999-888')
expect(res).toStrictEqual({"pref": "埼玉県", "city": "川口市", "town": "大字新堀", "addr": "999-888", "level": 3, "lat": 35.827425, "lng": 139.783579})
})

test('埼玉県川口市新堀町999-888', async () => {
const res = await normalize('埼玉県川口市新堀町999-888')
expect(res).toStrictEqual({"pref": "埼玉県", "city": "川口市", "town": "新堀町", "addr": "999-888", "level": 3, "lat": 35.825057, "lng": 139.781901})
})

test('埼玉県川口市大字新堀町999-888', async () => {
const res = await normalize('埼玉県川口市大字新堀町999-888')
expect(res).toStrictEqual({"pref": "埼玉県", "city": "川口市", "town": "新堀町", "addr": "999-888", "level": 3, "lat": 35.825057, "lng": 139.781901})
})
})

// 町から始まる町丁目について、町を省略した場合は寄せない
Expand Down

0 comments on commit 234e55d

Please sign in to comment.