如何进行规范化处理?
我正在与两个 API 进行交互,它们返回格式完全不同的地址。一个返回类似“6 Avenue
”的地址,另一个返回“6 Ave.
”。
我使用 Normalic gem 进行了探索,但由于某种原因,我的许多地址都返回了格式错误或空白:“6 Avenue
”返回为“Ave.
”。
我也尝试过GeoCoder,但是每个API(例如Google和Yahoo)都设置了配额。在开发中测试我的应用程序几个小时后,这些配额到期。这显然在生产中行不通。
如果有一个库可以让我做类似评估 “6 Ave.” 的事情,那就太好了。 ==“6 大道”
。
I'm interacting with two APIs, which return addresses that are formatted quite differently. One returns an address like "6 Avenue
" and another returns "6 Ave.
"
I explored using the Normalic gem, but for some reason many of my addresses are returned malformed or blank: "6 Avenue
" gets returned as "Ave.
".
I also tried GeoCoder, but each API such as Google and Yahoo have set quotas. After a few hours of testing my app in development, these quotas expire. This obviously won't do in production.
It would be great if there was a library that let me do something like evaluate "6 Ave." == "6 Avenue"
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于美国地址,USPS 提供 地址 API。我的理解是,这是免费的,但您的目的需要与电子商务网站一起使用,以在输入时验证地址。
为了清理数据库,美国邮政局经常将您发送到他们的(昂贵的)邮寄服务提供商之一。
For US addresses, the USPS offers an address api. My understanding is that there is no charge, but your purpose needs to be for use with an e commerce website to validate addesses as they're entered.
For cleaning databases, the USPS often sends you to one of their (expensive) service providers for mailers.
Ruby StreetAddress gem 应该为您处理这个问题: https://rubygems.org/gems/StreetAddress
以下是针对您的案例的一些示例用法:
因此,如果您通过解析方法运行两个 API 地址,它应该为您标准化这两个地址,并释放您的生活以进行更多反思、骑自行车和吃披萨。
The Ruby StreetAddress gem should take care of this for you: https://rubygems.org/gems/StreetAddress
Here's some example usage for your case:
So if you run both of your API addresses through the parse method, it should standardize both for you, and free up your life for more reflection, biking, and pizza consumption.