Search in sources :

Example 1 with Gremlin

use of org.apache.tinkerpop.gremlin.util.Gremlin in project graph by krlawrence.

the class RouteSearch method main.

// Run some tests
public static void main(String[] args) {
    // If you want to check your Gremlin version, uncomment the next line
    // System.out.println("Gremlin version is: " + Gremlin.version());
    RouteSearch rs = new RouteSearch();
    boolean loaded = rs.loadGraph("air-routes.graphml");
    if (loaded) {
        boolean done = false;
        while (!done) {
            System.out.println("\nEnter from and to airport codes, eg DFW");
            Console console = System.console();
            System.out.print("From : ");
            String from = console.readLine().toUpperCase();
            System.out.print("To   : ");
            String to = console.readLine().toUpperCase();
            System.out.print("Maximum number of routes to look for : ");
            int max = Integer.parseInt(console.readLine());
            System.out.print("Maximum number of stops : ");
            int stops = Integer.parseInt(console.readLine());
            List<Path> list;
            list = rs.findRoutes(from, to, max, stops);
            if (list == null) {
                System.out.println("\nPlease enter valid airport codes");
            } else if (list.isEmpty()) {
                System.out.println("\nSorry, no routes were found, try more stops");
            } else {
                list.forEach((v) -> System.out.println(v));
            }
            System.out.print("\nAnother search (Y/N)? : ");
            String again = console.readLine().trim().toUpperCase();
            if (again.equals("N")) {
                done = true;
            }
        }
    }
}
Also used : Path(org.apache.tinkerpop.gremlin.process.traversal.Path) org.apache.tinkerpop.gremlin.process.traversal(org.apache.tinkerpop.gremlin.process.traversal) Set(java.util.Set) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) IOException(java.io.IOException) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) T(org.apache.tinkerpop.gremlin.structure.T) IoCore(org.apache.tinkerpop.gremlin.structure.io.IoCore) Gremlin(org.apache.tinkerpop.gremlin.util.Gremlin) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) org.apache.tinkerpop.gremlin.tinkergraph.structure(org.apache.tinkerpop.gremlin.tinkergraph.structure) Console(java.io.Console) Path(org.apache.tinkerpop.gremlin.process.traversal.Path) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Console(java.io.Console)

Aggregations

Console (java.io.Console)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 org.apache.tinkerpop.gremlin.process.traversal (org.apache.tinkerpop.gremlin.process.traversal)1 Path (org.apache.tinkerpop.gremlin.process.traversal.Path)1 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)1 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__)1 Edge (org.apache.tinkerpop.gremlin.structure.Edge)1 T (org.apache.tinkerpop.gremlin.structure.T)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1 IoCore (org.apache.tinkerpop.gremlin.structure.io.IoCore)1 org.apache.tinkerpop.gremlin.tinkergraph.structure (org.apache.tinkerpop.gremlin.tinkergraph.structure)1 Gremlin (org.apache.tinkerpop.gremlin.util.Gremlin)1