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

dataset re-work for 7.0 release #1814

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/intro_to_parsing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ Working with multi-graphs
-------------------------

To read and query multi-graphs, that is RDF data that is context-aware, you need to use rdflib's
:class:`rdflib.ConjunctiveGraph` or :class:`rdflib.Dataset` class. These are extensions to :class:`rdflib.Graph` that
know all about quads (triples + graph IDs).
:class:`rdflib.Dataset` class. This is an extension to :class:`rdflib.Graph` that know all about
quads (triples + graph IDs).

If you had this multi-graph data file (in the ``trig`` format, using new-style ``PREFIX`` statement (not the older
``@prefix``):
Expand Down
2 changes: 1 addition & 1 deletion docs/merging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ In RDFLib, blank nodes are given unique IDs when parsing, so graph merging can b
``graph`` now contains the merged graph of ``input1`` and ``input2``.


.. note:: However, the set-theoretic graph operations in RDFLib are assumed to be performed in sub-graphs of some larger data-base (for instance, in the context of a :class:`~rdflib.graph.ConjunctiveGraph`) and assume shared blank node IDs, and therefore do NOT do *correct* merging, i.e.::
.. note:: However, the set-theoretic graph operations in RDFLib are assumed to be performed in sub-graphs of some larger data-base (for instance, in the context of a :class:`~rdflib.graph.Dataset`) and assume shared blank node IDs, and therefore do NOT do *correct* merging, i.e.::

from rdflib import Graph

Expand Down
3 changes: 2 additions & 1 deletion docs/persistence.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ In most cases, passing the name of the store to the Graph constructor is enough:


Most stores offering on-disk persistence will need to be opened before reading or writing.
When peristing a triplestore, rather than a ConjuntiveGraph quadstore, you need to specify
When peristing a triplestore, rather than a Dataset quadstore, you need to specify
an identifier with which you can open the graph:

.. code-block:: python
Expand Down Expand Up @@ -73,6 +73,7 @@ More store implementations are available in RDFLib extension projects:
* `rdflib-sqlalchemy <https://github.com/RDFLib/rdflib-sqlalchemy>`_, which supports stored on a wide-variety of RDBMs backends,
* `rdflib-leveldb <https://github.com/RDFLib/rdflib-leveldb>`_ - a store on to of Google's `LevelDB <https://code.google.com/p/leveldb/>`_ key-value store.
* `rdflib-kyotocabinet <https://github.com/RDFLib/rdflib-kyotocabinet>`_ - a store on to of the `Kyoto Cabinet <http://fallabs.com/kyotocabinet/>`_ key-value store.
* `rdflib-sqlitelsm <https://github.com/RDFLib/rdflib-sqlitelsm>`_ - a store on to of the `SQLite LSM <https://sqlite.org/src4/doc/trunk/www/lsm.wiki>`_ key-value store.

Example
^^^^^^^
Expand Down
8 changes: 4 additions & 4 deletions docs/plugin_parsers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ xml :class:`~rdflib.plugins.parsers.rdfxml.RDFXMLParser`

Multi-graph IDs
---------------
Note that for correct parsing of multi-graph data, e.g. Trig, HexT, etc., into a ``ConjunctiveGraph`` or a ``Dataset``,
as opposed to a context-unaware ``Graph``, you will need to set the ``publicID`` of the ``ConjunctiveGraph`` a
``Dataset`` to the identifier of the ``default_context`` (default graph), for example::
Note that for correct parsing of multi-graph data, e.g. Trig, HexT, etc., into a a ``Dataset``,
as opposed to a context-unaware ``Graph``, you will need to set the ``publicID`` of the
``Dataset`` to the identifier of the ``default_graph``, for example::

d = Dataset()
d.parse(
data=""" ... """,
format="trig",
publicID=d.default_context.identifier
publicID=d.default_graph.identifier
)

(from the file tests/test_serializer_hext.py)
12 changes: 6 additions & 6 deletions examples/berkeleydb_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Example 1: simple actions

* creating a ConjunctiveGraph using the BerkeleyDB Store
* creating a Dataset using the BerkeleyDB Store
* adding triples to it
* counting them
* closing the store, emptying the graph
Expand All @@ -16,17 +16,17 @@
* does not delete the DB at the end so you can see it on disk
"""
import os
from rdflib import ConjunctiveGraph, Namespace, Literal
from rdflib import Dataset, Namespace, Literal
from rdflib.store import NO_STORE, VALID_STORE
from tempfile import mktemp


def example_1():
"""Creates a ConjunctiveGraph and performs some BerkeleyDB tasks with it"""
"""Creates a Dataset and performs some BerkeleyDB tasks with it"""
path = mktemp()

# Declare we are using a BerkeleyDB Store
graph = ConjunctiveGraph("BerkeleyDB")
graph = Dataset("BerkeleyDB")

# Open previously created store, or create it if it doesn't exist yet
# (always doesn't exist in this example as using temp file location)
Expand Down Expand Up @@ -64,7 +64,7 @@ def example_1():
graph = None

# reopen the graph
graph = ConjunctiveGraph("BerkeleyDB")
graph = Dataset("BerkeleyDB")

graph.open(path, create=False)

Expand Down Expand Up @@ -103,7 +103,7 @@ def example_2():
import json
import base64

g = ConjunctiveGraph("BerkeleyDB")
g = Dataset("BerkeleyDB")
g.open("gsg_vocabs", create=True)

# gsq_vocabs = "https://api.github.com/repos/geological-survey-of-queensland/vocabularies/git/trees/master"
Expand Down
20 changes: 12 additions & 8 deletions examples/conjunctive_graphs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
An RDFLib ConjunctiveGraph is an (unnamed) aggregation of all the Named Graphs
within a Store. The :meth:`~rdflib.graph.ConjunctiveGraph.get_context`
An RDFLib Dataset is a means of working with a set of Named Graphs
within a Store. The :meth:`~rdflib.graph.Dataset.graph`
method can be used to get a particular named graph for use, such as to add
triples to, or the default graph can be used.

Expand All @@ -9,10 +9,10 @@
"""

from rdflib import Namespace, Literal, URIRef
from rdflib.graph import Graph, ConjunctiveGraph
from rdflib.graph import Graph, Dataset
from rdflib.plugins.stores.memory import Memory

if __name__ == "__main__":
def test_dataset_example():

LOVE = Namespace("http://love.com#")
LOVERS = Namespace("http://love.com/lovers/")
Expand All @@ -25,25 +25,25 @@

store = Memory()

g = ConjunctiveGraph(store=store)
g = Dataset(store=store, default_union=True)
g.bind("love", LOVE)
g.bind("lovers", LOVERS)

# Add a graph containing Mary's facts to the Conjunctive Graph
gmary = Graph(store=store, identifier=cmary)
gmary = g.graph(cmary)
# Mary's graph only contains the URI of the person she loves, not his cute name
gmary.add((mary, LOVE.hasName, Literal("Mary")))
gmary.add((mary, LOVE.loves, john))

# Add a graph containing John's facts to the Conjunctive Graph
gjohn = Graph(store=store, identifier=cjohn)
gjohn = g.graph(cjohn)
# John's graph contains his cute name
gjohn.add((john, LOVE.hasCuteName, Literal("Johnny Boy")))

# Enumerate contexts
print("Contexts:")
for c in g.contexts():
print(f"-- {c.identifier} ")
print(f"-- {c} ")
print("===================")
# Separate graphs
print("John's Graph:")
Expand All @@ -63,3 +63,7 @@
xx = x
print("Q: Who does Mary love?")
print("A: Mary loves {}".format(xx))

if __name__ == "__main__":
test_dataset_example()

4 changes: 2 additions & 2 deletions examples/datasets.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
An RDFLib Dataset is a slight extension to ConjunctiveGraph: it uses simpler terminology
An RDFLib Dataset uses simpler terminology than the old ConjunctiveGraph
and has a few additional convenience method extensions, for example add() can be used to
add quads directly to a specific Graph within the Dataset.

This example file shows how to decalre a Dataset, add content to it, serialise it, query it
This example file shows how to declare a Dataset, add content to it, serialise it, query it
and remove things from it.
"""

Expand Down
152 changes: 0 additions & 152 deletions examples/film.py

This file was deleted.

8 changes: 4 additions & 4 deletions examples/swap_primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
http://www.w3.org/2000/10/swap/Primer
"""

from rdflib import ConjunctiveGraph, Namespace, Literal
from rdflib import Dataset, Namespace, Literal
from rdflib.namespace import OWL, DC

if __name__ == "__main__":
Expand All @@ -14,7 +14,7 @@
# Here we create a "Graph" of our work.
# Think of it as a blank piece of graph paper!

primer = ConjunctiveGraph()
primer = Dataset()
myNS = Namespace("https://example.com/")

primer.add((myNS.pat, myNS.knows, myNS.jo))
Expand Down Expand Up @@ -59,7 +59,7 @@
# with a fresh new graph.

del primer
primer = ConjunctiveGraph()
primer = Dataset(default_union=True)

# Lets start with a verbatim string straight from the primer text:

Expand Down Expand Up @@ -117,7 +117,7 @@

print()
print("Printing bigger example's triples:")
for i in [(x, y, z) for x, y, z in primer]:
for i in [(x, y, z, c) for x, y, z, c in primer]:
print(i)

# or spit it back out (mostly) the way we created it:
Expand Down
4 changes: 2 additions & 2 deletions examples/transitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"""

if __name__ == "__main__":
from rdflib import ConjunctiveGraph, URIRef
from rdflib import Dataset, URIRef

person = URIRef("ex:person")
dad = URIRef("ex:d")
Expand All @@ -56,7 +56,7 @@

parent = URIRef("ex:parent")

g = ConjunctiveGraph()
g = Dataset()
g.add((person, parent, dad))
g.add((person, parent, mom))
g.add((dad, parent, momOfDad))
Expand Down
Loading