Class: SHACL::Algebra::NodeShape

Inherits:
Shape show all
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/algebra/node_shape.rb

Constant Summary collapse

NAME =
:NodeShape

Constants inherited from Shape

Shape::NODE_KIND_COMPARE

Constants inherited from Operator

Operator::BUILTIN_KEYS, Operator::PARAMETERS

Constants included from RDF::Util::Logger

RDF::Util::Logger::IOWrapper

Constants inherited from SPARQL::Algebra::Operator

SPARQL::Algebra::Operator::ARITY, SPARQL::Algebra::Operator::IsURI, SPARQL::Algebra::Operator::URI

Constants included from SPARQL::Algebra::Expression

SPARQL::Algebra::Expression::PATTERN_PARENTS

Instance Attribute Summary

Attributes inherited from Operator

#graph, #options, #shapes_graph

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods inherited from Shape

#builtin_class, #builtin_datatype, #builtin_disjoint, #builtin_equals, #builtin_hasValue, #builtin_in, #builtin_languageIn, #builtin_maxExclusive, #builtin_maxInclusive, #builtin_maxLength, #builtin_minExclusive, #builtin_minInclusive, #builtin_minLength, #builtin_nodeKind, #compare, #targetNodes

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

Methods included from JSON::LD::Utils

#add_value, #as_array, #as_resource, #blank_node?, #compare_values, #graph?, #has_value?, #index?, #list?, #node?, #node_or_ref?, #node_reference?, #property?, #simple_graph?, #value?

Methods included from RDF::Util::Logger

#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, base_uri, #base_uri, base_uri=, #bind, #boolean, #constant?, #deep_dup, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #formulae, #initialize, #inspect, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, prefixes, #prefixes, prefixes=, #rewrite, #to_binary, #to_sparql, to_sparql, #to_sxp, #to_sxp_bin, #validate!, #variable?, #variables, #vars

Methods included from SPARQL::Algebra::Expression

cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Constructor Details

This class inherits a constructor from SPARQL::Algebra::Operator

Instance Method Details

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

Validates the specified node within graph, a list of ValidationResult.

A node conforms if it is not deactivated and all of its operands conform.

Parameters:

Returns:



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/algebra/node_shape.rb', line 16

def conforms(node, depth: 0, **options)
  return [] if deactivated?
  options = id ? options.merge(shape: id) : options
  options[:severity] = @options[:severity] if @options[:severity]
  options[:severity] ||= RDF::Vocab::SHACL.Violation
  log_debug(NAME, depth: depth) {SXP::Generator.string({id: id, node: node}.to_sxp_bin)}

  # Evaluate against builtins
  builtin_results = @options.map do |k, v|
    self.send("builtin_#{k}".to_sym, v, node, nil, [node],
              depth: depth + 1,
              **options) if self.respond_to?("builtin_#{k}".to_sym)
  end.flatten.compact

  # Handle closed shapes
  # FIXME: this only considers URI paths, not property paths
  closed_results = []
  if @options[:closed]
    shape_paths = operands.select {|o| o.is_a?(PropertyShape)}.map(&:path)
    shape_properties = shape_paths.select {|p| p.is_a?(RDF::URI)}
    shape_properties += Array(@options[:ignoredProperties])

    closed_results = graph.query({subject: node}).map do |statement|
      next if shape_properties.include?(statement.predicate)
      not_satisfied(focus: node,
        value: statement.object,
        path: statement.predicate,
        message: "closed node has extra property",
        resultSeverity: options[:severity],
        component: RDF::Vocab::SHACL.ClosedConstraintComponent,
        **options)
    end.flatten.compact
  elsif @options[:ignoredProperties]
    raise SHACL::Error, "shape has ignoredProperties without being closed"
  end

  # Evaluate against operands
  op_results = operands.map do |op|
    res = op.conforms(node,
      focus: options.fetch(:focusNode, node),
      depth: depth + 1,
      **options)
    if op.is_a?(NodeShape) && !res.all?(&:conform?)
      # Special case for embedded NodeShape
      not_satisfied(focus: node,
        value: node,
        message: "node does not conform to #{op.id}",
        resultSeverity: options[:severity],
        component: RDF::Vocab::SHACL.NodeConstraintComponent,
        **options)
    else
      res
    end
  end.flatten.compact

  builtin_results + closed_results + op_results
end