Class: Mei::Geonames
- Inherits:
-
Object
- Object
- Mei::Geonames
- Includes:
- WebServiceBase
- Defined in:
- lib/mei/geonames.rb
Instance Attribute Summary
Attributes included from WebServiceBase
Instance Method Summary collapse
- #broader(row) ⇒ Object
- #build_query_url(q) ⇒ Object
-
#initialize(e) ⇒ Geonames
constructor
A new instance of Geonames.
- #narrower(row) ⇒ Object
- #parse_authority_response ⇒ Object
- #request_options ⇒ Object
- #search(q) ⇒ Object
- #solr_clean(term) ⇒ Object
- #variants(row) ⇒ Object
Methods included from WebServiceBase
Constructor Details
#initialize(e) ⇒ Geonames
Returns a new instance of Geonames.
12 13 14 |
# File 'lib/mei/geonames.rb', line 12 def initialize(e) @type = e end |
Instance Method Details
#broader(row) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mei/geonames.rb', line 61 def broader(row) broader_list = [] if row["fcl"] == "P" || row["fcl"] == "S" || row["fcl"] == "A" broader_list << {:uri_link=>"http://www.geonames.org/#{row["adminId1"]}", :label=>row["adminName1"]} if row["adminId1"].present? && row["adminName1"].present? broader_list << {:uri_link=>"http://www.geonames.org/#{row["adminId2"]}", :label=>row["adminName2"]} if row["adminId2"].present? && row["adminName2"].present? broader_list << {:uri_link=>"http://www.geonames.org/#{row["countryId"]}", :label=>row["countryName"]} if row["countryId"].present? && row["countryName"].present? end return broader_list end |
#build_query_url(q) ⇒ Object
22 23 24 25 26 |
# File 'lib/mei/geonames.rb', line 22 def build_query_url q @escaped_query = URI.escape(q) @escaped_query = q return "http://ws.geonames.org/searchJSON" end |
#narrower(row) ⇒ Object
72 73 74 |
# File 'lib/mei/geonames.rb', line 72 def narrower(row) return [] end |
#parse_authority_response ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/mei/geonames.rb', line 33 def end_response = [] @raw_response["geonames"].each do |geoname| count = ActiveFedora::Base.find_with_conditions("based_near_ssim:#{solr_clean("http://www.geonames.org/#{geoname["geonameId"]}")}", rows: '100', fl: 'id' ).length if count >= 99 count = "99+" else count = count.to_s end end_response << { "uri_link" => "http://www.geonames.org/#{geoname["geonameId"]}" || "missing!", "label" => geoname["name"], "broader" => broader(geoname), "narrower" => narrower(geoname), "variants" => variants(geoname), "count" => count } end end_response end |
#request_options ⇒ Object
8 9 10 |
# File 'lib/mei/geonames.rb', line 8 def {:params => {:featureClass => "#{@type}", :style => 'full', :maxRows => 20, :name_startsWith => "#{@escaped_query}", :username=>"boston_library"}, accept: :json} end |
#search(q) ⇒ Object
16 17 18 19 |
# File 'lib/mei/geonames.rb', line 16 def search q @raw_response = get_json(build_query_url(q)) end |
#solr_clean(term) ⇒ Object
90 91 92 |
# File 'lib/mei/geonames.rb', line 90 def solr_clean(term) return term.gsub('\\', '\\\\').gsub(':', '\\:').gsub(' ', '\ ') end |
#variants(row) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/mei/geonames.rb', line 76 def variants(row) varient_list = [] if row["alternateNames"].present? row["alternateNames"].each do |variant| #if ['eng'].include?( variant["lang"]) varient_list << variant["name"] #end end end return varient_list end |