Skip to content

Commit 42913b5

Browse files
committed
checkpoint
1 parent 83ec82e commit 42913b5

27 files changed

+350
-91
lines changed

rdflib/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@
118118

119119
del sys
120120

121+
#: Checking if this works ...
122+
CHECKME_A = 1
123+
121124

122125
NORMALIZE_LITERALS = True
123126
"""

rdflib/util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ def _iri2uri(iri: str) -> str:
620620

621621
def _has_non_default_graphs(graph: rdflib.graph.ConjunctiveGraph) -> bool:
622622
"""
623-
Check if the value passed as `graph` contains graphs other than the default
624-
graph.
623+
Check if the container passed as `graph` contains graphs other than the
624+
default graph.
625625
626626
The intent of this is to detect if the value passed can be serialized using
627627
formats which do not support named graphs like N-Triples and Turtle.
@@ -636,9 +636,9 @@ def _has_non_default_graphs(graph: rdflib.graph.ConjunctiveGraph) -> bool:
636636
least one graph other than the default graph it will return `True`.
637637
"""
638638
default_context = graph.default_context
639-
logging.debug("default_context.identifier = %s", default_context.identifier)
639+
# logging.debug("default_context.identifier = %s", default_context.identifier)
640640
for context_index, context in enumerate(graph.contexts()):
641-
logging.debug("contexts[%s].identifier = %s", context_index, context.identifier)
641+
# logging.debug("contexts[%s].identifier = %s", context_index, context.identifier)
642642
if context.identifier != default_context.identifier:
643643
return True
644644
if context_index > 0:
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"quad_count": 6,
3-
"exact_match": true
2+
"quad_count": 6
43
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exact_match": true
3+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"quad_count": 10,
3-
"exact_match": true
2+
"quad_count": 10
43
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exact_match": true
3+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"quad_count": 5,
3-
"exact_match": true
2+
"quad_count": 5
43
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exact_match": true
3+
}

test/data/variants/forward_slash-asserts.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"quad_count": 4,
3-
"exact_match": true,
43
"has_subject_iris": [
54
"http://example.org/kb/individual-a",
65
"http://example.org/kb/individual-b",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exact_match": true
3+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"quad_count": 8,
3-
"exact_match": true
2+
"quad_count": 8
43
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exact_match": true
3+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"quad_count": 4,
3-
"exact_match": true
2+
"quad_count": 4
43
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exact_match": true
3+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"quad_count": 1,
3-
"exact_match": true
2+
"quad_count": 1
43
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exact_match": true
3+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"quad_count": 1,
3-
"exact_match": true
2+
"quad_count": 1
43
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exact_match": true
3+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"quad_count": 7,
3-
"exact_match": true
2+
"quad_count": 7
43
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exact_match": true
3+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"quad_count": 1,
3-
"exact_match": true
2+
"quad_count": 1
43
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exact_match": true
3+
}

test/test_dataset/test_dataset.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# -*- coding: utf-8 -*-
2+
import logging
23
import os
34
import shutil
45
import tempfile
6+
from typing import Optional
7+
from rdflib.term import Identifier, Literal
58
from test.data import context1, likes, pizza, tarek
69

710
import pytest
@@ -10,6 +13,8 @@
1013
from rdflib.graph import DATASET_DEFAULT_GRAPH_ID, Dataset, Graph
1114
from rdflib.namespace import Namespace
1215
from rdflib.store import Store
16+
from test.utils.namespace import EGDC, EGSCHEME, EGURN
17+
from rdflib.namespace import XSD
1318

1419
# Will also run SPARQLUpdateStore tests against local SPARQL1.1 endpoint if
1520
# available. This assumes SPARQL1.1 query/update endpoints running locally at
@@ -265,3 +270,47 @@ def test_subgraph_without_identifier() -> None:
265270
) == ("genid", genid_prefix)
266271

267272
assert f"{subgraph.identifier}".startswith(genid_prefix)
273+
274+
275+
def test_updating_datatype() -> None:
276+
dataset = Dataset()
277+
278+
dataset.add((EGSCHEME.subject, EGSCHEME.predicate, EGSCHEME.object))
279+
280+
egurn_graph = dataset.get_context(EGURN.graph)
281+
egurn_graph.add(
282+
(EGSCHEME.subject, EGDC.predicate, Literal("XSD string", datatype=XSD.string))
283+
)
284+
285+
def find_literal_obj_ctx_id(dataset: Dataset, literal_value: str) -> Optional[Identifier]:
286+
for quad in (quad for quad in dataset.quads((None, None, None, None))):
287+
if isinstance(quad[2], Literal) and quad[2].value == literal_value:
288+
logging.debug("quad = %s", quad)
289+
return quad[3]
290+
return None
291+
292+
assert find_literal_obj_ctx_id(dataset, "XSD string") == EGURN.graph
293+
294+
for context in dataset.contexts():
295+
logging.debug("context.identifier = %s", context.identifier)
296+
for triple in context:
297+
logging.debug("triple = %s", triple)
298+
object = triple[2]
299+
if not isinstance(object, Literal):
300+
continue
301+
if object.datatype is None:
302+
continue
303+
logging.debug("object.datatype = %s", object.datatype)
304+
if object.datatype == XSD.string:
305+
object._datatype = None
306+
307+
assert find_literal_obj_ctx_id(dataset, "XSD string") == EGURN.graph
308+
309+
310+
# found = False
311+
# for quad in (quad for quad in dataset.quads((None, None, None, None))):
312+
# if isinstance(quad[2], Literal) and quad[2].value == "XSD string":
313+
# logging.debug("quad = %s", quad)
314+
# # found = True
315+
# # break
316+
# # assert found is True

0 commit comments

Comments
 (0)