Procházet zdrojové kódy

Reading and Displaying Sample Graph from GraphML

Jan Enders před 8 roky
rodič
revize
5e7b6d54e2

+ 11 - 9
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/App.java

@@ -1,7 +1,8 @@
 package de.tu_darmstadt.informatik.tk.scopviz;
 
-import com.tinkerpop.blueprints.impls.tg.*;
-import com.tinkerpop.blueprints.*;
+import java.io.IOException;
+
+import org.graphstream.graph.*;
 
 /**
  * Hello world!
@@ -11,13 +12,14 @@ public class App {
 
 	public static void main(String[] args) {
 		
-		Graph graph = new TinkerGraph();
-		Vertex a = graph.addVertex(null);
-		Vertex b = graph.addVertex(null);
-		a.setProperty("name", "marko");
-		b.setProperty("name", "peter");
-		Edge e = graph.addEdge(null, a, b, "knows");
-		System.out.println(e.getVertex(Direction.OUT).getProperty("name") + "--" + e.getLabel() + "-->" + e.getVertex(Direction.IN).getProperty("name"));
+		GraphMLImporter importer = new GraphMLImporter();
+		try {
+			Graph g = importer.readGraph("src/main/resources/TestGraphML.txt");
+			g.display();
+		} catch (IOException e) {
+			System.err.println("Error while reading or displaying test GraphML file!");
+			e.printStackTrace();
+		}
 		System.out.println("Hello World!");
 	}
 }

+ 1 - 7
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/GraphMLImporter.java

@@ -15,13 +15,7 @@ public class GraphMLImporter {
 		FileSource fs = new FileSourceGraphML();
 		fs.addSink(g);
 		fs.readAll(fileName);
-		/*while (fs.nextEvents()) {
-			// Optionally some code here ...
-		}
-		if(fs!=null){
-			//fs.end();
-		}
-		fs.removeSink(g);*/
+		fs.removeSink(g);
 		return g;
 	}
 }

+ 14 - 0
scopviz/src/main/resources/TestGraphML.txt

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
+		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+		xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
+			http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
+		<graph id="g" edgedefault="undirected">
+			<node id="A">
+			</node>
+			<node id="B">
+			</node>
+			<edge id="AB" source="A" target="B">
+			</edge>
+		</graph>
+</graphml>