AGPrologRules.java
package com.franz.ag.examples;
import com.franz.ag.*;
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);
AGUtils.loadNTriplesWithTiming(ts, AGPaths.dataSources("kennedy.ntriples"));
AGUtils.indexAllTriplesWithTiming(ts);
ts.registerNamespace("ex", "http://example.org/kennedy/");
AGUtils.addPrologRule("(<-- (male ?x) (q ?x !ex:sex !ex:male))", ts);
AGUtils.addPrologRule("(<-- (female ?x) (q ?x !ex:sex !ex:female))", ts);
AGUtils.addPrologRule("(<-- (father ?x ?y) (male ?x) (q ?x !ex:has-child ?y))", ts);
AGUtils.addPrologRule("(<-- (mother ?x ?y) (female ?x) (q ?x !ex:has-child ?y))", ts);
String pquery = "(?x)" + "(q !ex:person1 !ex:has-child ?x)" + "(male ?x)";
AGUtils.doPrologQuery(ts, pquery);
pquery = "(?m ?s)" + "(mother ?m ?s) (male ?s)";
AGUtils.doPrologQuery(ts, pquery);
pquery = "(?f ?d)" + "(father ?f ?d) (female ?d)";
AGUtils.doPrologQuery(ts, pquery);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next