Namespace prefix is serialized to "ns1" despite binding it. #1609
-
Hi, sorry to bother and to double-post (this here), but the more I think about it, the less I think it's intended behaviour: In the following minimal test case: from rdflib import Graph, Namespace, Literal, RDF
base = "http://test.com/ns"
foobar = Namespace("http://test.com/ns#")
g = Graph(base=base)
g.bind('foobar', foobar)
g.add((foobar.something, RDF.type, Literal('Blah')))
g.add((foobar.something, foobar.contains, Literal('a property')))
g.add((foobar.anotherthing, RDF.type, Literal('Blubb')))
g.add((foobar.anotherthing, foobar.contains, Literal('another property')))
print(g.serialize(format='turtle').decode("utf-8")) I get @base <http://test.com/ns> .
@prefix foobar: <http://test.com/ns#> .
<#anotherthing> a "Blubb" ;
ns1:contains "another property" .
ns1:something a "Blah" ;
ns1:contains "a property" . what I'd expecte is more like @base <http://test.com/ns> .
@prefix foobar: <http://test.com/ns#> .
<#anotherthing> a "Blubb" ;
foobar:contains "another property" .
<#something> a "Blah" ;
foobar:contains "a property" . So either there is something I fundamentally don't understand about RDFLib and how to use namespaces, or there's something funky going on. If you could tell me what I'm doing wrong, I'd be very grateful! But also, this might be an indication that the documentation on that part is not 100% clear. :) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I think I found the issue: If I remove the base, it turns out correct. If I don't bind the namespace, it adds it as Is this behaviour intended? If so, it should be documented. |
Beta Was this translation helpful? Give feedback.
-
As per the answer to the same question in Stack Overflow: you need to complete the URI in the base declaration by adding the final There probably could be better handing of this in RDFlib but it's an extreme edge case predicated on incorrect declarations of a base that match a prefix, so I'm tempted to close the issue as I don't think anyone's likely to address it. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your reply, the final @base <something#> .
@prefix foobar: <something#> .
<ting> a <thing-class> ;
<contains> "Literal Property" . So the In that sense, there is certainly some room for improvement... But I full well understand if that's not something that's getting addressed. It is an edge case after all. |
Beta Was this translation helpful? Give feedback.
As per the answer to the same question in Stack Overflow: you need to complete the URI in the base declaration by adding the final
#
, or just don't use a base at all. As it is, thebase
is indeed clashing with the declared prefix.There probably could be better handing of this in RDFlib but it's an extreme edge case predicated on incorrect declarations of a base that match a prefix, so I'm tempted to close the issue as I don't think anyone's likely to address it.