net.fortytwo.ripple.LinkedDataSailUsageExample Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ripple-demo Show documentation
Show all versions of ripple-demo Show documentation
Ripple demo at the command-line
package net.fortytwo.ripple;
import info.aduna.iteration.CloseableIteration;
import net.fortytwo.linkeddata.sail.LinkedDataSail;
import org.openrdf.query.BindingSet;
import org.openrdf.query.QueryEvaluationException;
import org.openrdf.query.impl.EmptyBindingSet;
import org.openrdf.query.parser.ParsedQuery;
import org.openrdf.query.parser.sparql.SPARQLParser;
import org.openrdf.sail.Sail;
import org.openrdf.sail.SailConnection;
import org.openrdf.sail.memory.MemoryStore;
/**
* @author Joshua Shinavier (http://fortytwo.net)
*/
public class LinkedDataSailUsageExample {
public static void main(final String[] args) throws Exception {
Sail baseSail = new MemoryStore();
baseSail.initialize();
LinkedDataSail sail = new LinkedDataSail(baseSail);
sail.initialize();
SailConnection sc = sail.getConnection();
try {
SPARQLParser parser = new SPARQLParser();
String queryStr = "PREFIX foaf: \n" +
"SELECT ?friend ?name WHERE {\n" +
" foaf:knows ?friend .\n" +
" ?friend foaf:name ?name .\n" +
"}";
String baseURI = "http://example.org/";
ParsedQuery query = parser.parseQuery(queryStr, baseURI);
CloseableIteration extends BindingSet, QueryEvaluationException> results
= sc.evaluate(query.getTupleExpr(), query.getDataset(), new EmptyBindingSet(), false);
while (results.hasNext()) {
System.out.println(results.next().getBinding("name"));
}
} finally {
sc.close();
}
sail.shutDown();
baseSail.shutDown();
}
}