class Qa::Authorities::LinkedData::TermConfig
Attributes
Public Class Methods
@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
# 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
@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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 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