bplgeo 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +32 -0
  3. data/lib/bplgeo/constants.rb +478 -0
  4. data/lib/bplgeo/geonames.rb +146 -0
  5. data/lib/bplgeo/parser.rb +227 -0
  6. data/lib/bplgeo/standardizer.rb +213 -0
  7. data/lib/bplgeo/tgn.rb +314 -0
  8. data/lib/bplgeo/town_lookup.rb +19 -0
  9. data/lib/bplgeo/version.rb +3 -0
  10. data/lib/bplgeo.rb +35 -0
  11. data/lib/tasks/bplgeo_tasks.rake +4 -0
  12. data/test/bplgeo_test.rb +102 -0
  13. data/test/dummy/README.rdoc +28 -0
  14. data/test/dummy/Rakefile +6 -0
  15. data/test/dummy/app/assets/javascripts/application.js +13 -0
  16. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  17. data/test/dummy/app/controllers/application_controller.rb +5 -0
  18. data/test/dummy/app/helpers/application_helper.rb +2 -0
  19. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  20. data/test/dummy/bin/bundle +3 -0
  21. data/test/dummy/bin/rails +4 -0
  22. data/test/dummy/bin/rake +4 -0
  23. data/test/dummy/config/application.rb +23 -0
  24. data/test/dummy/config/boot.rb +5 -0
  25. data/test/dummy/config/bplgeo.yml +23 -0
  26. data/test/dummy/config/bplgeo.yml.sample +24 -0
  27. data/test/dummy/config/database.yml +25 -0
  28. data/test/dummy/config/environment.rb +5 -0
  29. data/test/dummy/config/environments/development.rb +29 -0
  30. data/test/dummy/config/environments/production.rb +80 -0
  31. data/test/dummy/config/environments/test.rb +36 -0
  32. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  33. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  34. data/test/dummy/config/initializers/inflections.rb +16 -0
  35. data/test/dummy/config/initializers/mime_types.rb +5 -0
  36. data/test/dummy/config/initializers/secret_token.rb +12 -0
  37. data/test/dummy/config/initializers/session_store.rb +3 -0
  38. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  39. data/test/dummy/config/locales/en.yml +23 -0
  40. data/test/dummy/config/routes.rb +56 -0
  41. data/test/dummy/config.ru +4 -0
  42. data/test/dummy/db/test.sqlite3 +0 -0
  43. data/test/dummy/log/development.log +35 -0
  44. data/test/dummy/public/404.html +58 -0
  45. data/test/dummy/public/422.html +58 -0
  46. data/test/dummy/public/500.html +57 -0
  47. data/test/dummy/public/favicon.ico +0 -0
  48. data/test/geonames_test.rb +24 -0
  49. data/test/parser_test.rb +33 -0
  50. data/test/test_helper.rb +15 -0
  51. data/test/tgn_test.rb +19 -0
  52. data/test/town_lookup_test.rb +11 -0
  53. metadata +236 -0
