Extract street address from a string

僤鯓⒐⒋嵵緔 提交于 2020-03-28 07:02:28

问题


Is there any way to extract a street address from a string (say, email) using python? The address does not come in a set format. It can come without state, zip code, city, but I can guess and supply these parameters if they are missing. Also, the address may be represented by a corner of two streets. Once I extract the address, I want to send it to Google Map or other similar service to get back the real, formatted address.

It doesn't need to be 100% accurate, but is there any library to do that? If it doesn't exist, how should I start?


回答1:


As you already say yourself, an address can come in a large number of formats. And the reality is actually even worse if you take addresses from other countries into account. So no, there is not really a good way to parse and clean up such addresses. The larger the regional area is you want to include as possible formats, the more complicated it gets.

If you want to send the address to Google Maps anyway, then just send your original format. Google has enough data to extract the more useful parts and make the best possible out of it. As you are sending it to Google anyway, you can just do it in the first place.




回答2:


Addresses often follow a format, which can be exploited using regex. This is tricky, so luckily there is a wonderful library to make it easier for you.

pip install commonregex

Then

from commonregex import CommonRegex
parsed_text = CommonRegex("123 Your Street")
print(parsed_text.street_addresses)



回答3:


a = re.split(r"[\s\-:\\/_,]", "string address here !")
a1 = ""
for i in a:
    if re.findall(r"[^\W]",i):
        a1 += i + " " 
print(a1)

Try to send this to google.



来源:https://stackoverflow.com/questions/21976024/extract-street-address-from-a-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!