diff --git a/shacl12-rules/index.html b/shacl12-rules/index.html index 7fb7fdb5..9711eeef 100644 --- a/shacl12-rules/index.html +++ b/shacl12-rules/index.html @@ -161,6 +161,10 @@ .term2escape-yes { background-color: lightgreen; } .darkmode .term2escape-yes { background-color: darkgreen; } + + .list-indent { margin-left: 5px; } + .list-no-bullet { list-style: none; } + .list-inner { list-style: disc; } @@ -277,37 +281,37 @@

Document Conventions

bindings given above.

- - - - +
        # This box represents an output results graph
+ --> - + + + + + @@ -409,52 +413,52 @@

Basic Patterns

In this first example, we have the following data graph and rule set:

-
-   :A :fatherOf :X .
-   :B :motherOf :X .
-   :C :motherOf :A .
-
+
+            :A :fatherOf :X .
+            :B :motherOf :X .
+            :C :motherOf :A .
+          
-
-RULE { ?x :childOf ?y } WHERE { ?y :fatherOf ?x }
-RULE { ?x :childOf ?y } WHERE { ?y :motherOf ?x }
-
+
+            RULE { ?x :childOf ?y } WHERE { ?y :fatherOf ?x }
+            RULE { ?x :childOf ?y } WHERE { ?y :motherOf ?x }
+          

The above rules, applied to the data, will conclude that: `:X` is the `:childOf` `:A` and `:B`:

-
-   :X :childOf :A .
-   :X :childOf :B .
-   :A :childOf :C .
-
+
+            :X :childOf :A .
+            :X :childOf :B .
+            :A :childOf :C .
+          

We can then derive `:descendedFrom` relationships by adding a rule that depends on `:childOf` triples produced by the other rules:

-
-RULE { ?x :childOf ?y } WHERE { ?y :fatherOf ?x }
-RULE { ?x :childOf ?y } WHERE { ?y :motherOf ?x }
-RULE { ?x :descendedFrom ?y } WHERE { ?x :childOf ?y }
-
+
+            RULE { ?x :childOf ?y } WHERE { ?y :fatherOf ?x }
+            RULE { ?x :childOf ?y } WHERE { ?y :motherOf ?x }
+            RULE { ?x :descendedFrom ?y } WHERE { ?x :childOf ?y }
+          

The outcome is:

-
-   :A :descendedFrom :C .
-   :X :descendedFrom :B .
-   :X :descendedFrom :A .
-   :X :childOf :B .
-   :X :childOf :A .
-   :A :childOf :C .
-
+
+            :A :descendedFrom :C .
+            :X :descendedFrom :B .
+            :X :descendedFrom :A .
+            :X :childOf :B .
+            :X :childOf :A .
+            :A :childOf :C .
+          
@@ -464,24 +468,24 @@

Recursion

to infer that `:X` is `:descendedFrom` `:C`:

-
-RULE { ?x :childOf ?y } WHERE { ?y :fatherOf ?x }
-RULE { ?x :childOf ?y } WHERE { ?y :motherOf ?x }
-RULE { ?x :descendedFrom ?y } WHERE { ?x :childOf ?y }
-RULE { ?x :descendedFrom ?y } WHERE { ?x :childOf ?z . ?z :descendedFrom ?y }
-
+
+            RULE { ?x :childOf ?y } WHERE { ?y :fatherOf ?x }
+            RULE { ?x :childOf ?y } WHERE { ?y :motherOf ?x }
+            RULE { ?x :descendedFrom ?y } WHERE { ?x :childOf ?y }
+            RULE { ?x :descendedFrom ?y } WHERE { ?x :childOf ?z . ?z :descendedFrom ?y }
+          

giving:

-
-   :A :descendedFrom :C .
-   :X :descendedFrom :C .
-   :X :descendedFrom :B .
-   :X :descendedFrom :A .
-   :X :childOf :B .
-   :X :childOf :A .
-   :A :childOf :C .
-
+
+            :A :descendedFrom :C .
+            :X :descendedFrom :C .
+            :X :descendedFrom :B .
+            :X :descendedFrom :A .
+            :X :childOf :B .
+            :X :childOf :A .
+            :A :childOf :C .
+          

This adds the triple `:X :descendedFrom :C`.

@@ -501,20 +505,20 @@

Filtering

-
-:town1 :population 1000 .
-:town2 :population 2000 .
-
+
+            :town1 :population 1000 .
+            :town2 :population 2000 .
+          
-
-RULE { ?x rdf:type :largeTown } WHERE { ?x :population ?p . FILTER(?p > 1500) }
-
+
+            RULE { ?x rdf:type :largeTown } WHERE { ?x :population ?p . FILTER(?p > 1500) }
+          
-
-:town2 rdf:type :largeTown .
-
+
+            :town2 rdf:type :largeTown .
+          

