From c3c12b2074eab3c5009a741354c60946907eacb2 Mon Sep 17 00:00:00 2001 From: Nicholas Car Date: Thu, 9 Jan 2025 17:50:19 +1000 Subject: [PATCH] remove ConjunctiveGraph example; add Dataset example; add JSON-LS serialization example --- docs/apidocs/examples.rst | 14 +++++++++++--- examples/datasets.py | 12 ++++++------ examples/jsonld_serialization.py | 29 ++++++++++++++++++++--------- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/docs/apidocs/examples.rst b/docs/apidocs/examples.rst index 43b92c137..a8c3429bd 100644 --- a/docs/apidocs/examples.rst +++ b/docs/apidocs/examples.rst @@ -3,10 +3,18 @@ examples Package These examples all live in ``./examples`` in the source-distribution of RDFLib. -:mod:`~examples.conjunctive_graphs` Module ------------------------------------------- +:mod:`~examples.datasets` Module +-------------------------------- + +.. automodule:: examples.datasets + :members: + :undoc-members: + :show-inheritance: + +:mod:`~examples.jsonld_serialization` Module +-------------------------------------------- -.. automodule:: examples.conjunctive_graphs +.. automodule:: examples.jsonld_serialization :members: :undoc-members: :show-inheritance: diff --git a/examples/datasets.py b/examples/datasets.py index 7dfc4e48b..eab3aa384 100644 --- a/examples/datasets.py +++ b/examples/datasets.py @@ -1,5 +1,5 @@ """ -This file contains a number of common tasks using the RDFLib Dataset class. +This module contains a number of common tasks using the RDFLib Dataset class. An RDFLib Dataset is an object that stores multiple Named Graphs - instances of RDFLib Graph identified by IRI - within it and allows whole-of-dataset or single Graph use. @@ -10,11 +10,11 @@ There is an older implementation of a Dataset-like class in RDFLib < 7.x called ConjunctiveGraph that is now deprecated. -Sections in this file: +Sections in this module: -1. Creating & Adding -2. Looping & Counting -3. Manipulating Graphs +1. Creating & Growing Datasets +2. Looping & Counting triples/quads in Datasets +3. Manipulating Graphs with Datasets """ from rdflib import Dataset, Graph, Literal, URIRef @@ -30,7 +30,7 @@ # mypy: ignore_errors=true ####################################################################################### -# 1. Creating & Adding +# 1. Creating & Growing ####################################################################################### # Create an empty Dataset diff --git a/examples/jsonld_serialization.py b/examples/jsonld_serialization.py index 5bee1a614..dd83d6a5d 100644 --- a/examples/jsonld_serialization.py +++ b/examples/jsonld_serialization.py @@ -1,24 +1,35 @@ """ -JSON-LD is "A JSON-based Serialization for Linked Data" (https://www.w3.org/TR/json-ld/) that RDFLib implements for RDF serialization. +JSON-LD is "A JSON-based Serialization for Linked Data" (https://www.w3.org/TR/json-ld/) +that RDFLib implements for RDF serialization. -This file demonstrated some of the JSON-LD things you can do with RDFLib. Parsing & serializing so far. More to be added later. +This file demonstrated some of the JSON-LD things you can do with RDFLib. Parsing & +serializing so far. More to be added later. Parsing ------- -There are a number of "flavours" of JSON-LD - compact and verbose etc. RDFLib can parse all of these in a normal RDFLib way. + +There are a number of "flavours" of JSON-LD - compact and verbose etc. RDFLib can parse +all of these in a normal RDFLib way. Serialization ------------- -JSON-LD has a number of options for serialization - more than other RDF formats. For example, IRIs within JSON-LD can be compacted down to CURIES when a "context" statment is added to the JSON-LD data that maps identifiers - short codes - to IRIs and namespace IRIs like this: -# here the short code "dcterms" is mapped to the IRI http://purl.org/dc/terms/ and "schema" to https://schema.org/, as per RDFLib's in-build namespace prefixes +JSON-LD has a number of options for serialization - more than other RDF formats. For +example, IRIs within JSON-LD can be compacted down to CURIES when a "context" statement +is added to the JSON-LD data that maps identifiers - short codes - to IRIs and namespace +IRIs like this: -"@context": { - "dct": "http://purl.org/dc/terms/", - "schema": "https://schema.org/" -} +.. code-block:: json + + "@context": { + "dcterms": "http://purl.org/dc/terms/", + "schema": "https://schema.org/" + } + +Here the short code "dcterms" is mapped to the IRI http://purl.org/dc/terms/ and +"schema" to https://schema.org/, as per RDFLib's in-build namespace prefixes. """ # import RDFLib and other things