Class: Qa::Authorities::LinkedData::FindTerm

Inherits:
Object
  • Object
show all
Includes:
RdfHelper
Defined in:
lib/qa/authorities/linked_data/find_term.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(term_config) ⇒ FindTerm

Returns a new instance of FindTerm.

Parameters:

  • term_config (TermConfig)

    The term portion of the config



9
10
11
# File 'lib/qa/authorities/linked_data/find_term.rb', line 9

def initialize(term_config)
  @term_config = term_config
end

Instance Attribute Details

#term_configObject (readonly)

Returns the value of attribute term_config.



13
14
15
# File 'lib/qa/authorities/linked_data/find_term.rb', line 13

def term_config
  @term_config
end

Instance Method Details

#find(id, language: nil, replacements: {}, subauth: nil) ⇒ String

Find a single term in a linked data authority

Examples:

Json Results for Linked Data Term

{ "uri":"http://id.worldcat.org/fast/530369",
  "id":"530369","label":"Cornell University",
  "altlabel":["Ithaca (N.Y.). Cornell University"],
  "sameas":["http://id.loc.gov/authorities/names/n79021621","https://viaf.org/viaf/126293486"],
  "predicates":{
  "http://purl.org/dc/terms/identifier":"530369",
  "http://www.w3.org/2004/02/skos/core#inScheme":["http://id.worldcat.org/fast/ontology/1.0/#fast","http://id.worldcat.org/fast/ontology/1.0/#facet-Corporate"],
  "http://www.w3.org/1999/02/22-rdf-syntax-ns#type":"http://schema.org/Organization",
  "http://www.w3.org/2004/02/skos/core#prefLabel":"Cornell University",
  "http://schema.org/name":["Cornell University","Ithaca (N.Y.). Cornell University"],
  "http://www.w3.org/2004/02/skos/core#altLabel":["Ithaca (N.Y.). Cornell University"],
  "http://schema.org/sameAs":["http://id.loc.gov/authorities/names/n79021621","https://viaf.org/viaf/126293486"] } }

Parameters:

  • the (String)

    id of the term to fetch

  • (optional) (Symbol)

    language: language used to select literals when multi-language is supported (e.g. :en, :fr, etc.)

  • (optional) (Hash)

    replacements: replacement values with { pattern_name (defined in YAML config) => value }

  • subauth: (String) (defaults to: nil)

    the subauthority from which to fetch the term

Returns:

  • (String)

    json results

Raises:



36
37
38
39
40
41
42
43
44
# File 'lib/qa/authorities/linked_data/find_term.rb', line 36

def find(id, language: nil, replacements: {}, subauth: nil)
  raise Qa::InvalidLinkedDataAuthority, "Unable to initialize linked data term sub-authority #{subauth}" unless subauth.nil? || term_subauthority?(subauth)
  language ||= term_config.term_language
  url = term_config.term_url_with_replacements(id, subauth, replacements)
  Rails.logger.info "QA Linked Data term url: #{url}"
  graph = get_linked_data(url)
  return "{}" unless graph.size.positive?
  parse_term_authority_response(id, graph, language)
end