`FILTER` evaluates an expression and keeps the current @@ -541,28 +545,28 @@

Negation

from inferred triples inferred by other rules.

-
-:X1 rdf:type :Place ;
-    :population 1000 .
+          
+            :X1 rdf:type :Place ;
+            :population 1000 .
 
-:X2 rdf:type :Place ;
-    :population 2000 .
+            :X2 rdf:type :Place ;
+            :population 2000 .
 
-:X3 rdf:type :Place .
-
+ :X3 rdf:type :Place . +
-
-  RULE { ?x rdf:type :UnclassifiedSize } WHERE { 
-      ?x rdf:type :Place .
-      NOT { ?x :population ?p . }
-  }
-
+
+            RULE { ?x rdf:type :UnclassifiedSize } WHERE { 
+            ?x rdf:type :Place .
+            NOT { ?x :population ?p . }
+            }
+          
-
-:X3 rdf:type :UnclassifiedSize .
-
+
+            :X3 rdf:type :UnclassifiedSize .
+          
@@ -574,27 +578,27 @@

Assignment and Creating RDF Terms

on the data.

-
-RULE { ?x :distanceKm ?kilometers }
-WHERE { 
-    ?x :distanceMiles ?miles .
-    SET ( ?kilometers := ?miles * 1.60934 )
-}
-
+
+            RULE { ?x :distanceKm ?kilometers }
+            WHERE { 
+            ?x :distanceMiles ?miles .
+            SET ( ?kilometers := ?miles * 1.60934 )
+            }
+          

This can be combined with testing for the absence of a triple already recording the distance in kilometers.

-
-RULE { ?x :distanceKm ?kilometers }
-WHERE { 
-    ?x :distanceMiles ?miles
-    NOT { ?x :distanceKm ?km }
-    SET ( ?kilometers := ?miles * 1.60934 )
-}
-
+
+            RULE { ?x :distanceKm ?kilometers }
+            WHERE { 
+            ?x :distanceMiles ?miles
+            NOT { ?x :distanceKm ?km }
+            SET ( ?kilometers := ?miles * 1.60934 )
+            }
+          

Rules involving [=assignments=] and rules that create blank nodes in @@ -663,14 +667,14 @@

Data Blocks

@@examples to be updated

-
-
-DATA {
-  :father rdfs:subClassOf :familyRelationship .
-  :mother rdfs:subClassOf :familyRelationship .
-}
-
-

+
+
+            DATA {
+            :father rdfs:subClassOf :familyRelationship .
+            :mother rdfs:subClassOf :familyRelationship .
+            }
+          
+
@@ -726,22 +730,14 @@

Elements of the Abstract Syntax

Expression
-

- An [=expression=] is a function or a functional form; - the arguments are [=RDF terms=]. - An expression is evaluated with respect to a [=solution mapping=], giving - an [=RDF term=] as the result. - Expressions are compatible with - SHACL list parameter functions - and with SPARQL expressions.

-
-
Condition
-
-

- A [=condition=] is an [=expression=] that evaluates to true or false. - [=Conditions=] are used to restrict the values of variables in pattern matching. -

+ An [=expression=] is a function or a functional form; + the arguments are [=RDF terms=]. + An expression is evaluated with respect to a [=solution mapping=], giving + an [=RDF term=] as the result. + Expressions are compatible with + SHACL list parameter functions + and with SPARQL expressions.
Data block
@@ -763,58 +759,52 @@

Elements of the Abstract Syntax

A [=triple pattern=] is 3-tuple where each element is either a [=variable=] or an [=RDF term=] (which might be a triple term). The second element of the tuple must be an [=IRI=] or a [=variable=]. - [=Triple patterns=] can appear as [=triple pattern elements=] - as well as inside [=negation elements=].
-
Condition element
+
Filter element
- A [=condition element=] is a [=condition=] - that appears as a [=rule body element=]. + A [=filter element=] is an [=expression=] + that appears as a [=rule element=] + It is used to restrict the values of variables + in pattern matching.
Triple pattern element
A [=triple pattern element=] is a [=triple pattern=] - used as a [=rule body element=]. + that appears as a [=rule element=].
Negation element
- A [=negation element=] is a [=rule body element=] - comprised of a sequence of [=triple patterns=] and - [=conditions=]. + A [=negation element=] is a [=rule element=]. + It has a negation element body + comprised of a sequence of [=triple pattern elements=] and + [=filter elements=].
Assignment element
- An [=assignment element=] is a pair consisting + An [=assignment element=] is a [=rule element=] that is + a pair consisting of a variable, called the assignment variable, and an expression, called the assignment expression. - [=Assignment elements=] appear in the [=body=] of a [=rule=].
-
Rule body element
-
- A [=rule body element=] (often just "rule element") is any element that - can appear in a [=rule body=], i.e., - a [=triple pattern element=], - a [=condition element=], - a [=negation element=], - or an [=assignment element=]. - +
Rule element
+
A [=rule element=] is any one of + [=triple pattern element=], + [=filter element=], + [=negation element=], or + [=assignment element=].
Rule head
@@ -824,7 +814,12 @@

