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 search 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



187
188
189
190
191
192
193
194
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 187

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



155
156
157
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 155

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



150
151
152
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 150

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



144
145
146
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 144

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



96
97
98
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 96

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



102
103
104
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 102

def term_results_altlabel_predicate
  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



108
109
110
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 108

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



114
115
116
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 114

def term_results_broader_predicate
  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_predicateString

Return results id_predicate

Returns:

  • (String)

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



75
76
77
78
79
80
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 75

def term_results_id_predicate
  return @pred_id unless @pred_id.blank?
  @pred_id = Config.predicate_uri(term_results, :id_predicate)
  return @pred_id unless @pred_id.blank?
  @pred_id = pred_id_from_ldpath
end

#term_results_label_ldpathString

Return results label_ldpath

Returns:

  • (String)

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



84
85
86
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 84

def term_results_label_ldpath
  Config.config_value(term_results, :label_ldpath)
end

#term_results_label_predicateString

Return results label_predicate

Returns:

  • (String)

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



90
91
92
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 90

def term_results_label_predicate
  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



120
121
122
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 120

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



126
127
128
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 126

def term_results_narrower_predicate
  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



132
133
134
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 132

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



138
139
140
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 138

def term_results_sameas_predicate
  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



181
182
183
184
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 181

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



161
162
163
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 161

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



168
169
170
171
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 168

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



175
176
177
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 175

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