Last active
December 14, 2018 02:58
-
-
Save kzinmr/d7cf70cfa2a3a56eac5f050f00698139 to your computer and use it in GitHub Desktop.
住所の構造化 (revised from http://kbyanc.blogspot.com/2007/07/parsing-japanese-addresses.html)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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