Class: Qa::Authorities::Getty::AAT
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
|
# File 'lib/qa/authorities/getty/aat.rb', line 9
def build_query_url(q)
"http://vocab.getty.edu/sparql.json?query=#{URI.escape(sparql(q))}&_implicit=false&implicit=true&_equivalent=false&_form=%2Fsparql"
end
|
#find(id) ⇒ Object
36
37
38
|
# File 'lib/qa/authorities/getty/aat.rb', line 36
def find(id)
json(find_url(id))
end
|
#find_url(id) ⇒ Object
40
41
42
|
# File 'lib/qa/authorities/getty/aat.rb', line 40
def find_url(id)
"http://vocab.getty.edu/aat/#{id}.json"
end
|
#request_options ⇒ Object
44
45
46
|
# File 'lib/qa/authorities/getty/aat.rb', line 44
def request_options
{ accept: 'application/sparql-results+json' }
end
|
#search(q) ⇒ Object
5
6
7
|
# File 'lib/qa/authorities/getty/aat.rb', line 5
def search(q)
parse_authority_response(json(build_query_url(q)))
end
|
#sparql(q) ⇒ Object
rubocop:disable Metrics/MethodLength
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/qa/authorities/getty/aat.rb', line 13
def sparql(q) search = untaint(q)
if search.include?(' ')
clauses = search.split(' ').collect do |i|
%((regex(?name, "#{i}", "i")))
end
ex = "(#{clauses.join(' && ')})"
else
ex = %(regex(?name, "#{search}", "i"))
end
%(SELECT ?s ?name {
?s a skos:Concept; luc:term "#{search}";
skos:inScheme <http://vocab.getty.edu/aat/> ;
gvp:prefLabelGVP [skosxl:literalForm ?name].
FILTER #{ex} .
} ORDER BY ?name).gsub(/[\s\n]+/, " ")
end
|
#untaint(q) ⇒ Object
32
33
34
|
# File 'lib/qa/authorities/getty/aat.rb', line 32
def untaint(q)
q.gsub(/[^\w\s-]/, '')
end
|