class Qa::Authorities::Getty::Ulan
Public Instance Methods
build_query_url(q)
click to toggle source
Replace ampersands, otherwise the query will fail
# File lib/qa/authorities/getty/ulan.rb, line 10 def build_query_url(q) "http://vocab.getty.edu/sparql.json?query=#{ERB::Util.url_encode(sparql(q)).gsub('&', '%26')}&_implicit=false&implicit=true&_equivalent=false&_form=%2Fsparql" end
find(id)
click to toggle source
# File lib/qa/authorities/getty/ulan.rb, line 40 def find(id) json(find_url(id)) end
find_url(id)
click to toggle source
# File lib/qa/authorities/getty/ulan.rb, line 44 def find_url(id) "http://vocab.getty.edu/download/json?uri=http://vocab.getty.edu/ulan/#{id}.json" end
request_options()
click to toggle source
# File lib/qa/authorities/getty/ulan.rb, line 48 def request_options { accept: 'application/sparql-results+json' } end
search(q)
click to toggle source
# File lib/qa/authorities/getty/ulan.rb, line 5 def search(q) parse_authority_response(json(build_query_url(q))) end
sparql(q)
click to toggle source
# File lib/qa/authorities/getty/ulan.rb, line 14 def sparql(q) # rubocop:disable Metrics/MethodLength search = untaint(q) # if more than one term is supplied, check both preferred and alt labels 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 # The full text index matches on fields besides the term, so we filter to ensure the match is in the term. %(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).gsub(/[\s\n]+/, " ") end
untaint(q)
click to toggle source
# File lib/qa/authorities/getty/ulan.rb, line 36 def untaint(q) q.gsub(/[^\w\s-]/, '') end