Class: Qa::Authorities::Getty::TGN
Instance Attribute Summary
#raw_response
Instance Method Summary
collapse
#get_json, #json, #response
Methods inherited from Base
#all, #full_record
Instance Method Details
#build_query_url(q) ⇒ Object
9
10
11
12
13
14
|
# File 'lib/qa/authorities/getty/tgn.rb', line 9
def build_query_url(q)
query = URI.escape(sparql(untaint(q)))
"http://vocab.getty.edu/sparql.json?query=#{query.gsub('&', '%26').gsub(',[%5E,]+,[%5E,]+$', '%2C[^%2C]%2B%2C[^%2C]%2B%24')}&_implicit=false&implicit=true&_equivalent=false&_form=%2Fsparql"
end
|
#find(id) ⇒ Object
42
43
44
|
# File 'lib/qa/authorities/getty/tgn.rb', line 42
def find(id)
json(find_url(id))
end
|
#find_url(id) ⇒ Object
46
47
48
|
# File 'lib/qa/authorities/getty/tgn.rb', line 46
def find_url(id)
"http://vocab.getty.edu/tgn/#{id}.json"
end
|
#request_options ⇒ Object
50
51
52
|
# File 'lib/qa/authorities/getty/tgn.rb', line 50
def request_options
{ accept: 'application/sparql-results+json' }
end
|
#search(q) ⇒ Object
5
6
7
|
# File 'lib/qa/authorities/getty/tgn.rb', line 5
def search(q)
parse_authority_response(json(build_query_url(q)))
end
|
#sparql(q) ⇒ Object
Use a regex to exclude the continent and ‘world’ from the query If only one word is entered only search the name (not the parent string) If more than one word is entered, one word must appear in the name, and all words in either parent or name
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/qa/authorities/getty/tgn.rb', line 19
def sparql(q) search = untaint(q)
if search.include?(' ')
clauses = search.split(' ').collect do |i|
%((regex(?name, "#{i}", "i") || regex(?alt, "#{i}", "i")))
end
ex = "(#{clauses.join(' && ')})"
else
ex = %(regex(?name, "#{search}", "i"))
end
%(SELECT DISTINCT ?s ?name ?par {
?s a skos:Concept; luc:term "#{search}";
skos:inScheme <http://vocab.getty.edu/ulan/> ;
gvp:prefLabelGVP [skosxl:literalForm ?name] ;
gvp:parentString ?par .
FILTER #{ex} .
} ORDER BY ?name ASC(?par)).gsub(/[\s\n]+/, " ")
end
|
#untaint(q) ⇒ Object
38
39
40
|
# File 'lib/qa/authorities/getty/tgn.rb', line 38
def untaint(q)
q.gsub(/[^\w\s-]/, '')
end
|