1. The algorithm
Input:
-
The subject IRI
M
. This is the first focus node. -
An optional shape topology and a Term for the shape to start from
S
-
A list of other subject IRIs to ignore, because we do not want to include quads from other entity descriptions.
Process:
-
When a shape topology was set, execute the shape topology extraction algorithm, yet exclude all quads that have another member (from the current context) set as their named graph
-
If no shape topology was set, extract all quads with subject the focus node, and recursively include its blank nodes (see also [CBD])
-
Extract all quads with the graph name matching the focus node
-
When no quads were extracted from steps 1-3, a client MUST fetch more information about the focus node (i.e. by dereferencing it) and re-execute 1-3.
1.1. Shape Topology extraction
The Shape Topology is a structure that looks as follows:
class ShapeTopology{ closed: boolean ; requiredPaths: Path []; optionalPaths: Path []; nodelinks: NodeLink []; atLeastOneLists: [ Shape[] ]; } class NodeLink{ shape: ShapeTopology ; path: Path ; }
Paths in the shape topologies are SHACL Property Paths.
A Shape Topology has
-
Closed: A boolean telling whether it’s closed or not. If it’s open, a client MUST extract all quads, after a potential HTTP request to the focus node, with subject the focus node, and recursively include its blank nodes
-
Required paths: MUST trigger an HTTP request if the member does not have this path. All quads from paths, after a potential HTTP request, matching this required path MUST be added to the Member set.
-
Optional paths: All quads from paths, after a potential HTTP request, matching this path MUST be added to the Member set.
-
Node Links: A nodelink contains a reference to another Shape Topology, as well as a path. All quads, after a potential HTTP request, matching this path MUST be added to the Member set. The targets MUST be processed again using the shape topology extraction algorithm on that
-
atLeastOneLists: Each atLeastOneList is an array of at least one shape with one or more required paths and atLeastOneLists that must be set. If none of the shapes match, it will trigger an HTTP request. Only the quads from paths matching valid shapes are included in the Member.
Note: Certain quads are going to be matched by the algorithm multiple times. Each quad will of course be part of the member only once.
This results in this algorithm:
-
If it is open, a client MUST extract all quads, after a potential HTTP request to the focus node, with subject the focus node, and recursively include its blank nodes
-
If the current focus node is a named node and it was not requested before:
-
test if all required paths are set, if not do an HTTP request, if they are set, then,
-
test if at least one of each list in the atLeastOneLists was set. If not, do an HTTP request.
-
-
Visit all paths (required, optional, nodelinks and recursively the shapes in the atLeastOneLists if the shape is valid) paths and add all quads necessary to reach the targets to the result
-
For the results of nodelinks, if the target is a named node, set it as a focus node and repeat this algorithm with that nodelink’s shape as a shape
1.1.1. Generating a shape topology from SHACL
On a tree:Collection
, a SHACL shape MAY be provided with the tree:shape
property.
In that case, the SHACL shape MUST be processed towards a Shape topology as follows:
-
Checks if the shape is deactivated (
:S sh:deactivated true
), if it is, don’t continue -
Check if the shape is closed (
:S sh:closed true
), set the closed boolean to true. -
All
sh:property
elements with ansh:node
link are added to the shape’s NodeLinks array -
Add all properties with
sh:minCount
> 0 to the Required Paths array, and all others to the optional paths. -
Processes the conditionals
sh:xone
,sh:or
andsh:and
(but doesn’t processsh:not
):-
sh:and
: all properties on that shape topology MUST be merged with the current shape topology -
sh:xone
andsh:or
: in both cases, at least one item must match at least one quad for all required paths. If not, it will do an HTTP request to the current namednode.
-