Skip to content

Commit ca9feaf

Browse files
committed
Update docs to 4.0.0 changes
1 parent 045297b commit ca9feaf

8 files changed

Lines changed: 85 additions & 7 deletions

File tree

README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
[Documentation](https://digitalbazaar.github.io/pyld/) |
44
[Installation](#installation) | [Usage](#usage) | [Advanced
5-
Topics](#advanced-topics) | [Contributing](./CONTRIBUTING.md) |
5+
Topics](#advanced-topics) | [What's new in version 4](#whats-new-in-version-4) |
6+
[Contributing](./CONTRIBUTING.md) |
67
[Changelog](./CHANGELOG.md)
78

89
## Introduction
@@ -45,6 +46,27 @@ memory footprint in order to operate.
4546
* [Requests](http://docs.python-requests.org/) (optional)
4647
* [aiohttp](https://aiohttp.readthedocs.io/) (optional)
4748

49+
## What's new in version 4
50+
51+
PyLD 4 moves RDF handling to [RDFLib](https://rdflib.readthedocs.io/) and adds
52+
RDF Dataset Canonicalization 1.0 support.
53+
54+
The main developer-facing changes are:
55+
56+
* `jsonld.to_rdf()` returns an `rdflib.Dataset` by default when no output
57+
`format` is requested.
58+
* `jsonld.to_rdf(doc, {'legacyMode': True})` returns the RDF.js-like dataset
59+
`dict` used by PyLD versions lower than 4.
60+
* `jsonld.from_rdf()` accepts `rdflib.Dataset`, N-Quads strings, and the legacy
61+
dataset `dict`.
62+
* `jsonld.normalize()` defaults to `RDFC10`; pass `{'algorithm': 'URDNA2015'}`
63+
if older canonicalization output must remain stable.
64+
* The internal `pyld.nquads` parser/serializer module has been removed. Use the
65+
JSON-LD APIs with `format: 'application/n-quads'` or RDFLib directly.
66+
67+
See the full [version 4 upgrade notes](https://digitalbazaar.github.io/pyld/whats-new-version-4/)
68+
and the [`4.0.0` changelog entry](./CHANGELOG.md#400---unreleased).
69+
4870
## Installation
4971

5072
PyLD can be installed with a [pip](http://www.pip-installer.org/)
@@ -121,10 +143,10 @@ flattened = jsonld.flatten(doc)
121143
framed = jsonld.frame(doc, frame)
122144
# document transformed into a particular tree structure per the given frame
123145

124-
# normalize a document using the RDF Dataset Normalization Algorithm
125-
# (URDNA2015), see: https://www.w3.org/TR/rdf-canon/
146+
# normalize a document using RDF Dataset Canonicalization 1.0
147+
# (RDFC10), see: https://www.w3.org/TR/rdf-canon/
126148
normalized = jsonld.normalize(
127-
doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
149+
doc, {'algorithm': 'RDFC10', 'format': 'application/n-quads'})
128150
# normalized is a string that is a canonical representation of the document
129151
# that can be used for hashing, comparison, etc.
130152
```

docs/.pages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
nav:
22
- Quickstart:
33
- index.md
4+
- whats-new-version-4.md
45
- installation.md
56
- conformance.md
67
- Reference:

docs/examples/normalize.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
},
1010
}
1111

12+
# Normalize with RDFC10
13+
normalized = jsonld.normalize(
14+
doc,
15+
{"format": "application/n-quads"},
16+
)
17+
18+
print(normalized)
19+
20+
# Normalize with URDNA2015
1221
normalized = jsonld.normalize(
1322
doc,
1423
{"algorithm": "URDNA2015", "format": "application/n-quads"},

docs/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ applications add meaning to existing JSON documents with in-band or out-of-band
1515
contexts, while keeping the document shape practical for web APIs, JavaScript,
1616
and JSON document stores.
1717

18+
## :material-new-box: What's new in version 4
19+
20+
PyLD 4 uses [:material-library: RDFLib](https://rdflib.readthedocs.io/)
21+
`rdflib.Dataset` as the native RDF dataset representation, adds `RDFC10`
22+
canonicalization, and removes the internal `pyld.nquads` parser/serializer
23+
module.
24+
25+
[Read the version 4 upgrade notes :octicons-arrow-right-24:](whats-new-version-4.md)
26+
1827
## :material-lightning-bolt: Quick Examples
1928

2029
=== "jsonld.compact()"

docs/reference/from_rdf.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
show_bases: false
1313
heading_level: 3
1414

15+
`jsonld.from_rdf()` accepts a
16+
[:material-library: RDFLib](https://rdflib.readthedocs.io/) `rdflib.Dataset`,
17+
an N-Quads string, or the RDF.js-like dataset `dict` returned by PyLD versions
18+
lower than 4. Prefer `rdflib.Dataset` for new in-memory RDF code.
19+
20+
```python
21+
doc = jsonld.from_rdf(dataset)
22+
doc = jsonld.from_rdf(nquads, {"format": "application/n-quads"})
23+
```
24+
1525
## Example
1626

1727
{{ example('from_rdf.py', 'json') }}

docs/reference/normalize.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212
show_bases: false
1313
heading_level: 3
1414

15+
`RDFC10` is the default algorithm in PyLD 4. Use `URDNA2015` or `URGNA2012`
16+
explicitly when an integration requires the older canonicalization output.
17+
18+
```python
19+
canonical = jsonld.normalize(
20+
doc,
21+
{"algorithm": "URDNA2015", "format": "application/n-quads"},
22+
)
23+
identifier_map = jsonld.normalize(doc, {"algorithm": "RDFC10", "outputMap": True})
24+
```
25+
1526
## Example
1627

1728
{{ example('normalize.py') }}

docs/reference/to_rdf.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@
1212
show_bases: false
1313
heading_level: 3
1414

15-
When `format` is not set, `jsonld.to_rdf()` returns an
16-
[`rdflib.Dataset`](https://rdflib.readthedocs.io/). Set `legacyMode` to `True`
17-
to return the RDF.js-like dataset `dict` used by PyLD versions lower than 4.
15+
When `format` is not set, `jsonld.to_rdf()` returns a
16+
[:material-library: RDFLib](https://rdflib.readthedocs.io/) `rdflib.Dataset`.
17+
Set `legacyMode` to `True` to return the RDF.js-like dataset `dict` used by
18+
PyLD versions lower than 4.
19+
20+
```python
21+
dataset = jsonld.to_rdf(doc)
22+
nquads = jsonld.to_rdf(doc, {"format": "application/n-quads"})
23+
legacy_dataset = jsonld.to_rdf(doc, {"legacyMode": True})
24+
```
25+
26+
`legacyMode` only affects the unformatted return value. If `format` is set,
27+
`jsonld.to_rdf()` returns the requested serialization.
1828

1929
## Example
2030

lib/pyld/options.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,18 @@ class NormalizeOptions(ProcessingOptions, total=False):
149149
algorithm: Literal['URDNA2015', 'URGNA2012', 'RDFC10']
150150
"""The algorithm to use (default: `RDFC10`)."""
151151

152+
hashAlgorithm: str
153+
"""The hashing algorithm for `RDFC10` (default: `SHA256`)."""
154+
152155
inputFormat: Literal['application/n-quads']
153156
"""The format if input is not JSON-LD: `application/n-quads` for N-Quads."""
154157

155158
format: Literal['application/n-quads']
156159
"""The format if output is a string: `application/n-quads` for N-Quads."""
157160

161+
outputMap: bool
162+
"""`True` to return a blank node identifier map instead of the normalized dataset (default: `False`)."""
163+
158164

159165
class ToRdfOptions(ProcessingOptions, total=False):
160166
documentLoader: DocumentLoader | DocumentLoaderCallable

0 commit comments

Comments
 (0)