There are two ways to use RDQL : from the command line and in Java programs.
The main class is jena.rdfquery:
java -cp ... jena.rdfquery [--data modelFile] [--query File | queryString]
With no arguments, it prints a usage message.
Example code fragment 1 (basic template)
Query query = new Query(queryString) ; // Need to set the source if the query does not. // This provided this override any query named source. query.setSource(model); QueryExecution qe = new QueryEngine(query) ; QueryResults results = qe.exec() ; for ( Iterator iter = results ; iter.hasNext() ; ) { ResultBinding rbind = (ResultBinding)iter.next() ; // Return from get is null if not found Object obj = rbind.get("x") ; // obj will be a Jena object: resource, property or RDFNode. } results.close() ;
The ResultBinding class allows an alternative form which can be used to get quoted strings:
Value v = rbind.getValue("x") ; String s = (v == null) ? "<null>" : v.asQuotedString() ;
Example code fragment 2 (using the results formatter)
Query query = new Query(queryString) ; query.setSource(model); QueryExecution qe = new QueryEngine(query) ; QueryResults results = qe.exec() ; QueryResultsFormatter fmt = new QueryResultsFormatter(results) ; PrintWriter pw = new PrintWriter(System.out) ; fmt.printAll(pw, " | ") ; pw.flush() ; fmt.close() ; results.close() ;
The command line usage is a wrapper around the Java interface.