Class: Qa::Authorities::Getty

Inherits:
AuthorityWithSubAuthority show all
Includes:
WebServiceBase
Defined in:
lib/qa/authorities/getty.rb

Instance Attribute Summary

Attributes included from WebServiceBase

#raw_response

Attributes inherited from AuthorityWithSubAuthority

#sub_authority

Instance Method Summary collapse

Methods included from WebServiceBase

#get_json

Methods inherited from AuthorityWithSubAuthority

#initialize

Methods inherited from Base

#all, #full_record

Constructor Details

This class inherits a constructor from Qa::Authorities::AuthorityWithSubAuthority

Instance Method Details

#build_query_url(q) ⇒ Object



20
21
22
23
# File 'lib/qa/authorities/getty.rb', line 20

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



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

def find id
  json(find_url(id))
end

#find_url(id) ⇒ Object



44
45
46
# File 'lib/qa/authorities/getty.rb', line 44

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



16
17
18
# File 'lib/qa/authorities/getty.rb', line 16

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

#request_optionsObject



48
49
50
# File 'lib/qa/authorities/getty.rb', line 48

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

#search(q) ⇒ Object



11
12
13
# File 'lib/qa/authorities/getty.rb', line 11

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

#sparql(q) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/qa/authorities/getty.rb', line 25

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/#{@sub_authority}/> ;
             gvp:prefLabelGVP [skosxl:literalForm ?name].
          FILTER regex(?name, \"#{search}\", \"i\") .
        } LIMIT 10"
end

#sub_authoritiesObject



7
8
9
# File 'lib/qa/authorities/getty.rb', line 7

def sub_authorities
  [ "aat" ]
end

#untaint(q) ⇒ Object



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

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