Class: Qa::Authorities::Getty::Ulan
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
Replace ampersands, otherwise the query will fail
10
11
12
|
# File 'lib/qa/authorities/getty/ulan.rb', line 10
def build_query_url(q)
"http://vocab.getty.edu/sparql.json?query=#{URI.escape(sparql(q)).gsub('&', '%26')}&_implicit=false&implicit=true&_equivalent=false&_form=%2Fsparql"
end
|
#find(id) ⇒ Object
43
44
45
|
# File 'lib/qa/authorities/getty/ulan.rb', line 43
def find(id)
json(find_url(id))
end
|
#find_url(id) ⇒ Object
47
48
49
|
# File 'lib/qa/authorities/getty/ulan.rb', line 47
def find_url(id)
"http://vocab.getty.edu/ulan/#{id}.json"
end
|
#request_options ⇒ Object
51
52
53
|
# File 'lib/qa/authorities/getty/ulan.rb', line 51
def request_options
{ accept: 'application/sparql-results+json' }
end
|
#search(q) ⇒ Object
5
6
7
|
# File 'lib/qa/authorities/getty/ulan.rb', line 5
def search(q)
parse_authority_response(json(build_query_url(q)))
end
|
#sparql(q) ⇒ Object
rubocop:disable Metrics/MethodLength
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/qa/authorities/getty/ulan.rb', line 14
def sparql(q) search = untaint(q)
if search.include?(' ')
ex = "("
search.split(' ').each do |i|
ex += "regex(CONCAT(?name, ' ', ?alt), \"#{i}\",\"i\" ) && "
end
ex = ex[0..ex.length - 4]
ex += ")"
else
ex = "regex(?name, \"#{search}\", \"i\")"
end
sparql = "SELECT DISTINCT ?s ?name ?bio {
?s a skos:Concept; luc:term \"#{search}\";
skos:inScheme <http://vocab.getty.edu/ulan/> ;
gvp:prefLabelGVP [skosxl:literalForm ?name] ;
foaf:focus/gvp:biographyPreferred [schema:description ?bio] ;
skos:altLabel ?alt .
FILTER #{ex} .
} ORDER BY ?name"
sparql
end
|
#untaint(q) ⇒ Object
39
40
41
|
# File 'lib/qa/authorities/getty/ulan.rb', line 39
def untaint(q)
q.gsub(/[^\w\s-]/, '')
end
|