Understanding of SHACL Function Parameters

39 Views Asked by At

I was trying to understand how SHACL functions work from the SHACL documentation available on W3C working group notes. The function code given there is as follows:

ex:multiply
    a sh:SPARQLFunction ;
    rdfs:comment "Multiplies its two arguments $op1 and $op2." ;
    sh:parameter [
        sh:path ex:op1 ;
        sh:datatype xsd:integer ;
        sh:description "The first operand" ;
    ] ;
    sh:parameter [
        sh:path ex:op2 ;
        sh:datatype xsd:integer ;
        sh:description "The second operand" ;
    ] ;
    sh:returnType xsd:integer ;
    sh:select """
        SELECT ($op1 * $op2 AS ?result)
        WHERE {
        }
        """ .

The function is called using the following code:

SELECT ?subject ?area
WHERE {
    ?subject ex:width ?width .
    ?subject ex:height ?height .
    BIND (ex:multiply(?width, ?height) AS ?area) .
}

In the function call, the name of the path and variable is same. That is, ex:width leads to ?width and ex:height leads to ?height. The function is called using the variables ?width and ?height. In the shapes graph, the parameters are reached using the property sh:path. Regarding the above, my questions are below:

  1. As shown in the example, do we need to keep the path's name and the variable same in the data graph?
  2. How does the function call work? Is the path ex:width and ex:height getting mapped to ex:op1 and ex:op2 (the doubt is because in the shapes graph, it is mentioned as sh:path ex:op1, and the name of the variables and path is same in the data graph), OR, it is the variable ?width and ?height that are getting mapped to ex:op1 and ex:op2 ? Sorry if the question is a bit naive. I am new to this area and trying to understand it better.

Thanks in advance.

0

There are 0 best solutions below