首页 > 解决方案 > 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

标签: rubycsv

解决方案


如果 Indirizzo 不能识别名称为 的街道地址Washington,那可能是一个错误,应该在Github上报告。话虽如此,看起来宝石自 2013 年以来就没有更新过,所以我不会屏住呼吸进行修复。

与此同时,gemStreetAddress似乎能够解析这样的情况。自述文件中的示例具有地址1600 Pennsylvania Ave, Washington, DC, 20500。此外,这颗宝石看起来更维护;它最后一次更新是在 2017 年。


推荐阅读