ruby - Indirizzo 无法识别以州命名的街道名称
问题描述
我有一个从充满地址的 .CSV 文件生成的数组,我需要让它只提取街道名称,然后是 Rd、Road、St 等,而 RubyGem Indirizzo 完美地做到了这一点,但它没有识别以密苏里路或华盛顿大道等州命名的街道。有人知道如何解决这个问题吗?
#!ruby.exe
require 'Indirizzo'
require 'csv'
file = "Reports.csv"
begin
File.open(file, 'r')
rescue
print "Failed to open #{file}\n"
exit
end
data_file = File.new(file)
data = [] #initializes array for addresses from .csv
counter=0 #set counter up to allow for different sized files to be used without
issue
CSV.foreach(data_file, headers: true) do |row|
data << row.to_hash
counter+=1
end #goes through .csv one line at a time
data.reject!(&:empty?)
i=0
streets = []
column = "Street Name"
while (i<counter)
address = data[i][column]
street_name = address.gsub(/^((\d[a-zA-Z])|[^a-zA-Z])*/, '')
new_address = Indirizzo::Address.new(street_name, :expand_streets => false)
streetName = new_address.street
puts streetName
i+=1
end
解决方案
如果 Indirizzo 不能识别名称为 的街道地址Washington
,那可能是一个错误,应该在Github上报告。话虽如此,看起来宝石自 2013 年以来就没有更新过,所以我不会屏住呼吸进行修复。
与此同时,gemStreetAddress
似乎能够解析这样的情况。自述文件中的示例具有地址1600 Pennsylvania Ave, Washington, DC, 20500
。此外,这颗宝石看起来更维护;它最后一次更新是在 2017 年。
推荐阅读
- java - 如何使用 Android Studio 在 android 应用程序中可视化音频文件?
- sql - 基于sql server中第一行值的数据
- google-data-studio - Google Datastudio:根据新用户 ID 和返回用户 ID 的首次出现日期对其进行分类
- python - Slack API ProtocolError/ConnetionError 但仍在工作
- r - 通过环路识别车道
- javascript - 如何在单击时向按钮添加类
- ionic-framework - 将变量添加到 InAppBrowser URL
- java - 如何动态更新信任库?
- swift - “str1.characters”的含义
- html - VSCode script type="text/html" 不提供 html 智能感知功能