From 82d5756400b87c049cffe6b099556c13ddf4877e Mon Sep 17 00:00:00 2001
From: Andy Seaborne Document Conventions
bindings given above.
# This box represents an output results graph+ --> - + + + + + @@ -409,52 +413,52 @@
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 . +
-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 @@
-: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 @@
-: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 . +
-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 @@
@@examples to be updated
-
-DATA {
- :father rdfs:subClassOf :familyRelationship .
- :mother rdfs:subClassOf :familyRelationship .
-}
-
-
+
+ DATA {
+ :father rdfs:subClassOf :familyRelationship .
+ :mother rdfs:subClassOf :familyRelationship .
+ }
+
+ - 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.
-- 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.+ The elements of a sequence of [=rule elements=] are labelled starting at 1. +
+- 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: +
++ 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: +
++ 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=]. +
+- 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.