有没有办法让耶拿的RdfDataMgr write()维护文字类型。
这是我的代码,其中插入带类型文字的三元组,然后转储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);
此打印:
<file:///C:/Users/200001934/workspace-current/sparqlgraph/semTK/sparqlGraphLibrary/#book1>
<file:///C:/Users/200001934/workspace-current/sparqlgraph/semTK/sparqlGraphLibrary/#name>
"Name" .
但是我正在寻找保留类型为[[“ Name”的Turtle。类似于:
<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> .
是否存在其他RDFFormat,或RDFDataMgr中的设置,或者我缺少更基本的概念?
"abc"
与"abc"^^xsd:string
完全相同。它们是编写同一RDFTerm的两种方法。如RDF 1.1规范中所述,不带^^形式是首选。在SPARQL中也是如此-不需要^^XMLSchema:string
。