-
Hi, I have an iterator over statements:
And I would like to get back a string that contains the Ntriple representation of the statement st. Can someone help me out? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Iterator<Statement> statements = ...;
StringWriter sw = new StringWriter();
RDFWriter writer = Rio.createWriter(RDFFormat.NTRIPLES, sw);
writer.startRDF();
statements.forEachRemaining(writer::handleStatement);
writer.endRDF();
String ntriples = sw.toString(); This would give you a string with all the statements from the iterator. If you must have a string per statement, you would probably need to create a writer per statement then. Iterator<Statement> statements = ...;
while (statements.hasNext()) {
StringWriter sw = new StringWriter();
RDFWriter writer = Rio.createWriter(RDFFormat.NTRIPLES, sw);
writer.startRDF();
writer.handleStatement(statements.next());
writer.endRDF();
String ntriple = sw.toString();
} |
Beta Was this translation helpful? Give feedback.
-
Excellent answer from @frensjan FWIW, there is also a |
Beta Was this translation helpful? Give feedback.
This would give you a string with all the statements from the iterator. If you must have a string per statement, you would probably need to create a writer per statement then.