AGSparqlFiltersInOptionals.java
package com.franz.ag.examples;
import com.franz.ag.*;
public class AGSparqlFiltersInOptionals {
@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("dc", "http://purl.org/dc/elements/1.1/");
ts.registerNamespace("b", "http://example.org/book/");
ts.registerNamespace("ns", "http://example.org/ns#");
ts.addStatement("!b:book1","!dc:title",ts.createLiteral("SPARQL Tutorial"));
ts.addStatement("!b:book1","!ns:price",ts.createLiteral(42));
ts.addStatement("!b:book2","!dc:title",ts.createLiteral("The Semantic Web"));
ts.addStatement("!b:book2","!ns:price",ts.createLiteral(23));
String query =
"PREFIX dc: <http://purl.org/dc/elements/1.1/> " +
"PREFIX ns: <http://example.org/ns#> " +
"SELECT ?title ?price " +
"WHERE { ?x dc:title ?title . " +
"OPTIONAL { ?x ns:price ?price . FILTER (?price < 30) } " +
"}";
AGUtils.doSparqlSelect(ts, query);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next