AGSparqlDistinct.java
package com.franz.ag.examples;
import com.franz.ag.*;
public class AGSparqlDistinct {
@param
@throws
public static void main(String[] args) throws AllegroGraphException {
AllegroGraphConnection ags = new AllegroGraphConnection();
try {
ags.enable();
} catch (Exception e) {
throw new AllegroGraphException("Server connection problem", e);
}
AllegroGraph ts = ags.renew("sparql", AGPaths.TRIPLE_STORES);
ts.registerNamespace("foaf", "http://xmlns.com/foaf/0.1/");
BlankNode x = (BlankNode)ts.createBNode("_:x");
BlankNode y = (BlankNode)ts.createBNode("_:y");
BlankNode z = (BlankNode)ts.createBNode("_:z");
ts.addStatement(x,"!foaf:name",ts.createLiteral("Alice"));
ts.addStatement(x,"!foaf:mbox","<mailto:[email protected]>");
ts.addStatement(y,"!foaf:name",ts.createLiteral("Alice"));
ts.addStatement(y,"!foaf:mbox","<mailto:[email protected]>");
ts.addStatement(z,"!foaf:name",ts.createLiteral("Alice"));
ts.addStatement(z,"!foaf:mbox","<mailto:[email protected]>");
String query =
"PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
"SELECT ?name WHERE { ?x foaf:name ?name } ";
AGUtils.doSparqlSelect(ts, query);
query =
"PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
"SELECT DISTINCT ?name WHERE { ?x foaf:name ?name } ";
AGUtils.doSparqlSelect(ts, query);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next