geomash 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/geomash/parser.rb +5 -0
- data/lib/geomash/tgn.rb +19 -7
- data/lib/geomash/version.rb +1 -1
- data/test/tgn_test.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9fa71cc1b19bda8494204564e612606ffe8f6e6
|
4
|
+
data.tar.gz: 92febff016bf79bc87751a8de84d692590d95470
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 468e826603bf98ebf5ebcbe941174352ced6d5a1e222713678a716f895ebf79d369990c8c1bc950d8f27f25cd061ab26993d328fc68c0b3226e1ee01103cb763
|
7
|
+
data.tar.gz: 0452c64e9256ace6629475a9417709dcabcf7bf15dc2fff4ce26138edb5917131a97ff60d32e370760392b0052123664112f6bc1c36f7465369156847cd1f8a1
|
data/lib/geomash/parser.rb
CHANGED
@@ -289,6 +289,11 @@ module Geomash
|
|
289
289
|
return_hash[:term_differs_from_tgn] ||= google_api_result[best_match_index].data['partial_match'] unless google_api_result[best_match_index].data['partial_match'].blank?
|
290
290
|
end
|
291
291
|
|
292
|
+
#This changed in Google... need a better way to handle this
|
293
|
+
if return_hash[:state_part] == 'Nord-Pas-de-Calais Picardie'
|
294
|
+
return_hash[:state_part] = 'Picardy'
|
295
|
+
end
|
296
|
+
|
292
297
|
#FIXME: Google free API rate limit is 5 requests / 1 second now (used to be 10). Need a better way to handle this.
|
293
298
|
sleep(0.1)
|
294
299
|
|
data/lib/geomash/tgn.rb
CHANGED
@@ -404,22 +404,20 @@ EXAMPLE SPARQL:
|
|
404
404
|
OPTIONAL {<#{place_uri}> <http://www.w3.org/2004/02/skos/core#prefLabel> ?place_label_latn_pinyin
|
405
405
|
FILTER langMatches( lang(?place_label_latn_pinyin), "zh-latn-pinyin" )
|
406
406
|
}
|
407
|
-
OPTIONAL {<#{place_uri}> <http://www.w3.org/2004/02/skos/core#altLabel> ?place_label_alt
|
408
|
-
FILTER langMatches( lang(?place_label_alt), "en" )
|
409
|
-
}
|
410
407
|
<#{place_uri}> <http://vocab.getty.edu/ontology#placeTypePreferred> ?aat_pref
|
411
408
|
} UNION
|
412
409
|
}
|
413
410
|
end
|
414
411
|
|
415
412
|
query = query[0..-12]
|
416
|
-
query += ". } GROUP BY ?identifier_place ?place_label_default ?place_label_en ?place_label_latn_pinyin ?
|
413
|
+
query += ". } GROUP BY ?identifier_place ?place_label_default ?place_label_en ?place_label_latn_pinyin ?aat_pref"
|
417
414
|
query = query.squish
|
418
415
|
|
419
416
|
tgn_response_for_aat = Typhoeus::Request.post("http://vocab.getty.edu/sparql.json", :body=>{:query=>query}, :timeout=>500)
|
420
417
|
as_json_tgn_response_for_aat = JSON.parse(tgn_response_for_aat.body)
|
421
418
|
|
422
419
|
as_json_tgn_response_for_aat["results"]["bindings"].each do |aat_response|
|
420
|
+
tgn_term = nil
|
423
421
|
tgn_term_type = aat_response['aat_pref']['value'].split('/').last
|
424
422
|
|
425
423
|
if aat_response['place_label_en'].present? && aat_response['place_label_en']['value'] != '-'
|
@@ -430,10 +428,24 @@ EXAMPLE SPARQL:
|
|
430
428
|
tgn_term = aat_response['place_label_latn_pinyin']['value']
|
431
429
|
elsif aat_response['place_label_latn_notone'].present? && aat_response['place_label_latn_notone']['value'] != '-'
|
432
430
|
tgn_term = aat_response['place_label_latn_notone']['value']
|
433
|
-
elsif aat_response['place_label_alt'].present? && aat_response['place_label_alt']['value'] != '-'
|
434
|
-
tgn_term = aat_response['place_label_alt']['value']
|
435
431
|
else
|
436
|
-
|
432
|
+
#Just take the first prefLabel... could perhaps do some preference eventually... see 7002883 for an example of only a french prefLabel
|
433
|
+
default_label_response = Typhoeus::Request.get("http://vocab.getty.edu/download/json", :params=>{:uri=>"http://vocab.getty.edu/tgn/#{aat_response['identifier_place']}.json"}, :timeout=>500)
|
434
|
+
JSON.parse(default_label_response.body)['results']['bindings'].each do |ntriple|
|
435
|
+
case ntriple['Predicate']['value']
|
436
|
+
when 'http://www.w3.org/2004/02/skos/core#prefLabel'
|
437
|
+
if ntriple['Object']['xml:lang'].present? && ntriple['Object']['xml:lang'] == 'en'
|
438
|
+
tgn_term = ntriple['Object']['value']
|
439
|
+
else
|
440
|
+
tgn_term ||= ntriple['Object']['value']
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
if tgn_term.blank?
|
446
|
+
raise "Could not find a label for broader: #{place_uri} of base term: #{tgn_id}"
|
447
|
+
end
|
448
|
+
|
437
449
|
end
|
438
450
|
|
439
451
|
case tgn_term_type
|
data/lib/geomash/version.rb
CHANGED
data/test/tgn_test.rb
CHANGED
@@ -26,6 +26,17 @@ class TGNTest < ActiveSupport::TestCase
|
|
26
26
|
assert_equal 'Asia', result[:hier_geo][:continent]
|
27
27
|
assert_equal 'Harbin', result[:non_hier_geo][:value]
|
28
28
|
assert_nil result[:non_hier_geo][:qualifier]
|
29
|
+
|
30
|
+
result = Geomash::TGN.get_tgn_data('7008038')
|
31
|
+
assert_equal '48.866667', result[:coords][:latitude]
|
32
|
+
assert_equal '2.333333', result[:coords][:longitude]
|
33
|
+
assert_equal '48.866667,2.333333', result[:coords][:combined]
|
34
|
+
assert_equal 'Paris', result[:hier_geo][:city]
|
35
|
+
assert_equal 'Île-de-France', result[:hier_geo][:province]
|
36
|
+
assert_equal 'France', result[:hier_geo][:country]
|
37
|
+
assert_equal 'Europe', result[:hier_geo][:continent]
|
38
|
+
assert_equal nil, result[:non_hier_geo][:value]
|
39
|
+
assert_nil result[:non_hier_geo][:qualifier]
|
29
40
|
end
|
30
41
|
end
|
31
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geomash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boston Public Library
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|