AGPrologRules.java
package com.franz.agbase.examples;
import com.franz.agbase.*;
public class AGPrologRules {
@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("prologrules", AGPaths.TRIPLE_STORES);
AGLoadNtriples.loadNTriplesWithTiming(ts, AGPaths.dataSources("kennedy.ntriples"));
AGIndexAllTriples.indexAllTriplesWithTiming(ts);
ts.registerNamespace("ex", "http://example.org/kennedy/");
String[] rules = new String[4];
rules[0] = "(<-- (male ?x) (q ?x !ex:sex !ex:male))";
rules[1] = "(<-- (female ?x) (q ?x !ex:sex !ex:female))";
rules[2] = "(<-- (father ?x ?y) (male ?x) (q ?x !ex:has-child ?y))";
rules[3] = "(<-- (mother ?x ?y) (female ?x) (q ?x !ex:has-child ?y))";
ags.addPrologRules(rules);
PrologSelectQuery q = new PrologSelectQuery();
q.setTripleStore(ts);
q.setIncludeInferred(false);
String pquery = "(q !ex:person1 !ex:has-child ?x)" + "(male ?x)";
q.setVariables(new String[]{"x"});
q.setQuery(pquery);
ValueSetIterator it = q.run();
System.out.println("Results for " + pquery);
AGUtils.showResults(it);
pquery = "(mother ?m ?s) (male ?s)";
q.setVariables(new String[]{"m","s"});
q.setQuery(pquery);
it = q.run();
System.out.println("Results for " + pquery);
AGUtils.showResults(it);
pquery = "(father ?f ?d) (female ?d)";
q.setVariables(new String[]{"f","d"});
q.setQuery(pquery);
it = q.run();
System.out.println("Results for " + pquery);
AGUtils.showResults(it);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next