Class: Qa::Authorities::Getty::AAT

Inherits:
Base
  • Object
show all
Includes:
WebServiceBase
Defined in:
lib/qa/authorities/getty/aat.rb

Instance Attribute Summary

Attributes included from WebServiceBase

#raw_response

Instance Method Summary collapse

Methods included from WebServiceBase

#get_json

Methods inherited from Base

#all, #full_record

Instance Method Details

#build_query_url(q) ⇒ Object



13
14
15
16
# File 'lib/qa/authorities/getty/aat.rb', line 13

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



33
34
35
# File 'lib/qa/authorities/getty/aat.rb', line 33

def find id
  json(find_url(id))
end

#find_url(id) ⇒ Object



37
38
39
# File 'lib/qa/authorities/getty/aat.rb', line 37

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



9
10
11
# File 'lib/qa/authorities/getty/aat.rb', line 9

def json(*args)
  get_json(*args)
end

#request_optionsObject



41
42
43
# File 'lib/qa/authorities/getty/aat.rb', line 41

def request_options
  { accept: 'application/sparql-results+json'}
end

#search(q) ⇒ Object



4
5
6
# File 'lib/qa/authorities/getty/aat.rb', line 4

def search q
  parse_authority_response(json(build_query_url(q)))
end

#sparql(q) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# 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\") .
        } LIMIT 10"
end

#untaint(q) ⇒ Object



29
30
31
# File 'lib/qa/authorities/getty/aat.rb', line 29

def untaint(q)
  q.gsub(/[^\w\s-]/, '')
end