1

RDF4J 新手问题 -

当我从文件加载这个 RDF 时:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

<foaf:Person>
 <foaf:name>My Name</foaf:name>
</foaf:Person>

</rdf:RDF>

使用此代码

String fileName = "foaf.rdf";
try {
    InputStream is = new FileInputStream(fileName);
    Model model = Rio.parse(is, "", RDFFormat.RDFXML);
    System.out.println();
    Rio.write(model, System.out, RDFFormat.RDFXML);
    System.out.println();
    is.close();
}
catch (Exception ex) {
    System.out.println(ex.toString());
}

输出如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

<rdf:Description rdf:nodeID="node1basf0r6vx1">
    <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
    <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">My Name</foaf:name>
</rdf:Description>

</rdf:RDF>

我将如何以原始格式打印 RDF?

4

1 回答 1

2

RDF4J 还有一个漂亮的打印功能。也许这可以帮助你的输出。

你只需要创建一个 writer,然后将 pretty print 设置为 true。

Rio.createWriter(format, outputStream).set(BasicWriterSettings.PRETTY_PRINT, true)
于 2017-03-22T07:41:23.173 回答