Skip to content

Instantly share code, notes, and snippets.

@kzinmr
Last active December 14, 2018 02:58
Show Gist options
  • Save kzinmr/d7cf70cfa2a3a56eac5f050f00698139 to your computer and use it in GitHub Desktop.
Save kzinmr/d7cf70cfa2a3a56eac5f050f00698139 to your computer and use it in GitHub Desktop.
import re
import unicodedata
_address_re = re.compile(r'(京都府|東京都|.+?[道府県])?(.+郡)?(.+?[市町村])?(.+?区)?(.*)')
def transduce_jpaddress(addrstr):
addrstr_n = kansuji_to_arabic_numeral(addrstr)
m = _address_re.match(addrstr_n)
if m is not None:
(prefecture, county, city, ward, address) = m.groups()
address = address.strip()
# 東京都 is both a city and a prefecture.
if prefecture == '東京都' and city is None:
city = prefecture
return {'prefecture': prefecture,
'county': county,
'city': city,
'ward': ward,
'address': address}
return addrstr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment