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

latest.csv の東京都渋谷区富ヶ谷、千駄ヶ谷、幡ヶ谷のカナおよびローマ字データが欠損しているバグを修正 #124

Merged
merged 4 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- run: mkdir data || true
- run: npm install
- name: Build Nagano, Hokkaido, and Nara data
run: node bin/build.js 20,1,29
- name: Build Nagano, Hokkaido, Nara, and Tokyo data
run: node bin/build.js 20,1,29,13
- name: Test
run: npx mocha
103 changes: 1 addition & 102 deletions bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const sqlite3 = require('sqlite3')
const db = new sqlite3.Database('./data/latest.db')
const exportToCsv = require('../lib/export-to-csv')
const sortAddresses = require('../lib/sort-addresses')
const getPostalKanaOrRomeItems = require('../lib/get-postal-kana-or-rome-items')

const sleep = promisify(setTimeout)

Expand All @@ -30,20 +31,6 @@ const isjRenames = [
{ pref: '福岡県', orig: '筑紫郡那珂川町', renamed: '那珂川市' },
]

const isjPostalMappings = [
{ pref: '青森県', postal: '東津軽郡外ヶ浜町', isj: '東津軽郡外ケ浜町' },
{ pref: '茨城県', postal: '龍ケ崎市', isj: '龍ヶ崎市' },
{ pref: '千葉県', postal: '鎌ケ谷市', isj: '鎌ヶ谷市' },
{ pref: '千葉県', postal: '袖ケ浦市', isj: '袖ヶ浦市' },
{ pref: '東京都', postal: '三宅島三宅村', isj: '三宅村',
kana: 'ミヤケムラ', rome: 'MIYAKE MURA' },
{ pref: '東京都', postal: '八丈島八丈町', isj: '八丈町',
kana: 'ハチジョウマチ', rome: 'HACHIJO MACHI' },
{ pref: '滋賀県', postal: '犬上郡多賀町', isj: '犬上郡大字多賀町',
kana: 'イヌカミグンオオアザタガチョウ', rome: 'INUKAMI GUN OAZA TAGA CHO' },
{ pref: '福岡県', postal: '糟屋郡須惠町', isj: '糟屋郡須恵町' },
]

const prefNames = [
'北海道',
'青森県',
Expand Down Expand Up @@ -200,9 +187,6 @@ const removeUnnecessarySpace = text => {
return text.replace(' ', '').trim()
}

const REMOVE_CHOME_REGEX = /[二三四五六七八九]?十?[一二三四五六七八九]?丁目?$/
const removeChome = text => text.replace(REMOVE_CHOME_REGEX, '')

const GET_CHOME_NUMBER_REGEX = /([二三四五六七八九]?十?[一二三四五六七八九]?)丁目?$/
const getChomeNumber = (text, suffix = '') => {
const match = text.match(GET_CHOME_NUMBER_REGEX)
Expand All @@ -218,91 +202,6 @@ const removeStringEnclosedInParentheses = text => {
return text.replace(REMOVE_STRING_IN_PARENS_REGEX, '')
}

const REMOVE_STRING_STARTING_WITH_OPENING_PARENS_REGEX = /\(.+$/
const removeStringStartingWithOpeningParentheses = text => {
return text.replace(REMOVE_STRING_STARTING_WITH_OPENING_PARENS_REGEX, '')
}

const getPostalKanaOrRomeItems = (
prefName,
cityName,
townName,
postalCodeKanaOrRomeItems,
postalKanaOrRomeCityFieldName,
altKanaOrRomeCityFieldName,
) => {
const postalAlt = isjPostalMappings.find(
({ pref, isj }) => (pref === prefName && isj === cityName),
)

const townNameChomeRemoved = removeChome(townName)

if (postalAlt) {
let postalRecord = postalCodeKanaOrRomeItems.find(
item =>
item['都道府県名'] === prefName &&
item['市区町村名'] === postalAlt.postal &&
item['町域名'].indexOf(townNameChomeRemoved) === 0
,
)

if (!postalRecord) {
postalRecord = postalCodeKanaOrRomeItems.find(
item =>
item['都道府県名'] === prefName &&
item['市区町村名'] === postalAlt.postal
,
)
if (postalRecord['町域名カナ']) {
postalRecord['町域名カナ'] = ''
}
if (postalRecord['町域名ローマ字']) {
postalRecord['町域名ローマ字'] = ''
}
}

if (postalRecord && postalAlt[altKanaOrRomeCityFieldName]) {
postalRecord[postalKanaOrRomeCityFieldName] = postalAlt[altKanaOrRomeCityFieldName]
}

return postalRecord
} else {
let postalRecord = postalCodeKanaOrRomeItems.find(
item =>
item['都道府県名'] === prefName &&
item['市区町村名'] === cityName &&
item['町域名'].indexOf(townNameChomeRemoved) === 0
,
)

if (!postalRecord) {
postalRecord = postalCodeKanaOrRomeItems.find(
item =>
item['都道府県名'] === prefName &&
item['市区町村名'] === cityName
,
)
if (postalRecord['町域名カナ']) {
postalRecord['町域名カナ'] = ''
}
if (postalRecord['町域名ローマ字']) {
postalRecord['町域名ローマ字'] = ''
}
}

// 「ナカマチ(5115-5149、5171、5183、5186、」のような場合の「(」以降の不要な文字列を削除する。
if (postalRecord['町域名カナ']) {
postalRecord['町域名カナ'] = removeStringStartingWithOpeningParentheses(postalRecord['町域名カナ'])
}

if (postalRecord['町域名ローマ字']) {
postalRecord['町域名ローマ字'] = removeStringStartingWithOpeningParentheses(postalRecord['町域名ローマ字'])
}

return postalRecord
}
}

const _downloadZippedFile = (url, path) => new Promise( resolve => {
https.get(url, res => {
res
Expand Down
Loading