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, jsonld: false) ⇒ 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:



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

def find(id, language: nil, replacements: {}, subauth: nil, jsonld: false)
  raise Qa::InvalidLinkedDataAuthority, "Unable to initialize linked data term sub-authority #{subauth}" unless subauth.nil? || term_subauthority?(subauth)
  @language = Qa::LinkedData::LanguageService.preferred_language(user_language: language, authority_language: term_config.term_language)
  url = Qa::LinkedData::AuthorityUrlService.build_url(action_config: term_config, action: :term, action_request: id, substitutions: replacements, subauthority: subauth)
  Rails.logger.info "QA Linked Data term url: #{url}"
  load_graph(url: url)
  return "{}" unless full_graph.size.positive?
  return full_graph.dump(:jsonld, standard_prefixes: true) if jsonld
  parse_term_authority_response(id)
end