Mercurial > hg > Members > nobuyasu > TPPageRank
comparison src/sample/CreateTinkerGraph.java @ 4:dcd59917a2dd draft
fix LinkToVertex
author | one |
---|---|
date | Wed, 05 Sep 2012 12:44:08 +0900 |
parents | 1744340f8be6 |
children | 7e38484474f4 |
comparison
equal
deleted
inserted
replaced
3:b44abb9aa09f | 4:dcd59917a2dd |
---|---|
1 package sample; | 1 package sample; |
2 | 2 |
3 import java.io.File; | 3 import java.io.File; |
4 import java.io.FileInputStream; | 4 import java.io.FileInputStream; |
5 import java.io.FileNotFoundException; | |
6 import java.io.FileOutputStream; | 5 import java.io.FileOutputStream; |
7 import java.io.IOException; | 6 import java.io.IOException; |
7 | |
8 import pagerank.LinkToVertex; | |
8 | 9 |
9 import com.tinkerpop.blueprints.Direction; | 10 import com.tinkerpop.blueprints.Direction; |
10 import com.tinkerpop.blueprints.Edge; | 11 import com.tinkerpop.blueprints.Edge; |
11 import com.tinkerpop.blueprints.Graph; | 12 import com.tinkerpop.blueprints.Graph; |
12 import com.tinkerpop.blueprints.Vertex; | 13 import com.tinkerpop.blueprints.Vertex; |
13 import com.tinkerpop.blueprints.impls.tg.TinkerGraph; | 14 import com.tinkerpop.blueprints.impls.tg.TinkerGraph; |
14 import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; | |
15 import com.tinkerpop.blueprints.util.io.graphml.GraphMLReader; | 15 import com.tinkerpop.blueprints.util.io.graphml.GraphMLReader; |
16 import com.tinkerpop.blueprints.util.io.graphml.GraphMLWriter; | 16 import com.tinkerpop.blueprints.util.io.graphml.GraphMLWriter; |
17 | 17 |
18 public class CreateTinkerGraph { | 18 public class CreateTinkerGraph { |
19 | 19 |
20 public static final String filename = "./resources/tinkerpopDB"; | 20 public static final String filename = "./resources/testTinkerpopDB"; |
21 | 21 |
22 public static void main(String[] args) { | 22 public static void main(String[] args) { |
23 | 23 |
24 | |
25 try { | 24 try { |
26 | 25 |
27 outputGraph(); | 26 // outputGraph(); |
28 readGraph(); | 27 // readGraph(); |
29 | 28 readPageRankDB(); |
29 | |
30 } catch (IOException e) { | 30 } catch (IOException e) { |
31 e.printStackTrace(); | 31 e.printStackTrace(); |
32 } | 32 } |
33 | 33 |
34 } | 34 } |
53 + e.getVertex(Direction.IN).getProperty("name")); | 53 + e.getVertex(Direction.IN).getProperty("name")); |
54 for (Edge edge : b.getEdges(Direction.IN, "knows")) { | 54 for (Edge edge : b.getEdges(Direction.IN, "knows")) { |
55 Vertex v =edge.getVertex(Direction.OUT); | 55 Vertex v =edge.getVertex(Direction.OUT); |
56 System.out.println(v.getProperty("name")); | 56 System.out.println(v.getProperty("name")); |
57 } | 57 } |
58 | |
59 | |
60 GraphMLWriter.outputGraph(graph, out); | 58 GraphMLWriter.outputGraph(graph, out); |
61 | |
62 } | 59 } |
63 | 60 |
64 public static void readGraph() throws IOException { | 61 public static void readGraph() throws IOException { |
65 Graph graph = new TinkerGraph(); | 62 Graph graph = new TinkerGraph(); |
66 FileInputStream in = new FileInputStream(new File(filename)); | 63 FileInputStream in = new FileInputStream(new File(filename)); |
74 System.out.println(ee); | 71 System.out.println(ee); |
75 } | 72 } |
76 | 73 |
77 } | 74 } |
78 | 75 |
76 public static void readPageRankDB() throws IOException { | |
77 final String pageRankDB = "./resources/tinkerpopDB"; | |
78 Graph graph = new TinkerGraph(); | |
79 FileInputStream in = new FileInputStream(new File(pageRankDB)); | |
80 GraphMLReader.inputGraph(graph, in); | |
81 | |
82 LinkToVertex ltn = new LinkToVertex(graph); | |
83 | |
84 System.out.println("print All Vertex "); | |
85 for (Vertex v : graph.getVertices() ) { | |
86 if ( (ltn.getPageTitle(v) == null ) || | |
87 (ltn.getPageRank(v) == null)) continue; | |
88 String id = (String) v.getId(); | |
89 int nodeId = Integer.parseInt(id); | |
90 ltn.printVertexInfo(nodeId); | |
91 } | |
92 } | |
79 | 93 |
80 } | 94 } |