AGPrologDisjunction.java
package com.franz.agbase.examples;
import com.franz.agbase.*;
public class AGPrologDisjunction {
@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("prologdisjunction", AGPaths.TRIPLE_STORES);
AGLoadNtriples.loadNTriplesWithTiming(ts, AGPaths.dataSources("kennedy.ntriples"));
AGIndexAllTriples.indexAllTriplesWithTiming(ts);
ts.registerNamespace("ex", "http://example.org/kennedy/");
ags.addPrologRule("(<-- (ancestor ?x ?y) (q ?x !ex:has-child ?y))");
ags.addPrologRule("(<- (ancestor ?x ?y) (q ?x !ex:has-child ?z) (ancestor ?z ?y))");
PrologSelectQuery q = new PrologSelectQuery();
q.setTripleStore(ts);
String pquery = "(ancestor ?x !ex:person13)";
q.setVariables(new String[]{"x"});
q.setQuery(pquery);
ValueSetIterator it = q.run();
System.out.println("Results for " + pquery);
AGUtils.showResults(it);
ags.addPrologRule("(<-- (descendent ?x ?y) (ancestor ?y ?x))");
pquery = "(descendent ?x !ex:person13)";
q.setVariables(new String[]{"x"});
q.setQuery(pquery);
it = q.run();
System.out.println("Results for " + pquery);
AGUtils.showResults(it);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next