AGFederationSparqlReasoning.java
package com.franz.ag.examples;
import com.franz.ag.*;
public class AGFederationSparqlReasoning {
@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);
}
ags.registerNamespace("ex", "http://example.org/");
AllegroGraph ts1 = ags.renew("ontology", AGPaths.TRIPLE_STORES);
AllegroGraph ts2 = ags.renew("facts", AGPaths.TRIPLE_STORES);
AllegroGraph[] parts = {ts1,ts2};
AllegroGraph fed = ags.federate("federation", parts, true);
ts1.addStatement("!ex:SmallBlackDog","!rdfs:subClassOf","!ex:BlackDog");
ts1.addStatement("!ex:BlackDog","!rdfs:subClassOf","!ex:Dog");
ts1.addStatement("!ex:Dog","!rdfs:subClassOf","!ex:Mammal");
ts1.addStatement("!ex:Giraffe","!rdfs:subClassOf","!ex:Mammal");
ts1.addStatement("!ex:Lion","!rdfs:subClassOf","!ex:Mammal");
ts1.addStatement("!ex:Mammal","!rdfs:subClassOf","!ex:Animal");
ts1.addStatement("!ex:Abbey","!rdf:type","!ex:BlackDog");
String query =
"PREFIX ex: <http://example.org/>"
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
+ "SELECT ?class "
+ "WHERE { "
+ " ex:Abbey rdf:type ?class . "
+ "}";
AGUtils.doSparqlSelect(false, fed, query);
AGUtils.doSparqlSelect(true, fed, query);
fed.closeTripleStore();
ts1.closeTripleStore();
ts2.closeTripleStore();
ags.disable();
}
}
Up |
Next