Export result of sparql into ttl file

I have executed sparql query on stardog and have result in tupleQueryResult , how to export it into ttl file ?

SelectQuery query = connection.select( query_str );
TupleQueryResult tupleQueryResult = query.execute();

I can write it on console with QueryResultIO.writeTuple(tupleQueryResult, TextTableQueryResultWriter.FORMAT, System.out);
guide me how to write it in ttl file, thanks in advance for helping me


Turtle is not a valid format for SPARQL results. You would need to execute a GraphQuery (i.e., CONSTRUCT) in order to export the results as ttl:

GraphQueryResult gqr = connection.graph("construct {?s ?p ?o} where {?s ?p ?o}").execute();
QueryResultIO.writeGraph(gqr, RDFFormat.TURTLE, new FileOutputStream("/path/to/my/file.ttl"));

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.