data/lib/bplgeo/tgn.rb ADDED
@@ -0,0 +1,314 @@
1
+ module Bplgeo
2
+ class TGN
3
+
4
+ def self.bplgeo_config
5
+ root = Rails.root || './test/dummy'
6
+ env = Rails.env || 'test'
7
+ @bplgeo_config ||= YAML::load(ERB.new(IO.read(File.join(root, 'config', 'bplgeo.yml'))).result)[env].with_indifferent_access
8
+ end
9
+
10
+ def self.getty_username
11
+ bplgeo_config[:getty_username] || '<username>'
12
+ end
13
+
14
+ def self.getty_password
15
+ bplgeo_config[:getty_password] || '<password>'
16
+ end
17
+
18
+ # retrieve data from Getty TGN to populate <mods:subject auth="tgn">
19
+ def self.get_tgn_data(tgn_id)
20
+ tgn_response = Typhoeus::Request.get('http://vocabsservices.getty.edu/TGNService.asmx/TGNGetSubject?subjectID=' + tgn_id, userpwd: self.getty_username + ':' + self.getty_password)
21
+ unless tgn_response.code == 500
22
+ tgnrec = Nokogiri::XML(tgn_response.body)
23
+ #puts tgnrec.to_s
24
+
25
+ # coordinates
26
+ if tgnrec.at_xpath("//Coordinates")
27
+ coords = {}
28
+ coords[:latitude] = tgnrec.at_xpath("//Latitude/Decimal").children.to_s
29
+ coords[:longitude] = tgnrec.at_xpath("//Longitude/Decimal").children.to_s
30
+ coords[:combined] = coords[:latitude] + ',' + coords[:longitude]
31
+ else
32
+ coords = nil
33
+ end
34
+
35
+ hier_geo = {}
36
+
37
+ #main term
38
+ if tgnrec.at_xpath("//Terms/Preferred_Term/Term_Text")
39
+ tgn_term_type = tgnrec.at_xpath("//Preferred_Place_Type/Place_Type_ID").children.to_s
40
+ pref_term_langs = tgnrec.xpath("//Terms/Preferred_Term/Term_Languages/Term_Language/Language")
41
+ # if the preferred term is the preferred English form, use that
42
+ if pref_term_langs.children.to_s.include? "English"
43
+ tgn_term = tgnrec.at_xpath("//Terms/Preferred_Term/Term_Text").children.to_s
44
+ else # use the non-preferred term which is the preferred English form
45
+ if tgnrec.xpath("//Terms/Non-Preferred_Term")
46
+ non_pref_terms = tgnrec.xpath("//Terms/Non-Preferred_Term")
47
+ non_pref_terms.each do |non_pref_term|
48
+ non_pref_term_langs = non_pref_term.children.css("Term_Language")
49
+ # have to loop through these, as sometimes languages share form
50
+ non_pref_term_langs.each do |non_pref_term_lang|
51
+ if non_pref_term_lang.children.css("Preferred").children.to_s == "Preferred" && non_pref_term_lang.children.css("Language").children.to_s == "English"
52
+ tgn_term = non_pref_term.children.css("Term_Text").children.to_s
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ # if no term is the preferred English form, just use the preferred term
59
+ tgn_term ||= tgnrec.at_xpath("//Terms/Preferred_Term/Term_Text").children.to_s
60
+ end
61
+ if tgn_term && tgn_term_type
62
+ case tgn_term_type
63
+ when '29000/continent'
64
+ hier_geo[:continent] = tgn_term
65
+ when '81010/nation'
66
+ hier_geo[:country] = tgn_term
67
+ when '81161/province'
68
+ hier_geo[:province] = tgn_term
69
+ when '81165/region', '82193/union', '80005/semi-independent political entity'
70
+ hier_geo[:region] = tgn_term
71
+ when '81175/state', '81117/department', '82133/governorate'
72
+ hier_geo[:state] = tgn_term
73
+ when '81125/national district'
74
+ if tgn_term == 'District of Columbia'
75
+ hier_geo[:state] = tgn_term
76
+ else
77
+ hier_geo[:territory] = tgn_term
78
+ end
79
+ when '81181/territory', '81021/dependent state', '81186/union territory'
80
+ hier_geo[:territory] = tgn_term
81
+ when '81115/county'
82
+ hier_geo[:county] = tgn_term
83
+ when '83002/inhabited place'
84
+ hier_geo[:city] = tgn_term
85
+ when '84251/neighborhood'
86
+ hier_geo[:city_section] = tgn_term
87
+ when '21471/island'
88
+ hier_geo[:island] = tgn_term
89
+ when '81101/area', '22101/general region', '83210/deserted settlement', '81501/historical region', '81126/national division'
90
+ hier_geo[:area] = tgn_term
91
+ else
92
+ non_hier_geo = tgn_term
93
+ end
94
+ end
95
+
96
+ # parent data for <mods:hierarchicalGeographic>
97
+ if tgnrec.at_xpath("//Parent_String")
98
+ parents = tgnrec.at_xpath("//Parent_String").children.to_s.split('], ')
99
+ parents.each do |parent|
100
+ if parent.include? '(continent)'
101
+ hier_geo[:continent] = parent
102
+ elsif parent.include? '(nation)'
103
+ hier_geo[:country] = parent
104
+ elsif parent.include? '(province)'
105
+ hier_geo[:province] = parent
106
+ elsif (parent.include? '(region)') || (parent.include? '(union)') || (parent.include? '(semi-independent political entity)')
107
+ hier_geo[:region] = parent
108
+ elsif (parent.include? '(state)') || (parent.include? '(department)') || (parent.include? '(governorate)') || (parent.include?('(national district)') && parent.include?('District of Columbia'))
109
+ hier_geo[:state] = parent
110
+ elsif (parent.include? '(territory)') || (parent.include? '(dependent state)') || (parent.include? '(union territory)') || (parent.include? '(national district)')
111
+ hier_geo[:territory] = parent
112
+ elsif parent.include? '(county)'
113
+ hier_geo[:county] = parent
114
+ elsif parent.include? '(inhabited place)'
115
+ hier_geo[:city] = parent
116
+ elsif parent.include? '(neighborhood)'
117
+ hier_geo[:city_section] = parent
118
+ elsif parent.include? '(island)'
119
+ hier_geo[:island] = parent
120
+ elsif (parent.include? '(area)') || (parent.include? '(general region)') || (parent.include? '(deserted settlement)') || (parent.include? '(historical region)') || (parent.include? '(national division)')
121
+ hier_geo[:area] = parent
122
+ end
123
+ end
124
+ hier_geo.each do |k,v|
125
+ hier_geo[k] = v.gsub(/ \(.*/,'')
126
+ end
127
+ end
128
+
129
+ tgn_data = {}
130
+ tgn_data[:coords] = coords
131
+ tgn_data[:hier_geo] = hier_geo.length > 0 ? hier_geo : nil
132
+ tgn_data[:non_hier_geo] = non_hier_geo ? non_hier_geo : nil
133
+
134
+ else
135
+
136
+ tgn_data = nil
137
+
138
+ end
139
+
140
+ return tgn_data
141
+
142
+ end
143
+
144
+ def self.tgn_id_from_geo_hash(geo_hash)
145
+ return nil if Bplgeo::TGN.getty_username == '<username>'
146
+
147
+ geo_hash = geo_hash.clone
148
+
149
+ max_retry = 3
150
+ sleep_time = 60 # In seconds
151
+ retry_count = 0
152
+
153
+ return_hash = {}
154
+
155
+ state_part = geo_hash[:state_part]
156
+
157
+ country_code = Bplgeo::Constants::COUNTRY_TGN_LOOKUP[geo_hash[:country_part]][:tgn_id] unless Bplgeo::Constants::COUNTRY_TGN_LOOKUP[geo_hash[:country_part]].blank?
158
+ country_code ||= ''
159
+
160
+
161
+ country_part = Bplgeo::Constants::COUNTRY_TGN_LOOKUP[geo_hash[:country_part]][:tgn_country_name] unless Bplgeo::Constants::COUNTRY_TGN_LOOKUP[geo_hash[:country_part]].blank?
162
+ country_part ||= geo_hash[:country_part]
163
+ country_part ||= ''
164
+
165
+ city_part = geo_hash[:city_part]
166
+
167
+ neighborhood_part = geo_hash[:neighborhood_part]
168
+
169
+ top_match_term = ''
170
+ match_term = nil
171
+
172
+ if city_part.blank? && state_part.blank?
173
+ # Limit to nations
174
+ place_type = 81010
175
+ top_match_term = ['']
176
+ second_top_match_term = ''
177
+ match_term = country_part.to_ascii.downcase
178
+ elsif state_part.present? && city_part.blank? && country_code == 7012149
179
+ #Limit to states
180
+ place_type = 81175
181
+ top_match_term = ["#{country_part.to_ascii.downcase} (nation)"]
182
+ second_top_match_term = ["#{country_part.to_ascii.downcase} (nation)"]
183
+ match_term = state_part.to_ascii.downcase
184
+ elsif state_part.present? && city_part.blank?
185
+ #Limit to regions
186
+ place_type = 81165
187
+ top_match_term = ["#{country_part.to_ascii.downcase} (nation)"]
188
+ second_top_match_term = ["#{country_part.to_ascii.downcase} (nation)"]
189
+ match_term = state_part.to_ascii.downcase
190
+ elsif state_part.present? && city_part.present? && neighborhood_part.blank?
191
+ #Limited to only inhabited places at the moment...
192
+ place_type = 83002
193
+ sp = state_part.to_ascii.downcase
194
+ top_match_term = ["#{sp} (state)", "#{sp} (department)", "#{sp} (governorate)", "#{sp} (territory)", "#{sp} (dependent state)", "#{sp} (union territory)", "#{sp} (national district)", "#{sp} (province)"]
195
+ second_top_match_term = ["#{country_part.to_ascii.downcase} (nation)"]
196
+ match_term = city_part.to_ascii.downcase
197
+ elsif state_part.present? && city_part.present? && neighborhood_part.present?
198
+ #Limited to only to neighborhoods currently...
199
+ place_type = 84251
200
+ top_match_term = ["#{city_part.to_ascii.downcase} (inhabited place)"]
201
+ sp = neighborhood_part.to_ascii.downcase
202
+ second_top_match_term = ["#{sp} (state)", "#{sp} (department)", "#{sp} (governorate)", "#{sp} (territory)", "#{sp} (dependent state)", "#{sp} (union territory)", "#{sp} (national district)", "#{sp} (province)"]
203
+ match_term = neighborhood_part.to_ascii.downcase
204
+ else
205
+ return nil
206
+ end
207
+
208
+ begin
209
+ if retry_count > 0
210
+ sleep(sleep_time)
211
+ end
212
+ retry_count = retry_count + 1
213
+
214
+ tgn_response = Typhoeus::Request.get("http://vocabsservices.getty.edu/TGNService.asmx/TGNGetTermMatch?placetypeid=#{place_type}&nationid=#{country_code}&name=" + CGI.escape(match_term), userpwd: self.getty_username + ':' + self.getty_password)
215
+
216
+
217
+ end until (tgn_response.code != 500 || retry_count == max_retry)
218
+
219
+ unless tgn_response.code == 500
220
+ parsed_xml = Nokogiri::Slop(tgn_response.body)
221
+
222
+ #This is ugly and needs to be redone to achieve better recursive...
223
+ if parsed_xml.Vocabulary.Count.text == '0'
224
+ if neighborhood_part.present?
225
+ geo_hash[:neighborhood_part] = nil
226
+ geo_hash = tgn_id_from_geo_hash(geo_hash)
227
+ elsif city_part.present?
228
+ geo_hash[:city_part] = nil
229
+ geo_hash = tgn_id_from_geo_hash(geo_hash)
230
+ end
231
+
232
+ return nil
233
+ end
234
+
235
+ #If only one result, then not array. Otherwise array....
236
+ if parsed_xml.Vocabulary.Subject.first.blank?
237
+ subject = parsed_xml.Vocabulary.Subject
238
+
239
+ current_term = subject.Preferred_Term.text.gsub(/\(.*\)/, '').to_ascii.downcase.strip
240
+ alternative_terms = subject.elements.any? { |node| node.name == 'Term' } ? subject.Term : ''
241
+
242
+ #FIXME: Term should check for the correct level... temporary fix...
243
+ if current_term == match_term && top_match_term.any? { |top_match| subject.Preferred_Parent.text.to_ascii.downcase.include? top_match }
244
+ return_hash[:id] = subject.Subject_ID.text
245
+ #Check alternative term ids
246
+ elsif alternative_terms.present? && alternative_terms.children.any? { |alt_term| alt_term.text.to_ascii.downcase.strip == match_term} && top_match_term.any? { |top_match| subject.Preferred_Parent.text.to_ascii.downcase.include? top_match }
247
+ return_hash[:id] = subject.Subject_ID.text
248
+ elsif current_term == match_term && second_top_match_term.any? { |top_match| subject.Preferred_Parent.text.to_ascii.downcase.include? top_match }
249
+ return_hash[:id] = subject.Subject_ID.text
250
+ elsif alternative_terms.present? && alternative_terms.children.any? { |alt_term| alt_term.text.to_ascii.downcase.strip == match_term} && second_top_match_term.any? { |top_match| subject.Preferred_Parent.text.to_ascii.downcase.include? top_match }
251
+ return_hash[:id] = subject.Subject_ID.text
252
+ end
253
+ else
254
+ parsed_xml.Vocabulary.Subject.each do |subject|
255
+
256
+ current_term = subject.Preferred_Term.text.gsub(/\(.*\)/, '').to_ascii.downcase.strip
257
+ alternative_terms = subject.elements.any? { |node| node.name == 'Term' } ? subject.Term : ''
258
+
259
+ if current_term == match_term && top_match_term.any? { |top_match| subject.Preferred_Parent.text.to_ascii.downcase.include? top_match }
260
+ return_hash[:id] = subject.Subject_ID.text
261
+ end
262
+ end
263
+
264
+ if return_hash[:id].blank?
265
+ parsed_xml.Vocabulary.Subject.each do |subject|
266
+ current_term = subject.Preferred_Term.text.gsub(/\(.*\)/, '').to_ascii.downcase.strip
267
+ alternative_terms = subject.elements.any? { |node| node.name == 'Term' } ? subject.Term : ''
268
+
269
+ if alternative_terms.present? && alternative_terms.children.any? { |alt_term| alt_term.text.to_ascii.downcase.strip == match_term} && top_match_term.any? { |top_match| subject.Preferred_Parent.text.to_ascii.downcase.include? top_match }
270
+ return_hash[:id] = subject.Subject_ID.text
271
+ end
272
+ end
273
+ end
274
+
275
+ if return_hash[:id].blank?
276
+ parsed_xml.Vocabulary.Subject.each do |subject|
277
+ current_term = subject.Preferred_Term.text.gsub(/\(.*\)/, '').to_ascii.downcase.strip
278
+ alternative_terms = subject.elements.any? { |node| node.name == 'Term' } ? subject.Term : ''
279
+
280
+ if current_term == match_term && second_top_match_term.any? { |top_match| subject.Preferred_Parent.text.to_ascii.downcase.include? top_match }
281
+ return_hash[:id] = subject.Subject_ID.text
282
+ end
283
+ end
284
+ end
285
+
286
+ if return_hash[:id].blank?
287
+ parsed_xml.Vocabulary.Subject.each do |subject|
288
+ current_term = subject.Preferred_Term.text.gsub(/\(.*\)/, '').to_ascii.downcase.strip
289
+ alternative_terms = subject.elements.any? { |node| node.name == 'Term' } ? subject.Term : ''
290
+
291
+ if alternative_terms.present? && alternative_terms.children.any? { |alt_term| alt_term.text.to_ascii.downcase.strip == match_term} && second_top_match_term.any? { |top_match| subject.Preferred_Parent.text.to_ascii.downcase.include? top_match }
292
+ return_hash[:id] = subject.Subject_ID.text
293
+ end
294
+ end
295
+ end
296
+ end
297
+
298
+ end
299
+
300
+ if tgn_response.code == 500
301
+ raise 'TGN Server appears to not be responding for Geographic query: ' + term
302
+ end
303
+
304
+ if return_hash.present?
305
+ return_hash[:original_string_differs] = Bplgeo::Standardizer.parsed_and_original_check(geo_hash)
306
+ return return_hash
307
+ else
308
+ return nil
309
+ end
310
+ end
311
+
312
+
313
+ end
314
+ end
@@ -0,0 +1,19 @@
1
+ module Bplgeo
2
+ class TownLookup
3
+ #Only returns one result for now...
4
+ #Need to avoid cases like "Boston" and "East Boston"
5
+ def self.state_town_lookup(state_key, string)
6
+ return_tgn_id = nil
7
+ matched_terms_count = 0
8
+ matching_towns = Bplgeo::Constants::STATE_TOWN_TGN_IDS[state_key.to_sym].select {|hash| string.include?(hash[:location_name])}
9
+ matching_towns.each do |matching_town|
10
+ if matching_town[:location_name].split(' ').length > matched_terms_count
11
+ return_tgn_id = matching_town[:tgn_id]
12
+ matched_terms_count = matched_terms_count
13
+ end
14
+ end
15
+
16
+ return return_tgn_id
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Bplgeo
2
+ VERSION = "0.0.1"
3
+ end
data/lib/bplgeo.rb ADDED
@@ -0,0 +1,35 @@
1
+ module Bplgeo
2
+ require "bplgeo/constants"
3
+ require "bplgeo/parser"
4
+ require "bplgeo/standardizer"
5
+ require "bplgeo/tgn"
6
+ require "bplgeo/geonames"
7
+ require "bplgeo/town_lookup"
8
+ require "geocoder"
9
+ require "countries"
10
+ require "unidecoder"
11
+ require "typhoeus"
12
+ require "nokogiri"
13
+
14
+ def self.parse(term,parse_term=false)
15
+ return {} if term.blank?
16
+
17
+ return_hash = Bplgeo::Parser.parse_mapquest_api(term, parse_term)
18
+
19
+ if return_hash.blank?
20
+ return_hash = Bplgeo::Parser.parse_bing_api(term, parse_term)
21
+ end
22
+
23
+ if return_hash.blank?
24
+ return_hash = Bplgeo::Parser.parse_google_api(term, parse_term)
25
+ end
26
+
27
+ if return_hash.present?
28
+ return_hash[:tgn] = Bplgeo::TGN.tgn_id_from_geo_hash(return_hash)
29
+ return_hash[:geonames] = Bplgeo::Geonames.geonames_id_from_geo_hash(return_hash)
30
+ end
31
+
32
+ return return_hash
33
+
34
+ end
35
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :bplgeo do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,102 @@
1
+ require 'test_helper'
2
+
3
+ class BplgeoTest < ActiveSupport::TestCase
4
+
5
+ def test_parse
6
+ result = Bplgeo.parse('Boston, MA')
7
+ assert_equal 'Boston', result[:city_part]
8
+ assert_equal 'Massachusetts', result[:state_part]
9
+ assert_equal 'United States', result[:country_part]
10
+ assert_equal nil, result[:street_part]
11
+ assert_equal '7013445', result[:tgn][:id] if Bplgeo::TGN.getty_username != '<username>'
12
+ assert_equal false, result[:tgn][:original_string_differs] if Bplgeo::TGN.getty_username != '<username>'
13
+ assert_equal '4930956', result[:geonames][:id] if Bplgeo::Geonames.geonames_username != '<username>'
14
+ assert_equal false, result[:geonames][:original_string_differs] if Bplgeo::Geonames.geonames_username != '<username>'
15
+
16
+ result = Bplgeo.parse('New York, NY')
17
+ assert_equal 'New York', result[:city_part]
18
+ assert_equal 'New York', result[:state_part]
19
+ assert_equal 'United States', result[:country_part]
20
+ assert_equal nil, result[:street_part]
21
+ assert_equal '7007567', result[:tgn][:id] if Bplgeo::TGN.getty_username != '<username>'
22
+ assert_equal false, result[:tgn][:original_string_differs] if Bplgeo::TGN.getty_username != '<username>'
23
+ assert_equal '5128638', result[:geonames][:id] if Bplgeo::Geonames.geonames_username != '<username>'
24
+ assert_equal false, result[:geonames][:original_string_differs] if Bplgeo::Geonames.geonames_username != '<username>'
25
+
26
+ result = Bplgeo.parse('Washington, DC')
27
+ assert_equal 'Washington', result[:city_part]
28
+ assert_equal 'District of Columbia', result[:state_part]
29
+ assert_equal 'United States', result[:country_part]
30
+ assert_equal nil, result[:street_part]
31
+ assert_equal '7013962', result[:tgn][:id] if Bplgeo::TGN.getty_username != '<username>'
32
+ assert_equal false, result[:tgn][:original_string_differs] if Bplgeo::TGN.getty_username != '<username>'
33
+ assert_equal '4140963', result[:geonames][:id] if Bplgeo::Geonames.geonames_username != '<username>'
34
+ assert_equal false, result[:geonames][:original_string_differs] if Bplgeo::Geonames.geonames_username != '<username>'
35
+
36
+ result = Bplgeo.parse('Roxbury (Boston, Mass.)')
37
+ assert_equal 'Boston', result[:city_part]
38
+ assert_equal 'Massachusetts', result[:state_part]
39
+ assert_equal 'United States', result[:country_part]
40
+ assert_equal 'Roxbury', result[:neighborhood_part]
41
+ assert_equal nil, result[:street_part]
42
+ assert_equal '7015002', result[:tgn][:id] if Bplgeo::TGN.getty_username != '<username>'
43
+ assert_equal false, result[:tgn][:original_string_differs] if Bplgeo::TGN.getty_username != '<username>'
44
+ #FIXME?
45
+ assert_equal '4949151', result[:geonames][:id] if Bplgeo::Geonames.geonames_username != '<username>'
46
+ assert_equal false, result[:geonames][:original_string_differs] if Bplgeo::Geonames.geonames_username != '<username>'
47
+
48
+ result = Bplgeo.parse('Roxbury, Mass.')
49
+ assert_equal 'Boston', result[:city_part]
50
+ assert_equal 'Massachusetts', result[:state_part]
51
+ assert_equal 'United States', result[:country_part]
52
+ assert_equal 'Roxbury', result[:neighborhood_part]
53
+ assert_equal nil, result[:street_part]
54
+ assert_equal '7015002', result[:tgn][:id] if Bplgeo::TGN.getty_username != '<username>'
55
+ assert_equal false, result[:tgn][:original_string_differs] if Bplgeo::TGN.getty_username != '<username>'
56
+ #FIXME?
57
+ assert_equal '4949151', result[:geonames][:id] if Bplgeo::Geonames.geonames_username != '<username>'
58
+ assert_equal false, result[:geonames][:original_string_differs] if Bplgeo::Geonames.geonames_username != '<username>'
59
+
60
+ result = Bplgeo.parse('Vietnam')
61
+ assert_equal nil, result[:city_part]
62
+ assert_equal nil, result[:state_part]
63
+ assert_equal 'Vietnam', result[:country_part]
64
+ assert_equal nil, result[:neighborhood_part]
65
+ assert_equal '1000145', result[:tgn][:id] if Bplgeo::TGN.getty_username != '<username>'
66
+ assert_equal nil, result[:street_part]
67
+ assert_equal false, result[:tgn][:original_string_differs] if Bplgeo::TGN.getty_username != '<username>'
68
+
69
+ result = Bplgeo.parse('Soviet Union')
70
+ assert_equal nil, result[:city_part]
71
+ assert_equal nil, result[:state_part]
72
+ assert_equal nil, result[:country_part]
73
+ assert_equal nil, result[:neighborhood_part]
74
+ assert_equal nil, result[:tgn]
75
+ assert_equal nil, result[:street_part]
76
+
77
+ #FIXME: Should eventually still return Fenway even if not a TGN neighborhood... rewrite pending.
78
+ result = Bplgeo.parse('Fenway (Boston, Mass.)')
79
+ assert_equal 'Boston', result[:city_part]
80
+ assert_equal 'Massachusetts', result[:state_part]
81
+ assert_equal 'United States', result[:country_part]
82
+ assert_equal nil, result[:neighborhood_part]
83
+ assert_equal '7013445', result[:tgn][:id] if Bplgeo::TGN.getty_username != '<username>'
84
+ assert_equal 'TODO: Not Implemented for Google Results', result[:street_part]
85
+ assert_equal true, result[:tgn][:original_string_differs] if Bplgeo::TGN.getty_username != '<username>'
86
+
87
+ #Should find the Michigan Atlanta over the Georgia Atlanta
88
+ #State part from an API giving me Atlanta????
89
+ result = Bplgeo.parse('Atlanta, MI')
90
+ assert_equal 'Atlanta', result[:city_part]
91
+ assert_equal 'Michigan', result[:state_part]
92
+ assert_equal 'United States', result[:country_part]
93
+ assert_equal nil, result[:neighborhood_part]
94
+ assert_equal '2051159', result[:tgn][:id] if Bplgeo::TGN.getty_username != '<username>'
95
+ assert_equal false, result[:tgn][:original_string_differs] if Bplgeo::TGN.getty_username != '<username>'
96
+ assert_equal '4984500', result[:geonames][:id] if Bplgeo::Geonames.geonames_username != '<username>'
97
+ assert_equal false, result[:geonames][:original_string_differs] if Bplgeo::Geonames.geonames_username != '<username>'
98
+
99
+
100
+
101
+ end
102
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Dummy::Application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
6
+ <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require "bplgeo"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
+ # config.time_zone = 'Central Time (US & Canada)'
17
+
18
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
+ # config.i18n.default_locale = :de
21
+ end
22
+ end
23
+
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,23 @@
1
+ development:
2
+ #scanned_image_drive: /home/bluewolf/mapped/scan_images/BPLDC/_
3
+ #getty_username: bplib
4
+ getty_password: 8{83N78kO;B)2
5
+ geonames_username: boston_library
6
+ mapquest_key: Fmjtd%7Cluubn1utn0%2Ca2%3Do5-90b00a
7
+ bing_key: Avmp8UMpfYiAJOYa2D-6_cykJoprZsvvN5YLv6SDalvN-BZnW9KMlCzjIV7Zrtmn
8
+ timeout: 100
9
+ test: &TEST
10
+ #scanned_image_drive: /home/bluewolf/mapped/scan_images/BPLDC/_
11
+ #getty_username: bplib
12
+ getty_password: 8{83N78kO;B)2
13
+ geonames_username: boston_library
14
+ mapquest_key: Fmjtd%7Cluubn1utn0%2Ca2%3Do5-90b00a
15
+ bing_key: Avmp8UMpfYiAJOYa2D-6_cykJoprZsvvN5YLv6SDalvN-BZnW9KMlCzjIV7Zrtmn
16
+ timeout: 100
17
+ production:
18
+ getty_username: bplib
19
+ getty_password: 8{83N78kO;B)2
20
+ geonames_username: boston_library
21
+ mapquest_key: Fmjtd%7Cluubn1utn0%2Ca2%3Do5-90b00a
22
+ bing_key: Avmp8UMpfYiAJOYa2D-6_cykJoprZsvvN5YLv6SDalvN-BZnW9KMlCzjIV7Zrtmn
23
+ timeout: 7