AGSparqlConstruct.java
package com.franz.ag.examples;
import com.franz.ag.*;
public class AGSparqlConstruct {
@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("org", "http://example.com/ns#");
BlankNode a = (BlankNode)ts.createBNode("_:a");
BlankNode b = (BlankNode)ts.createBNode("_:b");
ts.addStatement(a,"!org:employeeName",ts.createLiteral("Alice"));
ts.addStatement(a,"!org:employeeId",ts.createLiteral(12345));
ts.addStatement(b,"!org:employeeName",ts.createLiteral("Bob"));
ts.addStatement(b,"!org:employeeId",ts.createLiteral(67890));
String query =
"PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
"PREFIX org: <http://example.com/ns#> " +
"CONSTRUCT { ?x foaf:name ?name } " +
"WHERE { ?x org:employeeName ?name }";
SPARQLQuery sq = new SPARQLQuery();
Cursor cc = sq.construct(ts,query);
AGUtils.showTriples(cc,ts);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next