Skip to content
Merged
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
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
args: ["--fix"]
- repo: https://github.com/psf/black-pre-commit-mirror
# WARNING: Black version should be the same as in `pyproject.toml`
rev: "25.1.0"
rev: "24.4.2"
hooks:
- id: black
pass_filenames: false
Expand All @@ -24,6 +24,5 @@ repos:
rev: 2.1.1
hooks:
- id: poetry-check
- id: poetry-lock
# sadly `--no-update` does not work on pre-commit.ci
args: ["--check"]
args: ["--lock"]
4 changes: 2 additions & 2 deletions rdflib/plugins/parsers/notation3.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

from rdflib.compat import long_type
from rdflib.exceptions import ParserError
from rdflib.graph import ConjunctiveGraph, Graph, QuotedGraph
from rdflib.graph import Dataset, Graph, QuotedGraph
from rdflib.term import (
_XSD_PFX,
BNode,
Expand Down Expand Up @@ -2047,7 +2047,7 @@ def parse( # type: ignore[override]
elif not fa:
raise ParserError("Cannot parse N3 into non-formula-aware store.")

conj_graph = ConjunctiveGraph(store=graph.store)
conj_graph = Dataset(store=graph.store)
conj_graph.default_context = graph # TODO: CG __init__ should have a
# default_context arg
# TODO: update N3Processor so that it can use conj_graph as the sink
Expand Down
4 changes: 2 additions & 2 deletions test/test_graph/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import rdflib
from rdflib import Graph
from rdflib.compare import graph_diff
from rdflib.graph import ConjunctiveGraph, Dataset
from rdflib.graph import Dataset
from rdflib.namespace import FOAF, RDF
from rdflib.term import BNode, Literal
from test.utils import (
Expand Down Expand Up @@ -111,7 +111,7 @@ def as_element_set(self, value: _ElementSetTypeOrStr) -> _ElementSetType:
if isinstance(value, str):
graph = self.graph_type()
graph.parse(data=value, format=self.format)
if isinstance(graph, ConjunctiveGraph):
if isinstance(graph, Dataset):
return GraphHelper.quad_set(graph, BNodeHandling.COLLAPSE)
else:
return GraphHelper.triple_set(graph, BNodeHandling.COLLAPSE)
Expand Down
76 changes: 34 additions & 42 deletions test/test_graph/test_graph_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,71 +291,63 @@ def test_triples(self):

for c in [graph, self.graph.get_context(c1)]:
# unbound subjects
asserte(set(c.subjects(likes, pizza)), set((michel, tarek)))
asserte(set(c.subjects(hates, pizza)), set((bob,)))
asserte(set(c.subjects(likes, cheese)), set([tarek, bob, michel]))
asserte(set(c.subjects(likes, pizza)), {michel, tarek})
asserte(set(c.subjects(hates, pizza)), {bob})
asserte(set(c.subjects(likes, cheese)), {tarek, bob, michel})
asserte(set(c.subjects(hates, cheese)), set())

# unbound objects
asserte(set(c.objects(michel, likes)), set([cheese, pizza]))
asserte(set(c.objects(tarek, likes)), set([cheese, pizza]))
asserte(set(c.objects(bob, hates)), set([michel, pizza]))
asserte(set(c.objects(bob, likes)), set([cheese]))
asserte(set(c.objects(michel, likes)), {cheese, pizza})
asserte(set(c.objects(tarek, likes)), {cheese, pizza})
asserte(set(c.objects(bob, hates)), {michel, pizza})
asserte(set(c.objects(bob, likes)), {cheese})

# unbound predicates
asserte(set(c.predicates(michel, cheese)), set([likes]))
asserte(set(c.predicates(tarek, cheese)), set([likes]))
asserte(set(c.predicates(bob, pizza)), set([hates]))
asserte(set(c.predicates(bob, michel)), set([hates]))
asserte(set(c.predicates(michel, cheese)), {likes})
asserte(set(c.predicates(tarek, cheese)), {likes})
asserte(set(c.predicates(bob, pizza)), {hates})
asserte(set(c.predicates(bob, michel)), {hates})

asserte(set(c.subject_objects(hates)), set([(bob, pizza), (bob, michel)]))
asserte(set(c.subject_objects(hates)), {(bob, pizza), (bob, michel)})
asserte(
set(c.subject_objects(likes)),
set(
[
(tarek, cheese),
(michel, cheese),
(michel, pizza),
(bob, cheese),
(tarek, pizza),
]
),
{
(tarek, cheese),
(michel, cheese),
(michel, pizza),
(bob, cheese),
(tarek, pizza),
},
)

asserte(
set(c.predicate_objects(michel)), set([(likes, cheese), (likes, pizza)])
)
asserte(set(c.predicate_objects(michel)), {(likes, cheese), (likes, pizza)})
asserte(
set(c.predicate_objects(bob)),
set([(likes, cheese), (hates, pizza), (hates, michel)]),
)
asserte(
set(c.predicate_objects(tarek)), set([(likes, cheese), (likes, pizza)])
{(likes, cheese), (hates, pizza), (hates, michel)},
)
asserte(set(c.predicate_objects(tarek)), {(likes, cheese), (likes, pizza)})

asserte(
set(c.subject_predicates(pizza)),
set([(bob, hates), (tarek, likes), (michel, likes)]),
{(bob, hates), (tarek, likes), (michel, likes)},
)
asserte(
set(c.subject_predicates(cheese)),
set([(bob, likes), (tarek, likes), (michel, likes)]),
{(bob, likes), (tarek, likes), (michel, likes)},
)
asserte(set(c.subject_predicates(michel)), set([(bob, hates)]))
asserte(set(c.subject_predicates(michel)), {(bob, hates)})

asserte(
set(c),
set(
[
(bob, hates, michel),
(bob, likes, cheese),
(tarek, likes, pizza),
(michel, likes, pizza),
(michel, likes, cheese),
(bob, hates, pizza),
(tarek, likes, cheese),
]
),
{
(bob, hates, michel),
(bob, likes, cheese),
(tarek, likes, pizza),
(michel, likes, pizza),
(michel, likes, cheese),
(bob, hates, pizza),
(tarek, likes, cheese),
},
)

# remove stuff and make sure the graph is empty again
Expand Down
6 changes: 3 additions & 3 deletions test/test_graph/test_graph_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from rdflib import RDF, RDFS, BNode, URIRef, Variable, plugin
from rdflib.graph import ConjunctiveGraph, QuotedGraph
from rdflib.graph import Dataset, QuotedGraph

implies = URIRef("http://www.w3.org/2000/10/swap/log#implies")
testN3 = """
Expand All @@ -21,7 +21,7 @@

def checkFormulaStore(store="default", configString=None): # noqa: N802, N803
try:
g = ConjunctiveGraph(store=store)
g = Dataset(store=store)
except ImportError:
pytest.skip("Dependencies for store '%s' not available!" % store)

Expand All @@ -48,7 +48,7 @@ def checkFormulaStore(store="default", configString=None): # noqa: N802, N803
d = URIRef("http://test/d")
v = Variable("y")

universe = ConjunctiveGraph(g.store)
universe = Dataset(g.store)

# test formula as terms
assert len(list(universe.triples((formulaA, implies, formulaB)))) == 1
Expand Down
5 changes: 2 additions & 3 deletions test/test_graph/test_namespace_rebinding.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from rdflib import ConjunctiveGraph, Graph, Literal
from rdflib import Dataset, Graph, Literal
from rdflib.namespace import OWL, Namespace, NamespaceManager
from rdflib.plugins.stores.memory import Memory
from rdflib.term import URIRef
Expand Down Expand Up @@ -292,12 +292,11 @@ def test_multigraph_bindings():
assert list(g1.namespaces()) == [("friend-of-a-friend", foaf1_uri)]

# Including newly-created objects that use the store
cg = ConjunctiveGraph(store=store)
cg = Dataset(store=store, default_union=True)
cg.namespace_manager = NamespaceManager(cg, bind_namespaces="core")

assert ("foaf", foaf1_uri) not in list(cg.namespaces())
assert ("friend-of-a-friend", foaf1_uri) in list(cg.namespaces())

assert len(list(g1.namespaces())) == 6
assert len(list(g2.namespaces())) == 6
assert len(list(cg.namespaces())) == 6
Expand Down
26 changes: 13 additions & 13 deletions test/test_n3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from rdflib.graph import ConjunctiveGraph, Graph
from rdflib.graph import Dataset, Graph
from rdflib.plugins.parsers.notation3 import BadSyntax, exponent_syntax
from rdflib.term import Literal, URIRef
from test import TEST_DIR
Expand Down Expand Up @@ -44,7 +44,7 @@
n3:predicate :p;
n3:object :y ] a log:Truth}.

# Needs more thought ... ideally, we have the implcit AND rules of
# Needs more thought ... ideally, we have the implicit AND rules of
# juxtaposition (introduction and elimination)

{
Expand Down Expand Up @@ -125,9 +125,9 @@ def test_base_serialize(self):
)
s = g.serialize(base="http://example.com/", format="n3", encoding="latin-1")
assert b"<people/Bob>" in s
g2 = ConjunctiveGraph()
g2.parse(data=s, publicID="http://example.com/", format="n3")
assert list(g) == list(g2)
g2 = Dataset()
g2.parse(data=s, format="n3")
assert list(g) == list(g2.triples((None, None, None)))

def test_issue23(self):
input = """<http://example.com/article1> <http://example.com/title> "this word is in \\u201Cquotes\\u201D"."""
Expand Down Expand Up @@ -195,24 +195,24 @@ def test_dot_in_prefix(self):
)

def test_model(self):
g = ConjunctiveGraph()
g = Dataset()
g.parse(data=test_data, format="n3")
i = 0
for s, p, o in g:
for s, p, o, c in g:
if isinstance(s, Graph):
i += 1
assert i == 3
assert len(list(g.contexts())) == 13
assert len(list(g.graphs())) == 13

g.close()

def test_quoted_serialization(self):
g = ConjunctiveGraph()
g = Dataset()
g.parse(data=test_data, format="n3")
g.serialize(format="n3")

def test_parse(self):
g = ConjunctiveGraph()
g = Dataset()
try:
g.parse(
"http://groups.csail.mit.edu/dig/2005/09/rein/examples/troop42-policy.n3",
Expand All @@ -229,14 +229,14 @@ def test_single_quoted_literals(self):

for data in test_data:
# N3 doesn't accept single quotes around string literals
g = ConjunctiveGraph()
g = Dataset()
with pytest.raises(BadSyntax):
g.parse(data=data, format="n3")

g = ConjunctiveGraph()
g = Dataset()
g.parse(data=data, format="turtle")
assert len(g) == 1
for _, _, o in g:
for _, _, o, c in g:
assert o == Literal("o")

def test_empty_prefix(self):
Expand Down
6 changes: 3 additions & 3 deletions test/test_parsers/test_empty_xml_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
and RDF/XML dependence on it
"""

from rdflib.graph import ConjunctiveGraph
from rdflib.graph import Dataset
from rdflib.namespace import FOAF, RDF
from rdflib.term import URIRef

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

class TestEmptyBase:
def test_empty_base_ref(self):
self.graph = ConjunctiveGraph()
self.graph = Dataset()
self.graph.parse(data=test_data, publicID=baseUri, format="xml")
assert (
len(list(self.graph)) > 0
Expand All @@ -50,7 +50,7 @@ def test_empty_base_ref(self):

class TestRelativeBase:
def test_relative_base_ref(self):
self.graph = ConjunctiveGraph()
self.graph = Dataset()
self.graph.parse(data=test_data2, publicID=baseUri2, format="xml")
assert (
len(self.graph) > 0
Expand Down
Loading
Loading