Class: SHACL::Algebra::PatternConstraintComponent

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

Constant Summary collapse

NAME =
:pattern

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 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

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

Specifies a regular expression that each value node matches to satisfy the condition.

Examples:

ex:PatternExampleShape
  a sh:NodeShape ;
  sh:targetNode ex:Bob, ex:Alice, ex:Carol ;
  sh:property [
    sh:path ex:bCode ;
    sh:pattern "^B" ;    # starts with 'B'
    sh:flags "i" ;       # Ignore case
  ] .

Parameters:

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shacl-e638b9acc6d8/lib/shacl/algebra/pattern.rb', line 23

def conforms(node, path: nil, depth: 0, **options)
  log_debug(NAME, depth: depth) {SXP::Generator.string({node: node}.to_sxp_bin)}
  pattern = Array(operands.first).first
  flags = operands.last.last if operands.last.is_a?(Array) && operands.last.first == :flags
  flags = flags.to_s
  regex_opts = 0
  regex_opts |= Regexp::MULTILINE  if flags.include?(?m)
  regex_opts |= Regexp::IGNORECASE if flags.include?(?i)
  regex_opts |= Regexp::EXTENDED   if flags.include?(?x)
  pat = Regexp.new(pattern, regex_opts)

  compares = !node.node? && pat.match?(node.to_s)
  satisfy(focus: node, path: path,
    value: node,
    message: "is#{' not' unless compares} a match #{pat.inspect}",
    resultSeverity: (options.fetch(:severity) unless compares),
    component: RDF::Vocab::SHACL.PatternConstraintComponent,
    **options)
end