Class: Qa::Authorities::LinkedData::TermConfig
- Inherits:
-
Object
- Object
- Qa::Authorities::LinkedData::TermConfig
- Defined in:
- lib/qa/authorities/linked_data/config/term_config.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ TermConfig
constructor
A new instance of TermConfig.
-
#supports_term? ⇒ True|False
Does this authority configuration have term defined?.
-
#term_id_expects_id? ⇒ True|False
Is the term_id substitution expected to be an ID?.
-
#term_id_expects_uri? ⇒ True|False
Is the term_id substitution expected to be a URI?.
-
#term_language ⇒ Symbol
Return the preferred language for literal value selection for term fetch.
-
#term_qa_replacement_patterns ⇒ Hash
Return parameters that are required for QA api.
-
#term_replacement_count ⇒ Integer
Return the number of possible replacement values to make in the term URL.
-
#term_replacements ⇒ Hash
Return the replacement configurations.
-
#term_replacements? ⇒ True|False
Are there replacement parameters configured for term fetch?.
-
#term_results ⇒ Hash
Return results predicates.
-
#term_results_altlabel_predicate ⇒ String
Return results altlabel_predicate.
-
#term_results_broader_predicate ⇒ String
Return results broader_predicate.
-
#term_results_id_predicate ⇒ String
Return results id_predicate.
-
#term_results_label_predicate ⇒ String
Return results label_predicate.
-
#term_results_narrower_predicate ⇒ String
Return results narrower_predicate.
-
#term_results_sameas_predicate ⇒ String
Return results sameas_predicate.
-
#term_subauthorities ⇒ Hash
Return the list of subauthorities for term fetch.
-
#term_subauthorities? ⇒ True|False
Are there subauthorities configured for term fetch?.
-
#term_subauthority?(subauth_name) ⇒ True|False
Is a specific subauthority configured for term fetch?.
-
#term_subauthority_count ⇒ Integer
Return the number of subauthorities defined for term fetch.
-
#term_subauthority_replacement_pattern ⇒ Hash
Return the replacement configurations.
-
#term_url ⇒ Hash
Return term url encoding defined in the configuration for this authority.
-
#term_url_mappings ⇒ Hash
Return term url parameter mapping defined in the configuration for this authority.
-
#term_url_template ⇒ String
Return term url template defined in the configuration for this authority.
-
#term_url_with_replacements(id, sub_auth = nil, replacements = {}) ⇒ String
Build a linked data authority term url.
Constructor Details
#initialize(config) ⇒ TermConfig
Returns a new instance of TermConfig.
9 10 11 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 9 def initialize(config) @term_config = config end |
Instance Method Details
#supports_term? ⇒ True|False
Does this authority configuration have term defined?
18 19 20 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 18 def supports_term? term_config.present? end |
#term_id_expects_id? ⇒ True|False
Is the term_id substitution expected to be an ID?
52 53 54 55 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 52 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? ⇒ True|False
Is the term_id substitution expected to be a URI?
45 46 47 48 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 45 def term_id_expects_uri? return false if term_config.nil? || !(term_config.key? :term_id) term_config[:term_id] == "URI" end |
#term_language ⇒ Symbol
Return the preferred language for literal value selection for term fetch. Only applies if the authority provides language encoded literals.
59 60 61 62 63 64 65 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 59 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 |
#term_qa_replacement_patterns ⇒ Hash
Return parameters that are required for QA api
111 112 113 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 111 def term_qa_replacement_patterns Config.config_value(term_config, :qa_replacement_patterns) end |
#term_replacement_count ⇒ Integer
Return the number of possible replacement values to make in the term URL
123 124 125 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 123 def term_replacement_count term_replacements.size end |
#term_replacements ⇒ Hash
Return the replacement configurations
129 130 131 132 133 134 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 129 def term_replacements return @term_replacements unless @term_replacements.nil? @term_replacements = {} @term_replacements = term_url_mappings.select { |k, _v| !term_qa_replacement_patterns.include?(k) } unless term_config.nil? || term_url_mappings.nil? @term_replacements end |
#term_replacements? ⇒ True|False
Are there replacement parameters configured for term fetch?
117 118 119 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 117 def term_replacements? term_replacement_count.positive? end |
#term_results ⇒ Hash
Return results predicates
69 70 71 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 69 def term_results Config.config_value(term_config, :results) end |
#term_results_altlabel_predicate ⇒ String
Return results altlabel_predicate
87 88 89 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 87 def term_results_altlabel_predicate Config.predicate_uri(term_results, :altlabel_predicate) end |
#term_results_broader_predicate ⇒ String
Return results broader_predicate
93 94 95 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 93 def term_results_broader_predicate Config.predicate_uri(term_results, :broader_predicate) end |
#term_results_id_predicate ⇒ String
Return results id_predicate
75 76 77 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 75 def term_results_id_predicate Config.predicate_uri(term_results, :id_predicate) end |
#term_results_label_predicate ⇒ String
Return results label_predicate
81 82 83 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 81 def term_results_label_predicate Config.predicate_uri(term_results, :label_predicate) end |
#term_results_narrower_predicate ⇒ String
Return results narrower_predicate
99 100 101 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 99 def term_results_narrower_predicate Config.predicate_uri(term_results, :narrower_predicate) end |
#term_results_sameas_predicate ⇒ String
Return results sameas_predicate
105 106 107 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 105 def term_results_sameas_predicate Config.predicate_uri(term_results, :sameas_predicate) end |
#term_subauthorities ⇒ Hash
Return the list of subauthorities for term fetch
157 158 159 160 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 157 def ||= {} if term_config.nil? || !(term_config.key? :subauthorities) ||= term_config[:subauthorities] end |
#term_subauthorities? ⇒ True|False
Are there subauthorities configured for term fetch?
138 139 140 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 138 def .positive? end |
#term_subauthority?(subauth_name) ⇒ True|False
Is a specific subauthority configured for term fetch?
144 145 146 147 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 144 def (subauth_name) subauth_name = subauth_name.to_sym if subauth_name.is_a? String .key? subauth_name end |
#term_subauthority_count ⇒ Integer
Return the number of subauthorities defined for term fetch
151 152 153 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 151 def .size end |
#term_subauthority_replacement_pattern ⇒ Hash
Return the replacement configurations
164 165 166 167 168 169 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 164 def return {} unless ||= {} if term_config.nil? || ! pattern = term_qa_replacement_patterns[:subauth] ||= { pattern: pattern, default: term_url_mappings[pattern.to_sym][:default] } end |
#term_url ⇒ Hash
Return term url encoding defined in the configuration for this authority.
24 25 26 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 24 def term_url Config.config_value(term_config, :url) end |
#term_url_mappings ⇒ Hash
Return term url parameter mapping defined in the configuration for this authority.
36 37 38 39 40 41 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 36 def term_url_mappings return @term_url_mappings unless @term_url_mappings.nil? mappings = Config.config_value(term_url, :mapping) return {} if mappings.nil? Hash[*mappings.collect { |m| [m[:variable].to_sym, m] }.flatten] end |
#term_url_template ⇒ String
Return term url template defined in the configuration for this authority.
30 31 32 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 30 def term_url_template Config.config_value(term_url, :template) end |
#term_url_with_replacements(id, sub_auth = nil, replacements = {}) ⇒ String
Build a linked data authority term url
176 177 178 179 180 181 182 183 |
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 176 def term_url_with_replacements(id, sub_auth = nil, replacements = {}) return nil unless supports_term? sub_auth = sub_auth.to_sym if sub_auth.is_a? String url = Config.replace_pattern(term_url_template, term_qa_replacement_patterns[:term_id], id) url = Config.(url, , , sub_auth) if url = Config.apply_replacements(url, term_replacements, replacements) if term_replacements? url end |