2

I'm saving a TTL file using RDFWriter. How can I explicitly save literals with their data type?

For example, I want "5.36289"^^xsd:float but I get 5.36289E0 instead.

I had the same problem with strings, but I found the BasicWriterSettings.XSD_STRING_TO_PLAIN_LITERAL property that solved. I cannot find any similar configuration for other data types.

I am creating the literals using the method Values.literal.

This is the source code:

FileOutputStream out = new FileOutputStream(ttlOutputFile);
RDFWriter writer = Rio.createWriter(RDFFormat.TURTLE, out);

final WriterConfig config = writer.getWriterConfig();
config.set(BasicWriterSettings.XSD_STRING_TO_PLAIN_LITERAL, false);

writer.startRDF();

for (Statement st : model) {
    writer.handleStatement(st);
}
writer.endRDF();
  • As [per the spec](https://www.w3.org/TR/turtle/#abbrev), this is simply an abbreviated syntax, and parsing will include the datatype. Why do you want to avoid this syntax? – Joe Jan 04 '22 at 11:31
  • 1
    The problem arises because I need to load that dataset on a Python tool (that probably does not use a standard library) and it gives me an error if I inject a TTL with the extended syntax. – Alessio Palmero Aprosio Jan 04 '22 at 15:07

1 Answers1

3

There is a configuration setting called ABBREVIATE_NUMBERS that works like a charm (and it needs to be used only when PRETTY_PRINT is true, which is the default value).

final WriterConfig config = writer.getWriterConfig();
config.set(BasicWriterSettings.PRETTY_PRINT, true);
config.set(BasicWriterSettings.XSD_STRING_TO_PLAIN_LITERAL, false);
config.set(TurtleWriterSettings.ABBREVIATE_NUMBERS, false);