trig export of multiple graphs assigns wrong prefixes to prefixedNames #679
Closed
Description
It seems, that trig export does not handle prefixes and named graphs very well (or at all). Trying to export a dataset with multiple graphs overwrites already assigned prefixes, produces different prefix assignments, wrong graph prefixes or prefixNames on different runs.
Testcase:
from rdflib import URIRef, Literal, Graph, Dataset
def trig_export_test():
graphs = [(URIRef("urn:tg1"),"A"), (URIRef("urn:tg2"), "B")]
ds = Dataset()
for i, n in graphs:
g = Graph(identifier=i)
a = URIRef("urn:{}#S".format(n))
b = URIRef("urn:{}#p".format(n))
c = Literal(chr(0xf23f1))
d = Literal(chr(0x66))
e = Literal(chr(0x23f2))
g.add((a,b,c))
g.add((a,b,d))
g.add((a,b,e))
ds.graph(g)
for n,k in [ ("json-ld","jsonld"),
("nquads", "nq"), ("trix", "trix"), ("trig", "trig")]:
ds.serialize("ds.{}".format(k), format=n)
trig_export_test()
Can produce the following
@prefix ns1: <urn:> .
@prefix ns2: <urn:B#> .
@prefix pns1: <urn:x-rdflib:> .
@prefix pns2: <urn:A#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
pns1:tg2 {
pns2:S pns2:p "f",
"⏲",
"" .
}
pns1:tg1 {
pns2:S pns2:p "f",
"⏲",
"" .
}
{}
or
@prefix ns1: <urn:x-rdflib:> .
@prefix ns2: <urn:A#> .
@prefix pns1: <urn:> .
@prefix pns2: <urn:B#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
{}
pns1:tg1 {
pns2:S pns2:p "f",
"⏲",
"" .
}
pns1:tg2 {
pns2:S pns2:p "f",
"⏲",
"" .
}
both are created with the same function