AGSparqlReasoning.java
package com.franz.ag.examples;
import com.franz.ag.*;
public class AGSparqlReasoning {
@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("sparqlreasoning", AGPaths.TRIPLE_STORES);
ts.registerNamespace("ex","http://example.org/");
ts.addStatement("!ex:a","!ex:owned-by","!ex:b");
ts.addStatement("!ex:c","!ex:owns","!ex:d");
ts.addStatement("!ex:jans","!ex:owns","!ex:birra");
ts.addStatement("!ex:owned-by","!owl:inverseOf","!ex:owns");
String query =
"PREFIX ex: <http://example.org/> " +
"SELECT DISTINCT ?x ?y " +
"WHERE { ?x ex:owns ?y }";
AGUtils.doSparqlSelect(false, ts, query);
AGUtils.doSparqlSelect(true, ts, query);
ts.addStatement("!ex:A","!rdfs:subClassOf", "!ex:B");
ts.addStatement("!ex:B","!rdfs:subClassOf", "!ex:C");
ts.addStatement("!ex:a","!rdf:type", "!ex:A");
query =
"PREFIX ex: <http://example.org/> " +
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"SELECT DISTINCT ?y " +
"WHERE { ex:a rdf:type ?y }";
AGUtils.doSparqlSelect(false, ts, query);
AGUtils.doSparqlSelect(true, ts, query);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next