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

Document RDFLib and pyld usage patterns #2823

Open
edmondchuc opened this issue Jul 15, 2024 · 1 comment
Open

Document RDFLib and pyld usage patterns #2823

edmondchuc opened this issue Jul 15, 2024 · 1 comment

Comments

@edmondchuc
Copy link
Contributor

We are collecting common use cases and patterns with working with JSON-LD in RDFLib and pyld and plan to add them to the RDFLib documentation.

The below details copied from this comment: #2308 (comment)

The pyld + RDFLib things I normally do:

Getting RDF into a framed JSON-LD

  • Serialize an RDFLib graph as JSON-LD
  • Alternatively, serialize the RDFLib graph as n-triples or n-quads and use the pyld processor' from_rdf function
  • Use the frame function in the pyld processor with the JSON-LD data + frame and context as inputs

The above is the same for compaction and expansion by using the relevant function in the pyld processor.

Parsing JSON-LD with pyld and loading into an RDFLib graph

  • To avoid some issues with the RDFLib's JSON-LD parser, we can use the pyld processor to parse it using the normalize function
  • The result is an n-quads string. This can now be loaded into an RDFLib graph or dataset
  • Alternatively, there's also a to_rdf function without the normalization algorithm. This is potentially faster.
@ajnelson-nist
Copy link
Contributor

A usage1 pattern I have is similar to your first heading, @edmondchuc . I have workflows that generate Git-tracked example data - most often in Turtle and/or JSON-LD. The steps I take are:

  1. Serialize a graph as JSON-LD.
  2. Use PyLD for compaction.

One example is in these Makefile lines, which call a Python wrapper to pyld.jsonld.compact here.

I wrote that logic a while before rdflib-jsonld was integrated into rdflib, and never got around to looking. Is there access to a compaction function in rdflib somewhere that obviates this usage pattern?

Footnotes

  1. Participation by NIST in the creation of the documentation of mentioned software is not intended to imply a recommendation or endorsement by the National Institute of Standards and Technology, nor is it intended to imply that any specific software is necessarily the best available for the purpose.

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

No branches or pull requests

2 participants