Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SHACL path to RDFLib Path utility and corresponding tests #2699

Merged
merged 2 commits into from
Feb 27, 2024

Conversation

mgberg
Copy link
Contributor

@mgberg mgberg commented Jan 31, 2024

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.

@coveralls
Copy link

Coverage Status

coverage: 90.964% (+0.02%) from 90.943%
when pulling 3b6ded5 on mgberg:shacl-path-parser
into ce7e414 on RDFLib:main.

Copy link
Member

@nicholascar nicholascar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to see more than just one utility function for a "Utilities" SHACL file!

@nicholascar nicholascar merged commit b33b3c8 into RDFLib:main Feb 27, 2024
22 checks passed
@mgberg
Copy link
Contributor Author

mgberg commented Feb 27, 2024

Would be good to see more than just one utility function for a "Utilities" SHACL file!

Agreed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants