AGPrologFunctorQ.java
package com.franz.agbase.examples;
import com.franz.agbase.*;
public class AGPrologFunctorQ {
@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("functorq", AGPaths.TRIPLE_STORES);
AGLoadNtriples.loadNTriplesWithTiming(ts, AGPaths.dataSources("kennedy.ntriples"));
AGIndexAllTriples.indexAllTriplesWithTiming(ts);
ts.registerNamespace("ex", "http://example.org/kennedy/");
PrologSelectQuery q = new PrologSelectQuery();
q.setTripleStore(ts);
String pquery = "(q !ex:person1 !ex:has-child ?x)";
q.setVariables(new String[]{"x"});
q.setQuery(pquery);
ValueSetIterator it = q.run();
System.out.println("Results for " + pquery);
AGUtils.showResults(it);
pquery = "(q !ex:person1 !ex:has-child ?x)(q ?x !ex:has-child ?y)";
q.setVariables(new String[]{"y"});
q.setQuery(pquery);
it = q.run();
System.out.println("Results for " + pquery);
AGUtils.showResults(it);
pquery = "(q !ex:person1 !ex:has-child ?x)"
+ "(q ?x !ex:has-child ?y)" + "(q ?y !ex:spouse ?z)";
q.setVariables(new String[]{"y","z"});
q.setQuery(pquery);
it = q.run();
System.out.println("Results for " + pquery);
AGUtils.showResults(it);
pquery = "(q ?x !ex:first-name ?n1)" +
"(q ?x !ex:has-child ?y)" +
"(q ?y !ex:first-name ?n2)" +
"(= ?n1 ?n2)";
q.setVariables(new String[]{"x","y"});
q.setQuery(pquery);
it = q.run();
System.out.println("Results for " + pquery);
AGUtils.showResults(it);
pquery = "(q ?x !ex:alma-mater ?am)" +
"(q ?am !ex:ivy-league !ex:true)" +
"(q ?x !ex:has-child ?y)" +
"(q ?y !ex:alma-mater ?am2)" +
"(q ?am2 !ex:ivy-league !ex:true)";
q.setVariables(new String[]{"x","y"});
q.setQuery(pquery);
it = q.run();
System.out.println("Results for " + pquery);
AGUtils.showResults(it);
pquery = "(q ?x !ex:alma-mater ?am)" +
"(q ?am !ex:ivy-league !ex:true)" +
"(q ?x !ex:has-child ?y)" +
"(q ?y !ex:alma-mater ?am)";
q.setVariables(new String[]{"x","y"});
q.setQuery(pquery);
it = q.run();
System.out.println("Results for " + pquery);
AGUtils.showResults(it);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next