On 20/05/15 13:39, Wojciech Ciesielski wrote:
Hi again :)

                     String  query ="SELECT ?subject ?predicate ?object
from"+ WybierzGrafComboBox.getSelectedItem().toString() +"\n" +
                                                 "WHERE {\n" +
                                                 "  ?subject ?predicate
?object\n" +
                                                 "}";
                     String service = "http://localhost:3030/test/query";;
                     Query q= QueryFactory.create(query);
                     try(QueryExecution qexec =
QueryExecutionFactory.sparqlService(service, q))
                     {
                         ResultSet rs = qexec.execSelect();
                         for ( ; rs.hasNext() ; )
                         {
                             QuerySolution soln = rs.nextSolution() ;
                             RDFNode s = soln.get("subject");
                             RDFNode p = soln.get("predicate");
                             RDFNode o = soln.get("object");
                             System.out.println(s +" "+ p+ " "+ o);
                         }
                     }

give me good result:

http://www.example.org/exampleDocument#Monica
http://www.example.org/vocabulary#hasSkill
http://www.example.org/vocabulary#Programming
http://www.example.org/exampleDocument#Monica
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
http://www.example.org/vocabulary#Person

But i need print it as all other serialization supported in Jena
I think about brutal metod - write all into file give dot on end (to
make it N-Quads), and then use RDFDataMgr :?
I'm sure there are other methods :?
Please pointing me how to do it


One possibility is to use a CONSTRUCT query which produces a model, then output the model using RDFDataMgr.write(...).

If you want to stick with a SELECT query, then you could do similarly and create a model in code and write the model.

For RDF/XML you'll need a model; for other formats there are stream output variations.

Or you could convert to triples (use RDFNode.asNode; Triple.create) and send the results to a StreamRDF. StreamRDFWriter is one kind of StreamRDF for outputing in various formats (not RDF/XML).

        Andy

Reply via email to