Class: Qa::Authorities::Getty::Ulan
- Includes:
- WebServiceBase
- Defined in:
- lib/qa/authorities/getty/ulan.rb
Instance Attribute Summary
Attributes included from WebServiceBase
Instance Method Summary collapse
-
#build_query_url(q) ⇒ Object
Replace ampersands, otherwise the query will fail.
- #find(id) ⇒ Object
- #find_url(id) ⇒ Object
-
#json(*args) ⇒ Object
get_json is not ideomatic, so we’ll make an alias.
- #request_options ⇒ Object
- #search(q) ⇒ Object
- #sparql(q) ⇒ Object
- #untaint(q) ⇒ Object
Methods included from WebServiceBase
Methods inherited from Base
Instance Method Details
#build_query_url(q) ⇒ Object
Replace ampersands, otherwise the query will fail
15 16 17 |
# File 'lib/qa/authorities/getty/ulan.rb', line 15 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
48 49 50 |
# File 'lib/qa/authorities/getty/ulan.rb', line 48 def find(id) json(find_url(id)) end |
#find_url(id) ⇒ Object
52 53 54 |
# File 'lib/qa/authorities/getty/ulan.rb', line 52 def find_url(id) "http://vocab.getty.edu/ulan/#{id}.json" end |
#json(*args) ⇒ Object
get_json is not ideomatic, so we’ll make an alias
10 11 12 |
# File 'lib/qa/authorities/getty/ulan.rb', line 10 def json(*args) get_json(*args) end |
#request_options ⇒ Object
56 57 58 |
# File 'lib/qa/authorities/getty/ulan.rb', line 56 def { accept: 'application/sparql-results+json' } end |
#search(q) ⇒ Object
5 6 7 |
# File 'lib/qa/authorities/getty/ulan.rb', line 5 def search(q) (json(build_query_url(q))) end |
#sparql(q) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/qa/authorities/getty/ulan.rb', line 19 def sparql(q) search = untaint(q) # if more than one term is supplied, check both preferred and alt labels 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 # The full text index matches on fields besides the term, so we filter to ensure the match is in the term. 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
44 45 46 |
# File 'lib/qa/authorities/getty/ulan.rb', line 44 def untaint(q) q.gsub(/[^\w\s-]/, '') end |