Is there a way to get Jena's RdfDataMgr write() to maintain types of literals.
Here's my code which inserts a triple with a typed literal, and them dumps the TURTLE:
String insertQuery = "prefix XMLSchema:<http://www.w3.org/2001/XMLSchema#> " +
"INSERT DATA " +
" { GRAPH <http://name> { " +
" <#book1> <#name> \"Name\"^^XMLSchema:string " +
" } } ";
org.apache.jena.query.Dataset ds = DatasetFactory.createTxnMem();
ds.begin(ReadWrite.WRITE);
try {
UpdateAction.parseExecute(insertQuery, ds);
} finally { ds.commit(); ds.end() ; }
ByteArrayOutputStream stream = new ByteArrayOutputStream();
RDFDataMgr.write(stream, ds.getNamedModel("http://name"), RDFFormat.TURTLE_PRETTY);
String str = stream.toString();
System.out.println(str);
This prints:
<file:///C:/Users/200001934/workspace-current/sparqlgraph/semTK/sparqlGraphLibrary/#book1>
<file:///C:/Users/200001934/workspace-current/sparqlgraph/semTK/sparqlGraphLibrary/#name>
"Name" .
But I'm looking for Turtle with the type of "Name" preserved. Something like:
<file:///C:/Users/200001934/workspace-current/sparqlgraph/semTK/sparqlGraphLibrary/#book1>
<file:///C:/Users/200001934/workspace-current/sparqlgraph/semTK/sparqlGraphLibrary/#name>
"Name"^^<http://www.w3.org/2001/XMLSchema#string> .
Is there a different RDFFormat, or a setting in RDFDataMgr, or am I missing a more fundamental concept?
In RDF 1.1 "abc"
is exactly the same RDF literal as "abc"^^xsd:string
. They are two ways of writing the same RDFTerm. The without-^^ form is preferred, as mentioned in the RDF 1.1 spec. This is true in SPARQL as well - the ^^XMLSchema:string
is unnecessary.