Class: Qa::Authorities::LinkedData::TermConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/qa/authorities/linked_data/config/term_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, prefixes = {}, full_config = nil) ⇒ TermConfig

Returns a new instance of TermConfig.

Parameters:

  • config (Hash)

    the term portion of the config

  • prefixes (Hash<Symbol><String>) (defaults to: {})

    URL map of prefixes to use with ldpaths

  • full_config (Qa::Authorities::LinkedData::Config) (defaults to: nil)

    the full linked data configuration that the passed in term config is part of



16
17
18
19
20
# 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

Instance Attribute Details

#prefixesObject (readonly)

Returns the value of attribute prefixes.



8
9
10
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 8

def prefixes
  @prefixes
end

Instance Method Details

#infoObject



231
232
233
234
235
236
237
238
# 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

#supports_language_parameter?Boolean

Returns true if supports language parameter; otherwise, false.

Returns:

  • (Boolean)

    true if supports language parameter; otherwise, false



199
200
201
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 199

def supports_language_parameter?
  qa_replacement_patterns.key? :lang
end

#supports_subauthorities?Boolean

Returns true if supports language parameter; otherwise, false.

Returns:

  • (Boolean)

    true if supports language parameter; otherwise, false



194
195
196
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 194

def supports_subauthorities?
  qa_replacement_patterns.key?(:subauth) && subauthorities?
end

#supports_term?True|False

Does this authority configuration have term defined?

Returns:

  • (True|False)

    true if term fetching is configured; otherwise, false



24
25
26
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 24

def supports_term?
  term_config.present?
end

#term_id_expects_id?True|False

Is the term_id substitution expected to be an ID?

Returns:

  • (True|False)

    true if the id substitution is expected to be an ID in the term url; otherwise, false



43
44
45
46
# 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?True|False

Is the term_id substitution expected to be a URI?

Returns:

  • (True|False)

    true if the id substitution is expected to be a URI in the term url; otherwise, false



36
37
38
39
# 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_languageSymbol Also known as: language

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.

Returns:

  • (Symbol)

    the configured language for term fetch (default - :en)



52
53
54
55
56
57
58
# 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

#term_qa_replacement_patternsHash Also known as: qa_replacement_patterns

Return parameters that are required for QA api

Returns:

  • (Hash)

    the configured term url parameter mappings



188
189
190
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 188

def term_qa_replacement_patterns
  term_config.fetch(:qa_replacement_patterns, {})
end

#term_resultsHash

Return results ldpaths or predicates

Returns:

  • (Hash)

    all the configured ldpaths or predicates to pull out of the results



63
64
65
# 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_ldpathString

Return results altlabel_ldpath

Returns:

  • (String)

    the configured ldpath to use to extract altlabel values from the results



120
121
122
# 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_predicateString

Return results altlabel_predicate

Returns:

  • (String)

    the configured predicate to use to extract altlabel values from the results



126
127
128
129
130
131
132
133
# 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_ldpathString

Return results broader_ldpath

Returns:

  • (String)

    the configured ldpath to use to extract URIs for broader terms from the results



137
138
139
# 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_predicateString

Return results broader_predicate

Returns:

  • (String)

    the configured predicate to use to extract URIs for broader terms from the results



143
144
145
146
147
148
149
150
# 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_ldpathString

Return results id_ldpath

Returns:

  • (String)

    the configured ldpath to use to extract the id from the results



69
70
71
# 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) ⇒ String

Return results id_predicate 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

Returns:

  • (String)

    the configured predicate to use to extract the id from the results



87
88
89
90
91
92
93
94
95
96
97
# 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_predicatesArray<String>

Return results id_predicates

Returns:

  • (Array<String>)

    the configured predicate to use to extract the id from the results



75
76
77
78
79
80
81
# 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_ldpathString

Return results label_ldpath

Returns:

  • (String)

    the configured ldpath to use to extract label values from the results



101
102
103
# 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) ⇒ String

Return results label_predicate

Returns:

  • (String)

    the configured predicate to use to extract label values from the results



107
108
109
110
111
112
113
114
115
116
# 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_ldpathString

Return results narrower_ldpath

Returns:

  • (String)

    the configured ldpath to use to extract URIs for narrower terms from the results



154
155
156
# 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_predicateString

Return results narrower_predicate

Returns:

  • (String)

    the configured predicate to use to extract URIs for narrower terms from the results



160
161
162
163
164
165
166
167
# 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_ldpathString

Return results sameas_ldpath

Returns:

  • (String)

    the configured ldpath to use to extract URIs for sameas terms from the results



171
172
173
# 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_predicateString

Return results sameas_predicate

Returns:

  • (String)

    the configured predicate to use to extract URIs for sameas terms from the results



177
178
179
180
181
182
183
184
# 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_subauthoritiesHash Also known as: subauthorities

Return the list of subauthorities for term fetch

Returns:

  • (Hash)

    the configurations for term url replacements



225
226
227
228
# 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

#term_subauthorities?True|False Also known as: subauthorities?

Are there subauthorities configured for term fetch?

Returns:

  • (True|False)

    true if there are subauthorities configured term fetch; otherwise, false



205
206
207
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 205

def term_subauthorities?
  term_subauthority_count.positive?
end

#term_subauthority?(subauth_name) ⇒ True|False

Is a specific subauthority configured for term fetch?

Returns:

  • (True|False)

    true if the specified subauthority is configured for term fetch; otherwise, false



212
213
214
215
# 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_countInteger

Return the number of subauthorities defined for term fetch

Returns:

  • (Integer)

    the number of subauthorities defined for term fetch



219
220
221
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 219

def term_subauthority_count
  term_subauthorities.size
end

#url_configQa::IriTemplate::UrlConfig

Return term url template defined in the configuration for this authority.

Returns:



30
31
32
# 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