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, request_header: {}, language: nil, replacements: {}, subauth: nil, format: 'json', performance_data: false) ⇒ Hash, String

Note:

All parameters after request_header are deprecated and will be removed in the next major release.

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

  • request_header (Hash) (defaults to: {})

    optional attributes that can be appended to the generated URL

  • language (Hash) (defaults to: nil)

    a customizable set of options

  • replacements (Hash) (defaults to: {})

    a customizable set of options

  • subauthority (Hash)

    a customizable set of options

  • format (Hash) (defaults to: 'json')

    a customizable set of options

  • performance_data (Hash) (defaults to: false)

    a customizable set of options

Options Hash (language:):

  • language (Symbol)

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

Options Hash (replacements:):

  • replacement (Hash)

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

Options Hash (format:):

  • return (String)

    data in this format

Options Hash (performance_data:):

  • true (Boolean)

    if include_performance_data should be returned with the results; otherwise, false (default: false)

Returns:

  • (Hash, String)

    normalized json results when format=‘json’; otherwise, serialized RDF in the requested format

Raises:



46
47
48
49
50
51
52
53
54
55
# File 'lib/qa/authorities/linked_data/find_term.rb', line 46

def find(id, request_header: {}, language: nil, replacements: {}, subauth: nil, format: 'json', performance_data: false) # rubocop:disable Metrics/ParameterLists
  request_header = build_request_header(language: language, replacements: replacements, subauth: subauth, format: format, performance_data: performance_data) if request_header.empty?
  unpack_request_header(request_header)
  raise Qa::InvalidLinkedDataAuthority, "Unable to initialize linked data term sub-authority #{subauthority}" unless subauthority.nil? || term_subauthority?(subauthority)
  @id = id
  url = authority_service.build_url(action_config: term_config, action: :term, action_request: normalize_id, request_header: request_header)
  Rails.logger.info "QA Linked Data term url: #{url}"
  load_graph(url: url)
  normalize_results
end