Class: Qa::Authorities::Getty::AAT
- Includes:
- WebServiceBase
- Defined in:
- lib/qa/authorities/getty/aat.rb
Instance Attribute Summary
Attributes included from WebServiceBase
Instance Method Summary collapse
- #build_query_url(q) ⇒ Object
- #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
14 15 16 |
# File 'lib/qa/authorities/getty/aat.rb', line 14 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
34 35 36 |
# File 'lib/qa/authorities/getty/aat.rb', line 34 def find(id) json(find_url(id)) end |
#find_url(id) ⇒ Object
38 39 40 |
# File 'lib/qa/authorities/getty/aat.rb', line 38 def find_url(id) "http://vocab.getty.edu/aat/#{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/aat.rb', line 10 def json(*args) get_json(*args) end |
#request_options ⇒ Object
42 43 44 |
# File 'lib/qa/authorities/getty/aat.rb', line 42 def { accept: 'application/sparql-results+json' } end |
#search(q) ⇒ Object
5 6 7 |
# File 'lib/qa/authorities/getty/aat.rb', line 5 def search(q) (json(build_query_url(q))) end |
#sparql(q) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/qa/authorities/getty/aat.rb', line 18 def sparql(q) search = untaint(q) # The full text index matches on fields besides the term, so we filter to ensure the match is in the term. sparql = "SELECT ?s ?name { ?s a skos:Concept; luc:term \"#{search}\"; skos:inScheme <http://vocab.getty.edu/aat/> ; gvp:prefLabelGVP [skosxl:literalForm ?name]. FILTER regex(?name, \"#{search}\", \"i\") . } ORDER BY ?name" sparql end |
#untaint(q) ⇒ Object
30 31 32 |
# File 'lib/qa/authorities/getty/aat.rb', line 30 def untaint(q) q.gsub(/[^\w\s-]/, '') end |