地址解析[PY]

发布于 2025-01-21 03:19:36 字数 947 浏览 3 评论 0原文

因此,我想编写一个将以形式输入输入的函数:

123 1st street APT 32S or
320 Jumping Alien Road
555 Google Ave

字典 / json中的输出所有从输入字符串字典中解析的所有信息

看起来就像是

output = {
   "streetNum" : "123",
   "roadName" : "1st",
   "suffix" : "street",
   "enders" : "APT", #or None /null
   "room" : "32S" #or None / null
}

我试图使用逻辑的内容,但我可以提出的最好的是是沿着地址的路线。Split(''),然后以路线名,后缀和街道名称通常位于该字符串中它们内部的空间也会破坏功能。

def addressParser(addressString):
    return {
       "streetNum" : addressString.split(' ')[0], #prob need regex help
       "roadName" : addressString.split(' ')[1],
       "suffix" : addressString.split(' ')[2],
       "enders" : addressString.split(' ')[3],
       "room" : addressString.split(' ')[4]
    }

编辑:确切找到我在这里需要的东西 https://pypi.org/project/project/address/address/

so im looking to write a function that will take input in the form:

123 1st street APT 32S or
320 Jumping Alien Road
555 Google Ave

and output in a dictionary / json all the information parsed from the inputted string

dictionary would look something like

output = {
   "streetNum" : "123",
   "roadName" : "1st",
   "suffix" : "street",
   "enders" : "APT", #or None /null
   "room" : "32S" #or None / null
}

Im trying to thing of the logic but the best I can come up with is something along the lines of address.split(' ') and then taking where the roadname, suffix, and streetname would typically be located in said string but obviously these things aren't always gonna be located in that order and when road names have spaces inside them that would break the function as well.

def addressParser(addressString):
    return {
       "streetNum" : addressString.split(' ')[0], #prob need regex help
       "roadName" : addressString.split(' ')[1],
       "suffix" : addressString.split(' ')[2],
       "enders" : addressString.split(' ')[3],
       "room" : addressString.split(' ')[4]
    }

Edit: found exactly what i needed here https://pypi.org/project/address/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文