-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
3,077 additions
and
719 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ berkeleydb==18.1.2 | |
networkx==2.0 | ||
html5lib==1.0.1 | ||
lxml==4.3.0 | ||
orjson==3.9.14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.