Add SHACL path to RDFLib Path utility and corresponding tests by mgberg · Pull Request #2699 · RDFLib/rdflib (original) (raw)
Summary of changes
This adds a utility to parse valid SHACL Paths (e.g. the objects of triples with predicate sh:path
) into an RDFLib-friendly object. The resulting object could either be:
- A
URIRef
, when the path is simply a predicate - A
Path
, when the path is complex (e.g.[sh:inversePath skos:broader]
)
This enables easy evaluation and manipulation of SHACL paths using RDFLib. For example:
- The output can be passed to any of several methods (
Graph.triples
,Graph.value
, etc.) as a predicate to get value(s) at that path - The
n3
method can be used to get a SPARQL property path representation of the path
Note that pyshacl
does not have a utility to do this- rather, it only evaluates SHACL paths.
Checklist
- Checked that there aren't other open pull requests for
the same change. - Checked that all tests and type checking passes.
- Considered granting push permissions to the PR branch,
so maintainers can fix minor issues and keep your PR up to date.