Class: SHACL::Algebra::XoneConstraintComponent

Inherits:
ConstraintComponent show all
Defined in:
lib/shacl/algebra/xone.rb

Constant Summary collapse

NAME =
:xone

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 ConstraintComponent

from_json, ncname

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: nil, depth: 0, **options) ⇒ Array<SHACL::ValidationResult>

Specifies the condition that each value node conforms to exactly one of the provided shapes.

Examples:

ex:XoneConstraintExampleShape
	a sh:NodeShape ;
	sh:targetClass ex:Person ;
	sh:xone (
		[
			sh:property [
				sh:path ex:fullName ;
				sh:minCount 1 ;
			]
		]
		[
			sh:property [
				sh:path ex:firstName ;
				sh:minCount 1 ;
			] ;
			sh:property [
				sh:path ex:lastName ;
				sh:minCount 1 ;
			]
		]
	) .

Parameters:

  • node (RDF::Term)

    focus node

  • path (RDF::URI, SPARQL::Algebra::Expression) (defaults to: nil)

    (nil) the property

  • options (Hash{Symbol => Object})

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/shacl/algebra/xone.rb', line 36

def conforms(node, path: nil, depth: 0, **options)
  log_debug(NAME, depth: depth) {SXP::Generator.string({node: node}.to_sxp_bin)}
  num_conform = operands.inject(0) do |memo, op|
    results = op.conforms(node, depth: depth + 1, **options)
    memo += (results.flatten.all?(&:conform?) ? 1 : 0)
  end
  case num_conform
  when 0
    not_satisfied(focus: node, path: path,
      value: node,
      message: "node does not conform to any shape",
      resultSeverity: options.fetch(:severity),
      component: RDF::Vocab::SHACL.XoneConstraintComponent,
      depth: depth, **options)
  when 1
    satisfy(focus: node, path: path,
      value: node,
      message: "node conforms to a single shape",
      component: RDF::Vocab::SHACL.XoneConstraintComponent,
      depth: depth, **options)
  else
    not_satisfied(focus: node, path: path,
      value: node,
      message: "node conforms to #{num_conform} shapes",
      resultSeverity: options.fetch(:severity),
      component: RDF::Vocab::SHACL.XoneConstraintComponent,
      depth: depth, **options)
  end
end