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

Inherits:
Object
  • Object
show all
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



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

def initialize(term_config)
  @term_config = term_config
end

Instance Attribute Details

#term_configObject (readonly)

Returns the value of attribute term_config.



18
19
20
# File 'lib/qa/authorities/linked_data/find_term.rb', line 18

def term_config
  @term_config
end

Instance Method Details

#find(id, language: nil, replacements: {}, subauth: nil, format: nil, jsonld: false, performance_data: false) ⇒ Hash

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:

  • (Hash)

    json results

Raises:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/qa/authorities/linked_data/find_term.rb', line 42

def find(id, language: nil, replacements: {}, subauth: nil, format: nil, jsonld: false, performance_data: false) # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
  # TODO: When jsonld parameter is removed, the format parameter should default to 'json'.  Not making this change now for backward compatibility of the default for jsonld parameter.
  raise Qa::InvalidLinkedDataAuthority, "Unable to initialize linked data term sub-authority #{subauth}" unless subauth.nil? || term_subauthority?(subauth)
  @language = language_service.preferred_language(user_language: language, authority_language: term_config.term_language)
  @id = id
  @performance_data = performance_data
  @format = format
  @jsonld = jsonld if @format.blank?
  if jsonld
    Qa.deprecation_warning(
      in_msg: 'Qa::Authorities::LinkedData::FindTerm',
      msg: "jsonld parameter to find method is deprecated; use `format: 'jsonld'` instead"
    )
  end
  url = authority_service.build_url(action_config: term_config, action: :term, action_request: normalize_id, substitutions: replacements, subauthority: subauth, language: @language)
  Rails.logger.info "QA Linked Data term url: #{url}"
  load_graph(url: url)
  normalize_results
end