Class: Qa::Authorities::Getty
- Inherits:
-
WebServiceBase
- Object
- Base
- WebServiceBase
- Qa::Authorities::Getty
- Defined in:
- lib/qa/authorities/getty.rb
Instance Attribute Summary
Attributes inherited from WebServiceBase
Attributes inherited from Base
Instance Method Summary collapse
- #build_query_url(q) ⇒ Object
- #find(id) ⇒ Object
- #find_url(id) ⇒ Object
-
#initialize(*args) ⇒ Getty
constructor
A new instance of Getty.
-
#json(*args) ⇒ Object
get_json is not ideomatic, so we’ll make an alias.
- #request_options ⇒ Object
- #search(q) ⇒ Object
- #sparql(q) ⇒ Object
- #sub_authorities ⇒ Object
- #untaint(q) ⇒ Object
Methods inherited from WebServiceBase
Methods inherited from Base
Constructor Details
#initialize(*args) ⇒ Getty
Returns a new instance of Getty.
6 7 8 9 10 |
# File 'lib/qa/authorities/getty.rb', line 6 def initialize *args super @sub_authority ||= args.first raise "No sub-authority provided" if .nil? end |
Instance Method Details
#build_query_url(q) ⇒ Object
25 26 27 28 |
# File 'lib/qa/authorities/getty.rb', line 25 def build_query_url q query = URI.escape(sparql(untaint(q))) "http://vocab.getty.edu/sparql.json?query=#{URI.escape(sparql(q))}&_implicit=false&implicit=true&_equivalent=false&_form=%2Fsparql" end |
#find(id) ⇒ Object
44 45 46 |
# File 'lib/qa/authorities/getty.rb', line 44 def find id json(find_url(id)) end |
#find_url(id) ⇒ Object
48 49 50 |
# File 'lib/qa/authorities/getty.rb', line 48 def find_url id "http://vocab.getty.edu/#{@sub_authority}/#{id}.json" end |
#json(*args) ⇒ Object
get_json is not ideomatic, so we’ll make an alias
21 22 23 |
# File 'lib/qa/authorities/getty.rb', line 21 def json(*args) get_json(*args) end |
#request_options ⇒ Object
52 53 54 55 |
# File 'lib/qa/authorities/getty.rb', line 52 def # Don't pass a request header. See http://answers.semanticweb.com/questions/31906/getty-sparql-gives-a-404-if-you-pass-accept-applicationjson { } end |
#search(q) ⇒ Object
16 17 18 |
# File 'lib/qa/authorities/getty.rb', line 16 def search q (json(build_query_url(q))) end |
#sparql(q) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/qa/authorities/getty.rb', line 30 def sparql(q) sparql = "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> SELECT * WHERE { ?s skos:prefLabel ?name . ?s skos:inScheme <http://vocab.getty.edu/#{@sub_authority}/> . ?s rdf:type <http://vocab.getty.edu/ontology#Concept> . FILTER regex(?name, \"#{untaint(q)}\", \"i\") . FILTER langMatches( lang(?name), \"EN\" ) . } LIMIT 10" end |
#sub_authorities ⇒ Object
12 13 14 |
# File 'lib/qa/authorities/getty.rb', line 12 def [ "aat" ] end |
#untaint(q) ⇒ Object
40 41 42 |
# File 'lib/qa/authorities/getty.rb', line 40 def untaint(q) q.gsub(/[^\w\s-]/, '') end |