AGSNAPaths.java
package com.franz.ag.examples;
import com.franz.ag.*;
public class AGSNAPaths {
@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("snapaths", AGPaths.TRIPLE_STORES);
ts.registerNamespace("ex", "http://example.org/");
AGUtils.loadNTriplesWithTiming(ts, AGPaths.dataSources("sna-doublediamond.nt"));
SNAExtension sna = ts.getSNAExtension();
Object[] parts = new Object[2];
parts[0] = "objects-of";
parts[1] = "!ex:to";
sna.registerGenerator("to", parts);
UPI[] bfsPath = sna.breadthFirstSearch("!ex:a", "!ex:h", "to", 0);
AGUtils.printUPIArray("BFS path: ", ts, bfsPath);
UPI[][] bfsPaths = sna.allBreadthFirstSearchPaths("!ex:a", "!ex:h", "to", 0);
System.out.println("There are " + bfsPaths.length + " bfs paths");
UPI[] dfsPath = sna.depthFirstSearch("!ex:a", "!ex:h", "to", 0);
AGUtils.printUPIArray("DFS path: ", ts, dfsPath);
UPI[][] dfsPaths = sna.allDepthFirstSearchPaths("!ex:a", "!ex:h", "to", 0);
System.out.println("There are " + dfsPaths.length + " dfs paths");
UPI[] bdsPath = sna.bidirectionalSearch("!ex:a", "!ex:h", "to", 0);
AGUtils.printUPIArray("BDS path: ", ts, bdsPath);
UPI[][] bdsPaths = sna.allBidirectionalSearchPaths("!ex:a", "!ex:h", "to", 0);
System.out.println("There are " + bdsPaths.length + " bds paths");
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next