Class: SHACL::Algebra::ConstraintComponent

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

Overview

Constraint Components define basic constraint behaivor through mandatory and optional parameters. Constraints are accessed through their parameters.

Constant Summary

Constants inherited from Operator

Operator::BUILTIN_KEYS, Operator::PARAMETERS

Instance Attribute Summary

Attributes inherited from Operator

#graph, #options, #shapes_graph

Class Method Summary collapse

Methods inherited from Operator

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

Class Method Details

.from_json(operator, **options) ⇒ Operator

Creates an operator instance from a parsed SHACL representation.

Special case for SPARQL ConstraintComponents.

Parameters:

  • operator (Hash)
  • options (Hash)

    ({})

Options Hash (**options):

  • :prefixes (Hash{String => RDF::URI})

Returns:

Raises:



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
# File 'lib/shacl/algebra/constraint_component.rb', line 20

def from_json(operator, **options)
  operands = []

  # Component is known by its subject IRI
  id = operator.fetch('id')

  # Component class (for instantiation) is based on the _local name_ of the component IRI
  class_name = ncname(id)

  parameters = operator.fetch('parameter', []).inject({}) do |memo, param|
    # Symbolize keys
    param = param.inject({}) {|memo, (k,v)| memo.merge(k.to_sym => v)}

    plc = ncname(param[:path])

    # Add class and local name
    param = param.merge(class: class_name, local_name: plc)
    memo.merge(param[:path] => param)
  end

  # Add parameters to operator lookup
  add_component(class_name, parameters)

  # Add parameter identifiers to operands
  operands << [:parameters, parameters.keys]

  # FIXME: labelTemplate

  validator = %w(validator nodeValidator propertyValidator).inject(nil) do |memo, p|
    memo || (SPARQLConstraintComponent.from_json(operator[p]) if operator.key?(p))
  end
  raise SHACL::Error, "Constraint Component has no validator" unless validator

  operands << [:validator, validator]

  new(*operands, **options)
end

.ncname(uri) ⇒ Symbol

Extract the NCName tail of an IRI as a symbol.

Parameters:

  • uri (RDF::URI)

Returns:

  • (Symbol)


62
63
64
# File 'lib/shacl/algebra/constraint_component.rb', line 62

def ncname(uri)
  uri.to_s.match(/(\w+)$/).to_s.to_sym
end