rdf4j
rdf4j copied to clipboard
Turtle writer does not respect namespaces in IRIs
Current Behavior
The turtle writer does not consider the namespace provided by an IRI. Instead, it turns the IRI into a string and then tries to derive a namespace from that string and then looks up that namespace in the namespace table.
Expected Behavior
If the IRI defines a namespace, that should first be used to look up the prefix in the namespace table. Interpreting the IRI as a string should only be a fallback.
Steps To Reproduce
@Test
public void testIriNamespace() throws Exception {
Model model = new DynamicModelFactory().createEmptyModel();
String prefix = "foo-bar";
String ns = "foo:this.is.my.bar.";
model.setNamespace(prefix, ns);
model.add(vf.createIRI(ns, "lala"), vf.createIRI(ns, "lulu"), vf.createIRI(ns, "lolo"));
StringWriter stringWriter = new StringWriter();
Rio.write(model, stringWriter, RDFFormat.TURTLE);
assertThat(stringWriter.toString()).contains("foo-bar:lala foo-bar:lulu foo-bar:lolo .");
}
Version
4.3.9
Are you interested in contributing a solution yourself?
Yes
Anything else?
No response