AGSparqlAsk.java
package com.franz.ag.examples;
import com.franz.ag.*;
public class AGSparqlAsk {
@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 a = (BlankNode)ts.createBNode("_:a");
BlankNode b = (BlankNode)ts.createBNode("_:b");
ts.addStatement(a,"!rdf:type","!foaf:Person");
ts.addStatement(a,"!foaf:name",ts.createLiteral("Alice"));
ts.addStatement(a,"!foaf:mbox","<mailto:[email protected]>");
ts.addStatement(a,"!foaf:mbox","<mailto:[email protected]>");
ts.addStatement(b,"!rdf:type","!foaf:Person");
ts.addStatement(b,"!foaf:name",ts.createLiteral("Bob"));
ts.addStatement(b,"!foaf:homepage","<http://work.example.org/alice/>");
String query =
"PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
"ASK { ?x foaf:name 'Alice' }";
SPARQLQuery sq = new SPARQLQuery();
boolean result = sq.ask(ts, query);
System.out.println("Query: " + query);
System.out.println("Result: " + result);
query =
"PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
"ASK { ?x foaf:name 'Fred' }";
sq = new SPARQLQuery();
result = sq.ask(ts, query);
System.out.println("Query: " + query);
System.out.println("Result: " + result);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next