Class: SHACL::Algebra::QualifiedValueConstraintComponent

Inherits:
Operator
  • Object
show all
Defined in:
lib/shacl/algebra/qualified_value.rb

Constant Summary collapse

NAME =
:qualifiedValueShape

Constants inherited from Operator

Operator::BUILTIN_KEYS, Operator::PARAMETERS

Instance Attribute Summary

Attributes inherited from Operator

#graph, #options, #shapes_graph

Instance Method Summary collapse

Methods inherited from Operator

add_component, apply_op, #comment, component_params, #deactivated?, from_expanded_value, from_json, #id, iri, #iri, #label, #not_satisfied, params, parse_path, #satisfy, to_rdf, #to_sxp_bin, #type

Instance Method Details

#conforms(node, path:, value_nodes:, depth: 0, **options) ⇒ Array<SHACL::ValidationResult>

Specifies the condition that a specified number of value nodes conforms to the given shape. Each sh:qualifiedValueShape can have: one value for sh:qualifiedMinCount, one value for sh:qualifiedMaxCount or, one value for each, at the same subject.

Parameters:

  • node (RDF::Term)

    focus node

  • path (RDF::URI, SPARQL::Algebra::Expression)

    the property path from the focus node to the value nodes.

  • value_nodes (Array<RDF::Term>)
  • options (Hash{Symbol => Object})

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/shacl/algebra/qualified_value.rb', line 14

def conforms(node, path:, value_nodes:, depth: 0, **options)
  log_debug(NAME, depth: depth) {SXP::Generator.string({node: node, value_nodes: value_nodes}.to_sxp_bin)}
  # Separate operands into operators and parameters
  params, ops = operands.partition {|o| o.is_a?(Array) && o.first.is_a?(Symbol)}
  params = params.inject({}) {|memo, a| memo.merge(a.first => a.last)}

  max_count = params[:qualifiedMinCount]
  min_count = params[:qualifiedMinCount]
  # FIXME: figure this out
  disjoint = !!params[:qualifiedValueShapesDisjoint]

  ops.map do |op|
    results = value_nodes.map do |n|
      op.conforms(n, depth: depth + 1, **options)
    end.flatten.compact

    count = results.select(&:conform?).length
    log_debug(NAME, depth: depth) {"#{count}/#{results} conforming shapes"}
    if min_count && count < min_count.to_i
      not_satisfied(focus: node, path: path,
        message: "only #{count} conforming values, requires at least #{min_count}",
        resultSeverity: options.fetch(:severity),
        component: RDF::Vocab::SHACL.QualifiedMinCountConstraintComponent,
        depth: depth, **options)
    elsif max_count && count > max_count.to_i
      not_satisfied(focus: node, path: path,
        message: "#{count} conforming values, requires at most #{max_count}",
        resultSeverity: options.fetch(:severity),
        component: RDF::Vocab::SHACL.QualifiedMaxCountConstraintComponent,
        depth: depth, **options)
    else
      satisfy(focus: node, path: path,
        message: "#{min_count.to_i} <= #{count} <= #{max_count || 'inf'} values conform",
        component: RDF::Vocab::SHACL.QualifiedMinCountConstraintComponent,
        depth: depth, **options)
    end
  end
end