SLRPDevelopmentFAQ

From IBM Semantic Layered Research Platform

Revision as of 20:09, 16 January 2007; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

Boca

Q: How can I create a transaction that spans operations on multiple named graphs?

A: The transaction begin/commit is one per !DatasetService. The begin/commit call on the model itself is a convenience method for compatibility with the Jena API. It's probably better to call:

 datasetService.getTransactionQueueHandler().begin(); 
 model1.add(statement1); 
 model2.add(statement2); 
 datasetService.getTransactionQueueHandler().commit(); 

(If you choose to call begin and commit directly on a Model object, it does not matter which model you use.)


Q: How can I get the boolean results of a SPARQL ASK query?

A: Here is some example code to run a query and get the boolean result.

 String query = "ASK WHERE { ?s ?p ?o }";
 Graph results = datasetService.getModelService().execQuery(
     Collections.singleton("http://test.ibm.com/test#namedGraph1"), 
     Collections.EMPTY_SET, 
     query, 
     Syntax.syntaxSPARQL.getSymbol()
 );
 Model resultsModel = ModelFactory.createModelForGraph(results);
 StmtIterator stmtIter = resultsModel.listStatements(null, ResultSetVocab.p_boolean, (RDFNode)null);
 boolean queryAnswer = stmtIter.nextStatement().getBoolean();
 // ...work with queryAnswer...

(The graphs which result from an ASK query are guaranteed to always contain a single triple.)