On 20/05/15 20:26, Wojciech Ciesielski wrote:
W dniu 2015-05-20 o 19:10, Andy Seaborne pisze:
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
I dont know how to bulid CONSTRUCT query, and how use it :(
CONSTRUCT WHERE { ?subject ?predicate ?object }
which is the short hand for
CONSTRUCT { ?subject ?predicate ?object }
WHERE { ?subject ?predicate ?object }
and then qexec.execConstruct()
I try do Model:
Model test=ModelFactory.createDefaultModel();
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");
Resource S = test.createResource(
s.toString() );
// Cope with blank nodes
Resource S = soln.getResource("subject") ;
// p must be a URI
Property P = test.createProperty(p.getString()) ;
Property P = test.createProperty(
p.toString() );
test.add(S,P,o);
}
test.write(System.out,"N-Triples");
}
and i think it work for N-Triples and Turtle, but RDF/XML give me:
Exception in thread "AWT-EventQueue-0"
com.hp.hpl.jena.shared.BadURIException: Only well-formed absolute
URIrefs can be included in RDF/XML output:
<5b58f023ed2cb06f12f4b9e0c5147e98> Code: 57/REQUIRED_COMPONENT_MISSING
in SCHEME: A component that is required by the scheme is missing.
That looks like a blank node. s.toString() is not a URI in that case.
But what do with other serialization and named graph ?
My app must print Default graph and all other graph storage in Fuseki +
I need to handle with CRUD operation from app level.
Sory but my knowledge about RDF and Jena is realy poor ...