AGSparqlUnions.java
package com.franz.ag.examples;
import com.franz.ag.*;
public class AGSparqlUnions {
@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("dc10", "http://purl.org/dc/elements/1.0/");
ts.registerNamespace("dc11", "http://purl.org/dc/elements/1.1/");
BlankNode a = (BlankNode)ts.createBNode("_:a");
BlankNode b = (BlankNode)ts.createBNode("_:b");
BlankNode c = (BlankNode)ts.createBNode("_:c");
ts.addStatement(a,"!dc10:title",ts.createLiteral("SPARQL Query Language Tutorial"));
ts.addStatement(a,"!dc10:creator",ts.createLiteral("Alice"));
ts.addStatement(b,"!dc11:title",ts.createLiteral("SPARQL Protocol Tutorial"));
ts.addStatement(b,"!dc11:creator",ts.createLiteral("Bob"));
ts.addStatement(c,"!dc10:title",ts.createLiteral("SPARQL"));
ts.addStatement(c,"!dc11:title",ts.createLiteral("SPARQL (Updated)"));
String query =
"PREFIX dc10: <http://purl.org/dc/elements/1.0/> " +
"PREFIX dc11: <http://purl.org/dc/elements/1.1/> " +
"SELECT ?title " +
"WHERE { { ?book dc10:title ?title } UNION { ?book dc11:title ?title } }";
AGUtils.doSparqlSelect(ts, query);
query =
"PREFIX dc10: <http://purl.org/dc/elements/1.0/> " +
"PREFIX dc11: <http://purl.org/dc/elements/1.1/> " +
"SELECT ?title ?author " +
"WHERE { { ?book dc10:title ?title . ?book dc10:creator ?author } " +
"UNION " +
"{ ?book dc11:title ?title . ?book dc11:creator ?author } " +
"}";
AGUtils.doSparqlSelect(ts, query);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next