11
|
1 package sample;
|
|
2
|
|
3 import java.io.File;
|
|
4 import java.io.FileInputStream;
|
|
5
|
|
6 import pagerank.LinkToVertex;
|
|
7
|
|
8 import com.tinkerpop.blueprints.Graph;
|
|
9 import com.tinkerpop.blueprints.Vertex;
|
|
10 import com.tinkerpop.blueprints.impls.tg.TinkerGraph;
|
|
11 import com.tinkerpop.blueprints.util.io.graphml.GraphMLReader;
|
|
12 import com.tinkerpop.gremlin.java.GremlinPipeline;
|
|
13 import com.tinkerpop.pipes.util.iterators.SingleIterator;
|
|
14
|
|
15 public class GremlinSample {
|
|
16
|
|
17 public static void main(String[] args) {
|
|
18
|
|
19 final String fileDB = "./resources/tinkerpopDB";
|
|
20
|
|
21
|
|
22 try {
|
|
23 Graph graph = new TinkerGraph();
|
|
24 FileInputStream in = new FileInputStream(new File(fileDB));
|
|
25 GraphMLReader.inputGraph(graph, in);
|
|
26 in.close();
|
|
27 LinkToVertex ltv = new LinkToVertex(graph);
|
|
28
|
|
29 String id = "21";
|
|
30 GremlinPipeline pipe = new GremlinPipeline();
|
|
31 pipe.start(graph.getVertex(id)).out("HasLink").property("pageTitle");
|
|
32 pipe.setStarts(new SingleIterator<Vertex>(graph.getVertex(id)));
|
|
33 for (Object title : pipe) {
|
|
34 System.out.println((String)title);
|
|
35 }
|
|
36
|
|
37
|
|
38 } catch (NumberFormatException e){
|
|
39 System.out.println("Program exit");
|
|
40 } catch (Exception e) {
|
|
41 e.printStackTrace();
|
|
42 } finally {
|
|
43
|
|
44 }
|
|
45
|
|
46 }
|
|
47
|
|
48 }
|