Elements of the Abstract Syntax

Rule body
- A [=rule body=] is a sequence of [=rule body elements=]. + A [=rule body=] is a sequence of [=rule elements=]; + that is, each sequence element is one of + a [=triple pattern element=], + a [=filter element=], + a [=negation element=], + or an [=assignment element=].
Rule imports
@@ -894,66 +889,127 @@

Elements of the Abstract Syntax

position 3 is informally called the object.

+

+ The elements of a sequence of [=rule elements=] are labelled starting at 1. +

+

Well-formedness Conditions

- Well-formedness is a set of conditions on the abstract syntax of - SHACL rules. Together, these conditions ensure that a [=variable=] in the + Well-formedness is a set of conditions on the abstract syntax of + a [=rule set=]. Together, these conditions ensure + that a [=variable=] in the [=head=] of a rule has a value defined in the [=body=] of the rule; - that each variable in an [=condition element=] + that each variable in an [=filter element=] or [=assignment expression=] - has a value at the point of evaluation; and that each + has a value at the point of evaluation; + and that each assignment in a rule introduces a new variable, one that has not been used earlier in the rule body.

- A [=rule=] is a well-formed rule if all of the following - conditions are met: + We define well-formedness for a sequence of [=rule elements=] + given an initial starting set of variables.

-

- A [=rule set=] is "well-formed" if and only if all of the [=rules=] of the - rule set are "well-formed". + Let elti be the i-th element of a sequence of [=rule elements=].

- -

- Revisit +

+ Let varsi be the set of variables defined by + elti where: +

+
+
    +
  • + If elti is a [=triple pattern element=] then +
      +
    • + varsi is the set of [=variables=] + that occurs in the [=triple pattern element=]. +
    • +
    +
  • +
  • + If elti is a [=assignment element=] then +
      +
    • + varsi is the set of the [=assignment variable=]. +
    • +
    +
  • + Otherwise, +
      +
    • + varsi is the empty set. +
    • +
    +
  • +
+
+

+ Let V0 be the initial variables of a sequence. +

+

+ Let Vi + be the union of V0 and all varsj, + where j is less than i. +

+

+ Let Vall be VN + where N is the length of the sequence.

+

+ A well-formed sequence is a sequence of [=rule elements=], + given a set of variables V0, + if the following conditions are met: +

+
+
    +
  • + If elti is a [=filter element=] then +
      +
    • every [=variable=] mentioned in a [=filter element=] + is an element of Vi-1. +
    • +
    +
  • +
  • + If elti is a [=assignment element=] then +
      +
    • every variable mentioned in the [=assignment expression=] + is an element of Vi-1 +
    • +
    • + the [=assignment variable=] is an not element of Vi-1. +
    • +
    +
  • +
  • + If elti is a [=negation element=] then +
      +
    • + the sequence of [=rule elements=] in the + [=negation element body=] is a [=well-formed sequence=] + given the set of variables Vi-1. +
    • +
    +
  • +
+
+

+ A [=rule=] is a well-formed rule + if the sequence of the [=rule body=] is a [=well-formed sequence=] given + V0 is the empty set, + and each variable in a [=triple template=] of the [=rule head=] + is an element of Vall. +

+

+ A [=rule set=] is a well-formed rule set if and only if all + rules of the rule set are [=well-formed rules=]. +

+
@@ -1151,7 +1207,7 @@

Dependency Graph Algorithm

## Classify each triple pattern TP in the rule as requiring "open" or "closed" ## depending on whether it is in a negation element or not. let bodyDependencies = {} - foreach rule body element RBE in the body of R1: + foreach rule element RBE in the body of R1: if RBE is a negation element: foreach triple pattern TP in RBE: let item be a pair (TP, "closed") @@ -1844,7 +1900,7 @@

Calculate Stratification

Evaluation of an Expression

- An expression, whether used in a [=condition element=] or + An expression, whether used in a [=filter element=] or an [=assignment element=], is evaluated with respect to a solution mapping which provides a value which is an RDF term, for each variable in the expression.