-
Notifications
You must be signed in to change notification settings - Fork 555
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
Graph parse method overrides prefix bindings #1997
Comments
It is according to my discoveries when working through testing the override/replace interactions and I included an observation on the matter:
which is intended to find its way into the documentation. I have a sense that the domain modelling (of the source as a serialized RDF Graph) is slightly more faithfully represented in the traditional RDFLib invocation idiom: g = Graph().parse(data=source, format=format) There doesn't seem to be any elegant and straightforward way of handling prefix-namespace bindings in a format-independent manner. The turtle parser doesn't use either rdflib/rdflib/plugins/parsers/notation3.py Line 1946 in 05dced2
Also consider: def test_parse_namespace():
data = """
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX ns: <https://example.com/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX schema: <https://schema.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
ns:08429fce-4d70-4be4-9c64-ffc80f554ea7
a skos:Concept .
"""
EX = Namespace("https://example.com/")
graph = Graph()
graph.parse(data=data, format="turtle")
graph.bind("ex", EX)
assert graph.serialize(format="turtle") == (
"@prefix ex: <https://example.com/> .\n"
"@prefix skos: <http://www.w3.org/2004/02/skos/core#> .\n"
"\n"
"ex:08429fce-4d70-4be4-9c64-ffc80f554ea7 a skos:Concept .\n"
"\n"
)
graph2 = Graph()
graph2 += graph # Namespace bindings in graph not preserved
assert graph2.serialize(format="turtle") == (
"\n"
"<https://example.com/08429fce-4d70-4be4-9c64-ffc80f554ea7> a "
"<http://www.w3.org/2004/02/skos/core#Concept> .\n"
"\n"
)
graph2 = Graph()
graph2.bind("xe", EX)
graph2 += graph # Namespace bindings in graph2 preserved
assert graph2.serialize(format="turtle") == (
"@prefix xe: <https://example.com/> .\n"
"\n"
"xe:08429fce-4d70-4be4-9c64-ffc80f554ea7 a "
"<http://www.w3.org/2004/02/skos/core#Concept> .\n"
"\n"
) |
I think your expectaion is reasonable @edmondchuc - but changing this will be a breaking change, so should be targeted for 7.x, see #2108 for some options. |
If I run the following code:
It will print:
I would have expected the bind to persist through the life of the graph object and print the following result:
If I swap the two lines from:
to:
it then prints what I expect.
Is this the expected behaviour where calling the
parse()
method overwrites prefix bindings in the graph's namespace manager?The text was updated successfully, but these errors were encountered: