class Qa::Authorities::LinkedData::TermConfig

Attributes

full_config[R]
prefixes[R]
term_config[R]

Public Class Methods

new(config, prefixes = {}, full_config = nil) click to toggle source

@param [Hash] config the term portion of the config @param [Hash<Symbol><String>] prefixes URL map of prefixes to use with ldpaths @param [Qa::Authorities::LinkedData::Config] full_config the full linked data configuration that the passed in term config is part of

# File lib/qa/authorities/linked_data/config/term_config.rb, line 16
def initialize(config, prefixes = {}, full_config = nil)
  @term_config = config
  @prefixes = prefixes
  @full_config = full_config
end

Public Instance Methods

info() click to toggle source
# File lib/qa/authorities/linked_data/config/term_config.rb, line 231
def info
  return [] unless supports_term?
  auth_name = authority_name.downcase.to_s
  language = Qa::LinkedData::LanguageService.preferred_language(authority_language: language).map(&:to_s)
  details = summary_without_subauthority(auth_name, language)
  subauthorities.keys { |subauth_name| details << summary_with_subauthority(auth_name, subauth_name.downcase.to_s, language) }
  details
end
language()
Alias for: term_language
qa_replacement_patterns()
subauthorities()
Alias for: term_subauthorities
subauthorities?()
supports_language_parameter?() click to toggle source

@return [Boolean] true if supports language parameter; otherwise, false

# File lib/qa/authorities/linked_data/config/term_config.rb, line 199
def supports_language_parameter?
  qa_replacement_patterns.key? :lang
end
supports_subauthorities?() click to toggle source

@return [Boolean] true if supports language parameter; otherwise, false

# File lib/qa/authorities/linked_data/config/term_config.rb, line 194
def supports_subauthorities?
  qa_replacement_patterns.key?(:subauth) && subauthorities?
end
supports_term?() click to toggle source

Does this authority configuration have term defined? @return [True|False] true if term fetching is configured; otherwise, false

# File lib/qa/authorities/linked_data/config/term_config.rb, line 24
def supports_term?
  term_config.present?
end
term_id_expects_id?() click to toggle source

Is the term_id substitution expected to be an ID? @return [True|False] true if the id substitution is expected to be an ID in the term url; otherwise, false

# File lib/qa/authorities/linked_data/config/term_config.rb, line 43
def term_id_expects_id?
  return false if term_config.nil? || !(term_config.key? :term_id)
  term_config[:term_id] == "ID"
end
term_id_expects_uri?() click to toggle source

Is the term_id substitution expected to be a URI? @return [True|False] true if the id substitution is expected to be a URI in the term url; otherwise, false

# File lib/qa/authorities/linked_data/config/term_config.rb, line 36
def term_id_expects_uri?
  return false if term_config.nil? || !(term_config.key? :term_id)
  term_config[:term_id] == "URI"
end
term_language() click to toggle source

Return the preferred language for literal value selection for term fetch. Only applies if the authority provides language encoded literals. This is the default used for this authority if the user does not pass in a language. Only applies if the authority provides language encoded literals. @return [Symbol] the configured language for term fetch (default - :en)

# File lib/qa/authorities/linked_data/config/term_config.rb, line 52
def term_language
  return @term_language unless @term_language.nil?
  lang = Config.config_value(term_config, :language)
  return nil if lang.nil?
  lang = [lang] if lang.is_a? String
  @term_language = lang.collect(&:to_sym)
end
Also aliased as: language
term_qa_replacement_patterns() click to toggle source

Return parameters that are required for QA api @return [Hash] the configured term url parameter mappings

# File lib/qa/authorities/linked_data/config/term_config.rb, line 188
def term_qa_replacement_patterns
  term_config.fetch(:qa_replacement_patterns, {})
end
Also aliased as: qa_replacement_patterns
term_results() click to toggle source

Return results ldpaths or predicates @return [Hash] all the configured ldpaths or predicates to pull out of the results

# File lib/qa/authorities/linked_data/config/term_config.rb, line 63
def term_results
  Config.config_value(term_config, :results)
end
term_results_altlabel_ldpath() click to toggle source

Return results altlabel_ldpath @return [String] the configured ldpath to use to extract altlabel values from the results

# File lib/qa/authorities/linked_data/config/term_config.rb, line 120
def term_results_altlabel_ldpath
  Config.config_value(term_results, :altlabel_ldpath)
end
term_results_altlabel_predicate() click to toggle source

Return results altlabel_predicate @return [String] the configured predicate to use to extract altlabel values from the results

# File lib/qa/authorities/linked_data/config/term_config.rb, line 126
def term_results_altlabel_predicate
  Qa.deprecation_warning(
    in_msg: 'Qa::Authorities::LinkedData::TermConfig',
    msg: "`term_results_altlabel_predicate` is deprecated; use `term_results_altlabel_ldpath` by updating linked data " \
         "term config results in authority #{authority_name} to specify as `altlabel_ldpath`"
  )
  Config.predicate_uri(term_results, :altlabel_predicate)
