AGSparqlBasicGraphPatterns.java
package com.franz.ag.examples;
import com.franz.ag.*;
public class AGSparqlBasicGraphPatterns {
@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.addStatement("<http://example.org/book/book1>",
"<http://purl.org/dc/elements/1.1/title>",
ts.createLiteral("SPARQL Tutorial"));
String query =
"SELECT ?title " +
"WHERE {" +
"<http://example.org/book/book1> <http://purl.org/dc/elements/1.1/title> ?title ." +
"}";
AGUtils.doSparqlSelect(ts, query);
ts.registerNamespace("foaf", "http://xmlns.com/foaf/0.1/");
BlankNode a = (BlankNode)ts.createBNode("_:a");
BlankNode b = (BlankNode)ts.createBNode("_:b");
BlankNode c = (BlankNode)ts.createBNode("_:c");
ts.addStatement(a,"!foaf:name",ts.createLiteral("Johnny Lee Outlaw"));
ts.addStatement(a,"!foaf:mbox","<mailto:[email protected]>");
ts.addStatement(b,"!foaf:name",ts.createLiteral("Peter Goodguy"));
ts.addStatement(b,"!foaf:mbox","<mailto:[email protected]>");
ts.addStatement(c,"!foaf:mbox","<mailto:[email protected]>");
query =
"PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
"SELECT ?name ?mbox " +
"WHERE " +
" { ?x foaf:name ?name . " +
" ?x foaf:mbox ?mbox }";
AGUtils.doSparqlSelect(ts, query);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next