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

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of TermConfig.

Parameters:

  • config (Hash)

    the term portion of the config



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

def initialize(config, prefixes = {})
  @term_config = config
  @prefixes = prefixes
end

Instance Method Details

#supports_term?True|False

Does this authority configuration have term defined?

Returns:

  • (True|False)

    true if term fetching is configured; otherwise, false



19
20
21
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 19

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



38
39
40
41
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 38

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



31
32
33
34
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 31

def term_id_expects_uri?
  return false if term_config.nil? || !(term_config.key? :term_id)
  term_config[:term_id] == "URI"
end

#term_languageSymbol

Return the preferred language for literal value selection for term fetch. Only applies if the authority provides language encoded literals.

Returns:

  • (Symbol)

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



45
46
47
48
49
50
51
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 45

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



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

def term_qa_replacement_patterns
  Config.config_value(term_config, :qa_replacement_patterns)
end

#term_resultsHash

Return results predicates

Returns:

  • (Hash)

    all the configured predicates to pull out of the results



55
56
57
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 55

def term_results
  Config.config_value(term_config, :results)
end

#term_results_altlabel_predicateString

Return results altlabel_predicate

Returns:

  • (String)

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



73
74
75
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 73

def term_results_altlabel_predicate
  Config.predicate_uri(term_results, :altlabel_predicate)
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



79
80
81
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 79

def term_results_broader_predicate
  Config.predicate_uri(term_results, :broader_predicate)
end

#term_results_id_predicateString

Return results id_predicate

Returns:

  • (String)

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



61
62
63
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 61

def term_results_id_predicate
  Config.predicate_uri(term_results, :id_predicate)
end

#term_results_label_predicateString

Return results label_predicate

Returns:

  • (String)

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



67
68
69
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 67

def term_results_label_predicate
  Config.predicate_uri(term_results, :label_predicate)
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



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

def term_results_narrower_predicate
  Config.predicate_uri(term_results, :narrower_predicate)
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



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

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



123
124
125
126
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 123

def term_subauthorities
  @term_subauthorities ||= {} if term_config.nil? || !(term_config.key? :subauthorities)
  @term_subauthorities ||= term_config[:subauthorities]
end

#term_subauthorities?True|False

Are there subauthorities configured for term fetch?

Returns:

  • (True|False)

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



104
105
106
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 104

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



110
111
112
113
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 110

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



117
118
119
# File 'lib/qa/authorities/linked_data/config/term_config.rb', line 117

def term_subauthority_count
  term_subauthorities.size
end

#url_configQa::IriTemplate::UrlConfig

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

Returns:



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

def url_config
  @url_config ||= Qa::IriTemplate::UrlConfig.new(term_config[:url]) if supports_term?
end