Class: Qa::LinkedData::LdpathService
- Inherits:
-
Object
- Object
- Qa::LinkedData::LdpathService
- Defined in:
- app/services/qa/linked_data/ldpath_service.rb
Constant Summary collapse
- VALUE_ON_ERROR =
[].freeze
Class Method Summary collapse
-
.ldpath_evaluate(program:, graph:, subject_uri:, limit_to_context: Qa.config.limit_ldpath_to_context?) ⇒ Array<String>
Evaluate an ldpath for a specific subject uri in the context of a graph and return the extracted values.
-
.ldpath_program(ldpath:, prefixes: {}) ⇒ Ldpath::Program
Create the ldpath program for a given ldpath.
Class Method Details
.ldpath_evaluate(program:, graph:, subject_uri:, limit_to_context: Qa.config.limit_ldpath_to_context?) ⇒ Array<String>
Evaluate an ldpath for a specific subject uri in the context of a graph and return the extracted values.
33 34 35 36 37 38 39 40 |
# File 'app/services/qa/linked_data/ldpath_service.rb', line 33 def self.ldpath_evaluate(program:, graph:, subject_uri:, limit_to_context: Qa.config.limit_ldpath_to_context?) return VALUE_ON_ERROR if program.blank? output = program.evaluate(subject_uri, context: graph, limit_to_context: limit_to_context) output.present? ? output['property'].uniq : nil rescue => e Rails.logger.warn("WARNING: #{I18n.t('qa.linked_data.ldpath.evaluate_logger_error')} (cause: #{e.}") raise StandardError, I18n.t("qa.linked_data.ldpath.evaluate_error") + "... cause: #{e.}" end |
.ldpath_program(ldpath:, prefixes: {}) ⇒ Ldpath::Program
Create the ldpath program for a given ldpath.
16 17 18 19 20 21 22 23 24 |
# File 'app/services/qa/linked_data/ldpath_service.rb', line 16 def self.ldpath_program(ldpath:, prefixes: {}) program_code = "" prefixes.each { |key, url| program_code << "@prefix #{key} : <#{url}> \;\n" } program_code << "property = #{ldpath} \;" Ldpath::Program.parse program_code rescue => e Rails.logger.warn("WARNING: #{I18n.t('qa.linked_data.ldpath.parse_logger_error')}... cause: #{e.}\n ldpath_program=\n#{program_code}") raise StandardError, I18n.t("qa.linked_data.ldpath.parse_error") + "... cause: #{e.}" end |