Class: GeoBlacklightSchema::Gazetteer
- Inherits:
-
Object
- Object
- GeoBlacklightSchema::Gazetteer
- Defined in:
- lib/geoblacklight/gazetteer.rb
Constant Summary collapse
- CSV_FN =
File.join(File.dirname(__FILE__), 'gazetteer.csv')
Instance Method Summary collapse
- #blank?(k) ⇒ Boolean
- #each ⇒ Object
-
#find_id(k) ⇒ Integer
Geonames id.
-
#find_keyword_by_id(id) ⇒ String
The keyword.
-
#find_loc_authority(k) ⇒ String
Authority name.
-
#find_loc_keyword(k) ⇒ String
Library of congress name.
-
#find_loc_uri(k) ⇒ String
Library of congress valueURI.
-
#find_placename(k) ⇒ String
Geonames name.
-
#find_placename_uri(k) ⇒ String
Geonames uri (includes trailing / as specified).
-
#initialize ⇒ Gazetteer
constructor
A new instance of Gazetteer.
Constructor Details
#initialize ⇒ Gazetteer
Returns a new instance of Gazetteer.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/geoblacklight/gazetteer.rb', line 13 def initialize @registry = {} CSV.foreach(CSV_FN, :encoding => 'UTF-8', :headers => true) do |v| v = v.each { |k,v| v.to_s.strip } k = v[0] k = v[1] if k.nil? or k.empty? k.strip! @registry[k] = { :geonames_placename => v[1], :geonames_id => v[2].to_i, :loc_keyword => (v[3].nil? or v[3].empty?)? nil : v[3], :loc_id => (v[4].nil? or v[4].empty?)? nil : v[4] } if @registry[k][:geonames_placename].nil? && @registry[k][:loc_keyword].nil? @registry[k] = nil end end end |
Instance Method Details
#blank?(k) ⇒ Boolean
91 92 93 |
# File 'lib/geoblacklight/gazetteer.rb', line 91 def blank?(k) @registry.include?(k) && @registry[k].nil? end |
#each ⇒ Object
32 33 34 |
# File 'lib/geoblacklight/gazetteer.rb', line 32 def each @registry.each_key.to_a.sort.each {|k| yield k } end |
#find_id(k) ⇒ Integer
Returns geonames id.
42 43 44 |
# File 'lib/geoblacklight/gazetteer.rb', line 42 def find_id(k) _get(k, :geonames_id) end |
#find_keyword_by_id(id) ⇒ String
Returns The keyword.
84 85 86 87 88 89 |
# File 'lib/geoblacklight/gazetteer.rb', line 84 def find_keyword_by_id(id) @registry.each do |k,v| return k if v[:geonames_id] == id end nil end |
#find_loc_authority(k) ⇒ String
Returns authority name.
66 67 68 69 70 71 72 73 |
# File 'lib/geoblacklight/gazetteer.rb', line 66 def (k) lcid = _get(k, :loc_id) return $1 if lcid =~ /^(lcsh|lcnaf):/ return 'lcsh' if lcid =~ /^sh\d+$/ return 'lcnaf' if lcid =~ /^(n|no)\d+$/ return 'lcsh' unless find_loc_keyword(k).nil? # default to lcsh if present nil end |
#find_loc_keyword(k) ⇒ String
Returns library of congress name.
47 48 49 |
# File 'lib/geoblacklight/gazetteer.rb', line 47 def find_loc_keyword(k) _get(k, :loc_keyword) end |
#find_loc_uri(k) ⇒ String
Returns library of congress valueURI.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/geoblacklight/gazetteer.rb', line 52 def find_loc_uri(k) lcid = _get(k, :loc_id) if lcid =~ /^lcsh:(\d+)$/ or lcid =~ /^sh(\d+)$/ "http://id.loc.gov/authorities/subjects/sh#{$1}" elsif lcid =~ /^lcnaf:(\d+)$/ or lcid =~ /^n(\d+)$/ "http://id.loc.gov/authorities/names/n#{$1}" elsif lcid =~ /^no(\d+)$/ "http://id.loc.gov/authorities/names/no#{$1}" else nil end end |
#find_placename(k) ⇒ String
Returns geonames name.
37 38 39 |
# File 'lib/geoblacklight/gazetteer.rb', line 37 def find_placename(k) _get(k, :geonames_placename) end |
#find_placename_uri(k) ⇒ String
Returns geonames uri (includes trailing / as specified).
78 79 80 81 |
# File 'lib/geoblacklight/gazetteer.rb', line 78 def find_placename_uri(k) return nil if _get(k, :geonames_id).nil? "http://sws.geonames.org/#{_get(k, :geonames_id)}/" end |