Skip to content

Commit cfa1b62

Browse files
committed
text file to gml code
1 parent bfb26f3 commit cfa1b62

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package pdgs.utils;
8+
9+
import java.io.IOException;
10+
import java.nio.charset.Charset;
11+
import java.nio.file.Files;
12+
import java.nio.file.Paths;
13+
import java.util.List;
14+
import org.graphstream.graph.Graph;
15+
import org.graphstream.graph.Node;
16+
import org.graphstream.stream.file.FileSink;
17+
import org.graphstream.stream.file.FileSinkGML;
18+
19+
/**
20+
*
21+
* @author Anastasis Andronidis <[email protected]>
22+
*/
23+
public class Unused {
24+
25+
private void readFileToGML(Graph graph) throws IOException {
26+
String fileName = "../data/erdos-names.txt";
27+
28+
try {
29+
List<String> lines = Files.readAllLines(Paths.get(fileName),
30+
Charset.defaultCharset());
31+
for (String line : lines) {
32+
String[] a = line.split(" ", 2);
33+
34+
Node n = graph.addNode(a[0]);
35+
n.addAttribute("name", a[1]);
36+
}
37+
} catch (IOException e) {
38+
e.printStackTrace();
39+
}
40+
41+
fileName = "../data/erdos-edges.txt";
42+
43+
try {
44+
List<String> lines = Files.readAllLines(Paths.get(fileName),
45+
Charset.defaultCharset());
46+
for (String line : lines) {
47+
String[] a = line.split(" ");
48+
49+
for (int i = 1; i < a.length; i++) {
50+
graph.addEdge(a[0] + " " + a[i], a[0], a[i]);
51+
}
52+
53+
}
54+
} catch (IOException e) {
55+
e.printStackTrace();
56+
}
57+
58+
graph.display();
59+
60+
FileSink fs = new FileSinkGML();
61+
62+
fs.writeAll(graph, "../data/erdos02.gml");
63+
}
64+
}

0 commit comments

Comments
 (0)