



 Learning Center Documentation Updates • Info FAQ

| AGPrologRules.javapackage 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);
AGLoadNtriples.loadNTriplesWithTiming(ts, AGPaths.dataSources("kennedy.ntriples"));
AGIndexAllTriples.indexAllTriplesWithTiming(ts);
ts.registerNamespace("ex", "http://example.org/kennedy/");
addPrologRule("(<-- (male ?x) (q ?x !ex:sex !ex:male))", ags);
addPrologRule("(<-- (female ?x) (q ?x !ex:sex !ex:female))", ags);
addPrologRule("(<-- (father ?x ?y) (male ?x) (q ?x !ex:has-child ?y))", ags);
addPrologRule("(<-- (mother ?x ?y) (female ?x) (q ?x !ex:has-child ?y))", ags);
String pquery = "(?x)" + "(q !ex:person1 !ex:has-child ?x)" + "(male ?x)";
AGPrologSelect.doPrologSelect(ts, pquery);
pquery = "(?m ?s)" + "(mother ?m ?s) (male ?s)";
AGPrologSelect.doPrologSelect(ts, pquery);
pquery = "(?f ?d)" + "(father ?f ?d) (female ?d)";
AGPrologSelect.doPrologSelect(ts, pquery);
ts.closeTripleStore();
ags.disable();
}
public static void addPrologRule(String string, AllegroGraphConnection ags) throws AllegroGraphException {
AGEvalInServer.evalInServer("(enable-!-reader)",ags);
AGEvalInServer.evalInServer(string,ags);
}
}
Up |
Next
© 2008 Franz Inc - Privacy Statement
[ Consulting Services
| Franz
| TopQuadrant
| Racer Systems
]
|