On 2013-09-12 01:54, Andy Seaborne wrote:
On 12/09/13 08:38, Claude Warren wrote:
something like
protected void writeRDFStatements( Model model, PrintWriter writer )
{
Set<Resource> subjects = new TreeSet<Resource>();
subjects.addAll( model.listSubjects().asSet() );
Iterator<Resource> rIter = subjects.iterator()
while (rIter.hasNext()) writeRDFStatements( model, rIter.nex(),
writer );
}
Might do the trick, assuming that you want the statements in
"natural"
order and that you don't have so many as to overflow memory.
If you want a different order you could implement a comparator and
pass it
to the TreeSet constructor.
Claude
Yes - if you care about specific order then you can't reply on
listStatement or Graph.find (even, in theory, across different calls
to to same operation). Internally, there are hash tables, and any
format that involves pretty-printing is reordering the triples. For
example, Turtle (pretty form or in blocks) is a
by-subject-then-by-predicate sort).
Diving into the output internals ... and dropping to the triple level
...
There are low level utility operations
RDFDataMgr.writeTriples or .writeQuads
that writes an iterator in N-Triples or N-Quads format but a little
better is "flat Turtle".
http://jena.apache.org/documentation/io/rdf-output.html#line-printed-formats
which is produced by streaming the triples into the object obtained by
StreamRDFLib.writer
for writing a StreamRDF (which is primarily the output of a parser
but it is a sink of triple, quads, prefixes and base declarations).
Andy
Hi Andy,
This is very informative as I wasn't even aware that Jena document
covers
the I/O separately. BTW, what're the package names for these
StreamRDFLib
and RDFDataMgr ? I tried to find them in the Jena JavaDoc, but no luck.
Thanks
Chan