Skip to content

Commit

Permalink
Merge branch 'main' into issue-2283
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnelson-nist committed Sep 10, 2024
2 parents 24d3ab2 + 65cd211 commit 95de373
Show file tree
Hide file tree
Showing 73 changed files with 3,077 additions and 719 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ unsure about them, submit your PR as is and ask for help.
- [ ] Created an issue to discuss the change and get in-principle agreement.
- [ ] Considered adding an example in `./examples`.
- If the change has a potential impact on users of this project:
<!-- This can be removed if the changed does affect users of this project. -->
<!-- This can be removed if the change does not affect users of this project. -->
- [ ] Added or updated tests that fail without the change.
- [ ] Updated relevant documentation to avoid inaccuracies.
- [ ] Considered adding additional documentation.
Expand Down
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ updates:
versions:
- 3.4.3
- 3.5.2
# We only use setuptools for a couple of things in the test suite
# There is no need to keep it bleeding-edge. There are too frequent
# updates to setuptools, requires too much maintenance to keep it up to date.
- dependency-name: setuptools
versions:
- ">=72.0"
- dependency-name: types-setuptools
versions:
- ">=72.0"
# Ignore all black updates, because we use a pinned version we don't want to change
- dependency-name: black
# Ignore types-setuptools patch-level updates, because they issue too many!
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The stable release of RDFLib may be installed with Python's package management t

Some features of RDFLib require optional dependencies which may be installed using *pip* extras:

$ pip install rdflib[berkeleydb,networkx,html,lxml]
$ pip install rdflib[berkeleydb,networkx,html,lxml,orjson]

Alternatively manually download the package from the Python Package
Index (PyPI) at https://pypi.python.org/pypi/rdflib
Expand Down
1 change: 1 addition & 0 deletions devtools/constraints.min
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ berkeleydb==18.1.2
networkx==2.0
html5lib==1.0.1
lxml==4.3.0
orjson==3.9.14
2 changes: 1 addition & 1 deletion docker/latest/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.io/library/python:3.12.4-slim@sha256:52f92c54e879539342692d20a4bea99516d4a2eb3cd16dfbb4e4b964aa8becaa
FROM docker.io/library/python:3.12.5-slim@sha256:105e9d85a67db1602e70fa2bbb49c1e66bae7e3bdcb6259344fe8ca116434f74

COPY docker/latest/requirements.txt /var/tmp/build/

Expand Down
2 changes: 1 addition & 1 deletion docker/unstable/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.io/library/python:3.12.4-slim@sha256:52f92c54e879539342692d20a4bea99516d4a2eb3cd16dfbb4e4b964aa8becaa
FROM docker.io/library/python:3.12.5-slim@sha256:105e9d85a67db1602e70fa2bbb49c1e66bae7e3bdcb6259344fe8ca116434f74

# This file is generated from docker:unstable in Taskfile.yml
COPY var/requirements.txt /var/tmp/build/
Expand Down
1 change: 1 addition & 0 deletions docs/plugin_parsers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ json-ld :class:`~rdflib.plugins.parsers.jsonld.JsonLDParser`
hext :class:`~rdflib.plugins.parsers.hext.HextuplesParser`
n3 :class:`~rdflib.plugins.parsers.notation3.N3Parser`
nquads :class:`~rdflib.plugins.parsers.nquads.NQuadsParser`
patch :class:`~rdflib.plugins.parsers.patch.RDFPatchParser`
nt :class:`~rdflib.plugins.parsers.ntriples.NTParser`
trix :class:`~rdflib.plugins.parsers.trix.TriXParser`
turtle :class:`~rdflib.plugins.parsers.notation3.TurtleParser`
Expand Down
6 changes: 6 additions & 0 deletions docs/plugin_serializers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ n3 :class:`~rdflib.plugins.serializers.n3.N3Serializer`
nquads :class:`~rdflib.plugins.serializers.nquads.NQuadsSerializer`
nt :class:`~rdflib.plugins.serializers.nt.NTSerializer`
hext :class:`~rdflib.plugins.serializers.hext.HextuplesSerializer`
patch :class:`~rdflib.plugins.serializers.patch.PatchSerializer`
pretty-xml :class:`~rdflib.plugins.serializers.rdfxml.PrettyXMLSerializer`
trig :class:`~rdflib.plugins.serializers.trig.TrigSerializer`
trix :class:`~rdflib.plugins.serializers.trix.TriXSerializer`
Expand All @@ -34,6 +35,11 @@ JSON-LD
-------
JSON-LD - 'json-ld' - has been incorporated into RDFLib since v6.0.0.

RDF Patch
---------

The RDF Patch Serializer - 'patch' - uses the RDF Patch format defined at https://afs.github.io/rdf-patch/. It supports serializing context aware stores as either addition or deletion patches; and also supports serializing the difference between two context aware stores as a Patch of additions and deletions.

HexTuples
---------
The HexTuples Serializer - 'hext' - uses the HexTuples format defined at https://github.com/ontola/hextuples.
Expand Down
35 changes: 35 additions & 0 deletions examples/parse_patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from rdflib import Dataset


def main():
# RDF patch data
add_patch = """
TX .
A _:bn1 <http://example.org/predicate1> "object1" .
A _:bn1 <http://example.org/predicate2> "object2" .
TC .
"""

delete_patch = """
TX .
D _:bn1 <http://example.org/predicate1> "object1" .
TC .
"""

ds = Dataset()

# Apply add patch
ds.parse(data=add_patch, format="patch")
print("After add patch:")
for triple in ds:
print(triple)

# Apply delete patch
ds.parse(data=delete_patch, format="patch")
print("After delete patch:")
for triple in ds:
print(triple)


if __name__ == "__main__":
main()
64 changes: 64 additions & 0 deletions examples/patch_serializer_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from rdflib import Dataset, Graph, Literal, URIRef


def main():
# example for adding a quad
ds = Dataset()
g = Graph(identifier=URIRef("http://graph-a"))
ds.add_graph(g)
triple = (URIRef("http://subj-a"), URIRef("http://pred-a"), Literal("obj-a"))
ds.get_context(g.identifier).add(triple)
result = ds.serialize(format="patch", operation="add")
print("Add Quad Patch:")
print(result)

# alternate example for adding a quad
ds = Dataset()
quad = (
URIRef("http://subj-a"),
URIRef("http://pred-a"),
Literal("obj-a"),
Graph(identifier=URIRef("http://graph-a")),
)
ds.add(quad)
result = ds.serialize(format="patch", operation="add")
print("Add Quad Patch:")
print(result)

# example for adding a triple
ds = Dataset()
ds.add(triple)
result = ds.serialize(format="patch", operation="add")
print("\nAdd Triple Patch:")
print(result)

# Example for diff quads
quad_1 = (
URIRef("http://subj-a"),
URIRef("http://pred-a"),
Literal("obj-a"),
Graph(identifier=URIRef("http://graph-a")),
)
quad_2 = (
URIRef("http://subj-b"),
URIRef("http://pred-b"),
Literal("obj-b"),
Graph(identifier=URIRef("http://graph-b")),
)
quad_3 = (
URIRef("http://subj-c"),
URIRef("http://pred-c"),
Literal("obj-c"),
Graph(identifier=URIRef("http://graph-c")),
)
ds1 = Dataset()
ds2 = Dataset()
ds1.addN([quad_1, quad_2])
ds2.addN([quad_2, quad_3])
result = ds1.serialize(format="patch", target=ds2)
print("Diff Quad Patch:")
print(result)


if __name__ == "__main__":
main()
Loading

0 comments on commit 95de373

Please sign in to comment.