diff --git a/shacl12-core/index.html b/shacl12-core/index.html index 0e34e5e5..00ef26a4 100644 --- a/shacl12-core/index.html +++ b/shacl12-core/index.html @@ -2616,7 +2616,7 @@

Node Expressions

During evaluation, the engine can access triples related to expr in the shapes graph.
  • focusGraph is a graph, called the focus graph. This is the default query graph for the evaluation of the node expression.
  • focusNode is a node, called the input focus node. This variable may have no value.
  • -
  • scope is a map from variable names to individual nodes. +
  • scope is a map from (key) nodes to individual (value) nodes. The empty map is written as {}.
  • diff --git a/shacl12-node-expr/index.html b/shacl12-node-expr/index.html index c3c892e1..d856271b 100644 --- a/shacl12-node-expr/index.html +++ b/shacl12-node-expr/index.html @@ -2189,6 +2189,265 @@

    InstancesOf Expressions

    +
    +

    Custom Node Expressions

    +

    + SHACL includes vocabulary terms that can be used to define new node expression functions + by wrapping other (parameterized) node expressions. + This makes it possible to extend the library of available SHACL node expressions without having to + hard-code changes to an engine. +

    + +
    +

    Custom Named Parameter Functions

    +

    + + A custom named parameter function is an IRI in a shapes graph + that is a SHACL instance of sh:NamedParameterExpressionFunction and + a SHACL subclass of sh:NamedParameterExpression. + It has a single value for sh:bodyExpression that is a well-formed + node expression. +

    + A custom named parameter function declares one or more parameters as values + of sh:parameter, where each such parameter has exactly one value for + sh:path and that value is an IRI. + At least one of the parameters has sh:keyParameter true, declaring the key parameters + for the function. + The key parameters of all node expression functions + (including the built-in ones from the shnex: namespace) must be disjoint. +

    + Custom named parameter functions can reference the declared parameters using an + arg expression such as [ shnex:arg ex:param ], where the value of shnex:arg + matches the IRI of the parameter's sh:path. +
    +

    +

    + + A custom named parameter expression is a node expression + represented by a blank node that has exactly one value for at least one of + the key parameters. + +

    +
    +
    EVALUATION OF CUSTOM NAMED PARAMETER EXPRESSIONS
    +

    + Let expr be a custom named parameter expression with the + custom named parameter function f. + Let body be the value of sh:bodyExpression at f + in the shapes graph. +

    + Let argScope be a map of (parameter) nodes as keys and (argument) nodes + as values, so that each parameter of f has the value of the parameter's + sh:path from expr. + For example, if f declares just one parameter with sh:path ex:param + and expr is [ ex:param 42 ] then argScope is { ex:param : 42 }. +

    + The output nodes of expr are computed using + evalExpr(expr, focusGraph, focusNode, scope) -> evalExpr(body, focusGraph, focusNode, argScope) +

    +
    +

    The remainder of this section is informative.

    +

    + The following example defines a new node expression function ex:AverageExpression + that takes another node expression as input using the key parameter ex:average + and then calculates the sum of all input nodes and divides it by the number of nodes, + returning the average value of these nodes. +

    + +

    + This new node expression function can the be used as follows: +

    + +
    + +
    +

    Custom List Parameter Functions

    +

    + + A custom list parameter function is an IRI in a shapes graph + that is a SHACL instance of sh:ListParameterExpressionFunction and + a SHACL subclass of sh:ListParameterExpression. + The IRI of a custom list parameter function is its list parameter property. + It has a single value for sh:bodyExpression that is a well-formed + node expression. +

    + Custom list parameter functions can reference the arguments using an + arg expression such as [ shnex:arg 0 ] and [ shnex:arg 1 ] + where the xsd:integer n corresponds to the nth member + of the arguments list, starting with 0 as the first member. +
    +

    +

    + + A custom list parameter expression is a node expression + represented by a blank node that is the subject of exactly one triple + and the predicate of that triple is the list parameter property of a + custom list parameter function in the shapes graph. + +

    +
    +
    EVALUATION OF CUSTOM LIST PARAMETER EXPRESSIONS
    +

    + Let expr be a custom list parameter expression with the + custom list parameter function f. + Let body be the value of sh:bodyExpression at f + in the shapes graph. +

    + Let argScope be a map of (parameter index) nodes as keys and (argument) nodes + as values, so that each list argument of expr has the index of the argument as an + xsd:integer as key, starting with 0 for the first argument. + For example, if expr has arguments ( 38 4 ) then the + argScope is { 0 : 38, 1 : 4 }. +

    + The output nodes of expr are computed using + evalExpr(expr, focusGraph, focusNode, scope) -> evalExpr(body, focusGraph, focusNode, argScope) + where an evaluation failure is reported when there is more than 1 output node. +

    +
    +

    The remainder of this section is informative.

    +

    + The following example defines a new node expression function ex:spacedConcat + that takes two nodes as input and returns a string concatenating the two nodes with a space in between. +

    + +

    + This new node expression function can the be used as follows: +

    + +
    + +
    +

    Arg Expressions

    +

    + Custom node expressions can use shnex:arg to access the arguments. +

    +

    + + A blank node that is the subject of the following properties + is called an arg expression with the function name shnex:ArgExpression: + + + + + + + + + + + + + +
    PropertyConstraintsDescription
    shnex:arg + + sh:or (
    +   [ sh:nodeKind sh:IRI ]
    +   [ sh:datatype xsd:integer ]
    + ) +
    +
    + The argument key, e.g. ex:myParameter or 1. +
    +
    +

    +
    +
    EVALUATION OF ARG EXPRESSIONS
    +

    + Let arg be the value of shnex:arg in the arg expression. + The output nodes of the var expression are computed as follows, in order: +

    +
      +
    1. + if arg is in the scope and has the value a then + evalExpr(expr, focusGraph, focusNode, scope) -> evalExpr(a, focusGraph, focusNode, {}) +
    2. +
    3. otherwise evalExpr(expr, focusGraph, focusNode, scope) -> []
    4. +
    +
    +

    The remainder of this section is informative.

    +

    + Both shnex:arg and shnex:var access values from the scope. + The difference is that shnex:arg interprets the values as node expressions, while + shnex:var treats the values as individual nodes. + As a result, a custom node expression can evaluate nested node expressions that are passed in as arguments. +

    +

    + Examples of shnex:arg can be found in + and . +

    +
    +
    +

    Constraint Components

    @@ -2765,7 +3024,7 @@

    Example: Dynamic Minimum Age of Presidents

    sh:minInclusive [ shnex:if [ sparql:eq ( - [ shnex:path ex:country ] + [ shnex:pathValues ex:country ] ex:USA ) ] @@ -2859,7 +3118,7 @@

    Example: Dynamic Enumerations

    a sh:PropertyShape ; sh:path ex:state ; sh:in [ - shnex:path ( ex:country ex:stateCode ) + shnex:pathValues ( ex:country ex:stateCode ) ] .
    @@ -2870,7 +3129,7 @@

    Example: Dynamic Enumerations

    - During validation, a Dynamic SHACL engine will evaluate the path expression at sh:in + During validation, a Dynamic SHACL engine will evaluate the path values expression at sh:in and use the resulting nodes as members of the allowed values. Thus, when the value of ex:country is ex:USA, it will look up the state codes that are linked to ex:USA. diff --git a/shacl12-vocabularies/shacl.ttl b/shacl12-vocabularies/shacl.ttl index 71d6333a..ed980e9b 100644 --- a/shacl12-vocabularies/shacl.ttl +++ b/shacl12-vocabularies/shacl.ttl @@ -1386,6 +1386,13 @@ sh:ListParameterExpression rdfs:subClassOf sh:NodeExpression ; rdfs:isDefinedBy sh: . +sh:bodyExpression + a rdf:Property ; + rdfs:label "body expression"@en ; + rdfs:comment "A node expression that is the implementation/body of a custom node expression function."@en ; + rdfs:domain sh:NodeExpressionFunction ; + rdfs:isDefinedBy sh: . + # General SPARQL execution support --------------------------------------------