end
term_results_broader_ldpath() click to toggle source

Return results broader_ldpath @return [String] the configured ldpath to use to extract URIs for broader terms from the results

# File lib/qa/authorities/linked_data/config/term_config.rb, line 137
def term_results_broader_ldpath
  Config.config_value(term_results, :broader_ldpath)
end
term_results_broader_predicate() click to toggle source

Return results broader_predicate @return [String] the configured predicate to use to extract URIs for broader terms from the results

# File lib/qa/authorities/linked_data/config/term_config.rb, line 143
def term_results_broader_predicate
  Qa.deprecation_warning(
    in_msg: 'Qa::Authorities::LinkedData::TermConfig',
    msg: "`term_results_broader_predicate` is deprecated; use `term_results_broader_ldpath` by updating linked data " \
         "term config results in authority #{authority_name} to specify as `broader_ldpath`"
  )
  Config.predicate_uri(term_results, :broader_predicate)
end
term_results_id_ldpath() click to toggle source

Return results id_ldpath @return [String] the configured ldpath to use to extract the id from the results

# File lib/qa/authorities/linked_data/config/term_config.rb, line 69
def term_results_id_ldpath
  Config.config_value(term_results, :id_ldpath)
end
term_results_id_predicate(suppress_deprecation_warning: false) click to toggle source

