如何进行规范化处理?

发布于 2024-12-23 04:38:09 字数 357 浏览 3 评论 0原文

我正在与两个 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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

長街聽風 2024-12-30 04:38:09

对于美国地址,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.

云朵有点甜 2024-12-30 04:38:09

Ruby StreetAddress gem 应该为您处理这个问题: https://rubygems.org/gems/StreetAddress

以下是针对您的案例的一些示例用法:

pry(main)> StreetAddress::US.parse("42 6 Ave., Washington, DC")
=> 42 6 Ave, Washington, DC
pry(main)> StreetAddress::US.parse("42 6 Avenue, Washington, DC")
=> 42 6 Ave, Washington, DC

因此,如果您通过解析方法运行两个 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:

pry(main)> StreetAddress::US.parse("42 6 Ave., Washington, DC")
=> 42 6 Ave, Washington, DC
pry(main)> StreetAddress::US.parse("42 6 Avenue, Washington, DC")
=> 42 6 Ave, Washington, DC

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文