Mercurial > hg > Members > nobuyasu > TPPageRank
view src/sample/CreateTinkerGraph.java @ 2:1744340f8be6 draft
add some java files
author | one |
---|---|
date | Wed, 05 Sep 2012 11:56:21 +0900 |
parents | 08f01b5c4d4a |
children | dcd59917a2dd |
line wrap: on
line source
package sample; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import com.tinkerpop.blueprints.Direction; import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Graph; import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.impls.tg.TinkerGraph; import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; import com.tinkerpop.blueprints.util.io.graphml.GraphMLReader; import com.tinkerpop.blueprints.util.io.graphml.GraphMLWriter; public class CreateTinkerGraph { public static final String filename = "./resources/tinkerpopDB"; public static void main(String[] args) { try { outputGraph(); readGraph(); } catch (IOException e) { e.printStackTrace(); } } public static void outputGraph() throws IOException { Graph graph = new TinkerGraph(); FileOutputStream out = new FileOutputStream(new File(filename)); Vertex a = graph.addVertex(null); Vertex b = graph.addVertex(null); Vertex c = graph.addVertex(null); Vertex d = graph.addVertex(null); a.setProperty("name", "maro"); b.setProperty("name", "Peter"); c.setProperty("name", "smith"); d.setProperty("name", "black"); Edge e = graph.addEdge(null, a, b, "knows"); Edge e2 = graph.addEdge(null, c, a, "knows"); Edge e3 = graph.addEdge(null, d, b, "knows"); System.out.println(e.getVertex(Direction.OUT).getProperty("name") + "--" + e.getLabel() + "-->" + e.getVertex(Direction.IN).getProperty("name")); for (Edge edge : b.getEdges(Direction.IN, "knows")) { Vertex v =edge.getVertex(Direction.OUT); System.out.println(v.getProperty("name")); } GraphMLWriter.outputGraph(graph, out); } public static void readGraph() throws IOException { Graph graph = new TinkerGraph(); FileInputStream in = new FileInputStream(new File(filename)); GraphMLReader.inputGraph(graph, in); Vertex aa = graph.getVertex("1"); System.out.println("vertex " + aa.getId() + " has name " + aa.getProperty("name")); if (aa.getProperty("aaa") != null) System.out.println(aa.getProperty("aaa")); for(Edge ee : aa.getEdges(Direction.OUT)) { System.out.println(ee); } } }