Return results id_predicate @return [String] the configured predicate to use to extract the id from the results NOTE: Customizations using this method should be updated to use ‘term_results_id_predicates` which returns [Array<String>] of

id predicates.  This method remains for backward compatibility only but may cause issues if used in places expecting an Array
# File lib/qa/authorities/linked_data/config/term_config.rb, line 87
def term_results_id_predicate(suppress_deprecation_warning: false)
  unless suppress_deprecation_warning
    Qa.deprecation_warning(
      in_msg: 'Qa::Authorities::LinkedData::TermConfig',
      msg: "`term_results_id_predicate` is deprecated; use `term_results_id_ldpath` by updating linked data " \
           "term config results in authority #{authority_name} to specify as `id_ldpath`"
    )
  end
  id_predicates = term_results_id_predicates
  id_predicates.first
end
term_results_id_predicates() click to toggle source

Return results id_predicates @return [Array<String>] the configured predicate to use to extract the id from the results

# File lib/qa/authorities/linked_data/config/term_config.rb, line 75
def term_results_id_predicates
  @pred_ids ||=
    begin
      pred = Config.predicate_uri(term_results, :id_predicate)
      pred ? [pred] : id_predicates_from_ldpath
    end
end
term_results_label_ldpath() click to toggle source

Return results label_ldpath @return [String] the configured ldpath to use to extract label values from the results

# File lib/qa/authorities/linked_data/config/term_config.rb, line 101
def term_results_label_ldpath
  Config.config_value(term_results, :label_ldpath)
end
term_results_label_predicate(suppress_deprecation_warning: false) click to toggle source

Return results label_predicate @return [String] the configured predicate to use to extract label values from the results

# File lib/qa/authorities/linked_data/config/term_config.rb, line 107
def term_results_label_predicate(suppress_deprecation_warning: false)
  unless suppress_deprecation_warning
    Qa.deprecation_warning(
      in_msg: 'Qa::Authorities::LinkedData::TermConfig',
      msg: "`term_results_label_predicate` is deprecated; use `term_results_label_ldpath` by updating linked data " \
           "term config results in authority #{authority_name} to specify as `label_ldpath`"
    )
  end
  Config.predicate_uri(term_results, :label_predicate)
end
term_results_narrower_ldpath() click to toggle source

Return results narrower_ldpath @return [String] the configured ldpath to use to extract URIs for narrower terms from the results

# File lib/qa/authorities/linked_data/config/term_config.rb, line 154
def term_results_narrower_ldpath
  Config.config_value(term_results, :narrower_ldpath)
end
term_results_narrower_predicate() click to toggle source

Return results narrower_predicate @return [String] the configured predicate to use to extract URIs for narrower terms from the results

# File lib/qa/authorities/linked_data/config/term_config.rb, line 160
def term_results_narrower_predicate
  Qa.deprecation_warning(
    in_msg: 'Qa::Authorities::LinkedData::TermConfig',
    msg: "`term_results_narrower_predicate` is deprecated; use `term_results_narrower_ldpath` by updating linked data " \
         "term config results in authority #{authority_name} to specify as `narrower_ldpath`"
  )
  Config.predicate_uri(term_results, :narrower_predicate)
end
term_results_sameas_ldpath() click to toggle source

Return results sameas_ldpath @return [String] the configured ldpath to use to extract URIs for sameas terms from the results

# File lib/qa/authorities/linked_data/config/term_config.rb, line 171
def term_results_sameas_ldpath
  Config.config_value(term_results, :sameas_ldpath)
end
term_results_sameas_predicate() click to toggle source

Return results sameas_predicate @return [String] the configured predicate to use to extract URIs for sameas terms from the results

# File lib/qa/authorities/linked_data/config/term_config.rb, line 177
def term_results_sameas_predicate
  Qa.deprecation_warning(
    in_msg: 'Qa::Authorities::LinkedData::TermConfig',
    msg: "`term_results_sameas_predicate` is deprecated; use `term_results_sameas_ldpath` by updating linked data " \
         "term config results in authority #{authority_name} to specify as `sameas_ldpath`"
  )
  Config.predicate_uri(term_results, :sameas_predicate)
end
term_subauthorities() click to toggle source

Return the list of subauthorities for term fetch @return [Hash] the configurations for term url replacements

# File lib/qa/authorities/linked_data/config/term_config.rb, line 225
def term_subauthorities
  @term_subauthorities ||= {} if term_config.nil? || !(term_config.key? :subauthorities)
  @term_subauthorities ||= term_config[:subauthorities]
end
Also aliased as: subauthorities
term_subauthorities?() click to toggle source

Are there subauthorities configured for term fetch? @return [True|False] true if there are subauthorities configured term fetch; otherwise, false

# File lib/qa/authorities/linked_data/config/term_config.rb, line 205
def term_subauthorities?
  term_subauthority_count.positive?
end
Also aliased as: subauthorities?
term_subauthority?(subauth_name) click to toggle source

Is a specific subauthority configured for term fetch? @return [True|False] true if the specified subauthority is configured for term fetch; otherwise, false

# File lib/qa/authorities/linked_data/config/term_config.rb, line 212
def term_subauthority?(subauth_name)
  subauth_name = subauth_name.to_sym if subauth_name.is_a? String
  term_subauthorities.key? subauth_name
end
term_subauthority_count() click to toggle source

Return the number of subauthorities defined for term fetch @return [Integer] the number of subauthorities defined for term fetch

# File lib/qa/authorities/linked_data/config/term_config.rb, line 219
def term_subauthority_count
  term_subauthorities.size
end
url_config() click to toggle source

Return term url template defined in the configuration for this authority. @return [Qa::IriTemplate::UrlConfig] the configured term url template

# File lib/qa/authorities/linked_data/config/term_config.rb, line 30
def url_config
  @url_config ||= Qa::IriTemplate::UrlConfig.new(term_config[:url]) if supports_term?
end

Private Instance Methods

id_predicates_from_ldpath() click to toggle source

Parse ldpath into an array of predicates.

Gets ldpath (e.g. ‘loc:lccn | madsrdf:code

xsd:string’) using config accessor for results id ldpath.

Multiple paths are delineated by | which is used to split the ldpath into an array of paths. @return [Array<String>] the predicate for each path in the ldpath

# File lib/qa/authorities/linked_data/config/term_config.rb, line 246
def id_predicates_from_ldpath
  id_ldpath = term_results_id_ldpath
  return [] if id_ldpath.blank?
  id_ldpath.split('|').map(&:strip).map do |path|
    predicate = parse_predicate_from_single_path(path)
    predicate.present? ? RDF::URI.new(predicate) : nil
  end.compact
end
parse_predicate_from_single_path(path) click to toggle source

Parse a single path (e.g. ‘loc:lccn’ where ‘loc’ is the ontology prefix and ‘lccn’ is the property name) Gets prefixes (e.g. { “loc”: “id.loc.gov/vocabulary/identifiers/”, “madsrdf”: “www.loc.gov/mads/rdf/v1#” }) from authority config @return [String] the predicate constructed by combining the expanded prefix with the property name

# File lib/qa/authorities/linked_data/config/term_config.rb, line 258
def parse_predicate_from_single_path(path)
  tokens = path.split(':')
  return nil if tokens.size < 2
  prefix = tokens.first.to_sym
  prefix_path = prefixes[prefix]
  prefix_path = Qa::LinkedData::LdpathService.predefined_prefixes[prefix] if prefix_path.blank?
  raise Qa::InvalidConfiguration, "Prefix '#{prefix}' is not defined in term configuration for authority #{authority_name}" if prefix_path.blank?
  "#{prefix_path}#{tokens.second.strip}"
end
summary_with_subauthority(auth_name, subauth_name, language) click to toggle source
# File lib/qa/authorities/linked_data/config/term_config.rb, line 280
def summary_with_subauthority(auth_name, subauth_name, language)
  {
    "label" => "#{auth_name} term #{subauth_name} (QA)",
    "uri" => "urn:qa:term:#{auth_name}:#{subauth_name}",
    "authority" => auth_name,
    "subauthority" => subauth_name,
    "action" => "term",
    "language" => language
  }
end
summary_without_subauthority(auth_name, language) click to toggle source
# File lib/qa/authorities/linked_data/config/term_config.rb, line 268
def summary_without_subauthority(auth_name, language)
  [
    {
      "label" => "#{auth_name} term (QA)",
      "uri" => "urn:qa:term:#{auth_name}",
      "authority" => auth_name,
      "action" => "term",
      "language" => language
    }
  ]
end