shacl
Utilities for interacting with SHACL Shapes Graphs more easily.
Classes:
Functions:
-
build_shacl_path–Build the SHACL Path triples for a path given by a
URIReffor -
parse_shacl_path–Parse a valid SHACL path (e.g. the object of a triple with predicate sh:path)
SHACLPathError
Bases: Exception
build_shacl_path
build_shacl_path(path: URIRef | Path, target_graph: Graph | None = None) -> tuple[IdentifiedNode, Graph | None]
Build the SHACL Path triples for a path given by a URIRef for
simple paths or a Path for complex paths.
Returns an IdentifiedNode for the path (which should be
the object of a triple with predicate sh:path) and the graph into which any
new triples were added.
Parameters:
-
(pathURIRef | Path) – -
(target_graphGraph | None, default:None) –Optionally, a
Graphinto which to put constructed triples. If not provided, a new graph will be created
Returns:
-
tuple[IdentifiedNode, Graph | None]–A (path_identifier, graph) tuple where: - path_identifier: If path is a
URIRef, this is simply the provided path. If path is aPath, this is theBNodecorresponding to the root of the SHACL path expression added to the graph. - graph: None if path is aURIRef(as no new triples are constructed). If path is aPath, this is either the target_graph provided or a new graph into which the path triples were added.
Source code in rdflib/extras/shacl.py
parse_shacl_path
parse_shacl_path(shapes_graph: Graph, path_identifier: Node) -> Union[URIRef, Path]
Parse a valid SHACL path (e.g. the object of a triple with predicate sh:path)
from a Graph as a URIRef if the path
is simply a predicate or a Path otherwise.
Parameters:
-
(shapes_graphGraph) –A
Graphcontaining the path to be parsed -
(path_identifierNode) –A
Nodeof the path
Returns: