How to generate a graphml file in Java. Gephi, JGraph, Prefuse, etc
Asked Answered
L

6

8

Help! I'm looking to create a Java application that generates a graph in any one of these formats:

  • .graphml
  • .ygf
  • .gml
  • .tgf

I need to be able to open the file in the graph editor "yEd".

So far, I have found these solutions:

  1. yFiles For Java
    • Pro: Export to graphml, able to open in yEd, Java based, perfect.
    • Why I can't use it: Would cost me more than $2000 to use :( it is exactly what I need however
  2. Gephi
    • Pro: FREE, Export to graphml, Java based!
    • Why I can't use it: When I try to open the generated graphml file in yEd, the graphml is broken: it's linear - one line, like this screenshot:
    • enter image description here
    • If I get it to work, then this is perfect
    • The graph I tried was generated using their example project
  3. JGraphX
    • Pro: Able to generate a graph, Java based, FREE
    • Why I can't use it: How to export the generated graph to graphml? I couldn't figure it out...
  4. Prefuse
    • Pro: Free, graph generation, Java based
    • What I can't use it: Seems like I can only read graphml, and not write graphml. Also, I built the demos fine with build.sh all, but then when I tried to run demos.jar, I got "Failed to load Main-Class"...
  5. Blueprints with GraphML Reader and Writer Library (Tinkerpop?)
    • Pro: Java, Free, seems like you can export graphml with it
    • Why I can't use it: I'm confused, do I need to use this in conjunction with one of the "Implementations" listed? How do I use this?
  6. JGraphT with GraphMLExporter
    • Pro: Able to generate graph, Java based, free, can export to graphml I think
    • Why I can't use it: I can't figure out how to export it! When I tried to open the generated graphml in yed, I got "yEd has encountered the following error: Could not import file test.graphml." I used thier example project, and did this:

JGraphT Code I Used:

UndirectedGraph<String, DefaultEdge> g = new SimpleGraph<String, DefaultEdge>(DefaultEdge.class);

String v1 = "v1";
String v2 = "v2";
String v3 = "v3";
String v4 = "v4";

// add the vertices
g.addVertex(v1);
g.addVertex(v2);
g.addVertex(v3);
g.addVertex(v4);

// add edges to create a circuit
g.addEdge(v1, v2);
g.addEdge(v2, v3);
g.addEdge(v3, v4);
g.addEdge(v4, v1);


FileWriter w;
try {
GmlExporter<String, DefaultEdge> exporter = 
    new GmlExporter<String, DefaultEdge>(); 
    w = new FileWriter("test.graphml");
    exporter.export(w, g);
} catch (IOException e) {
    e.printStackTrace();
}

Any ideas? Thanks!

Lodger answered 28/4, 2014 at 19:17 Comment(2)
Have you found a solution? I trying to find a Java library where I can create graphs then I export to graphml.Bearberry
It should work with JgraphT with the code sketch in the question, it just needs some improvements. For examples and hints: github.com/Systemdir/GML-Writer-for-yED daniel-ebert.github.io/jgrapht-graph-exporting-examplesBriolette
B
3

I also wanted to export JgraphT graphs for yED but was not happy with the results. Therefore, I created an extended GMLWriter supporting yED's specific GML format (groups, colours, different edges,...).

GML-Writer-for-yED

Banian answered 18/1, 2017 at 11:20 Comment(0)
T
8

It might be late to answer, but for solution number two: Right after you import the graph into yEd, just click "Layout" and select one. yed will not choose one for you as default, that's why it seemed to be linear.

Typewrite answered 26/2, 2015 at 10:48 Comment(0)
B
3

I also wanted to export JgraphT graphs for yED but was not happy with the results. Therefore, I created an extended GMLWriter supporting yED's specific GML format (groups, colours, different edges,...).

GML-Writer-for-yED

Banian answered 18/1, 2017 at 11:20 Comment(0)
C
2

I don't know if this fits your use case, but I use neo4j for creating a graph and then use the neo4j-shell-tools to export the graph as graphml. Perhaps this will work for you.

Christianize answered 29/4, 2014 at 7:23 Comment(1)
Not sure Gephi's GraphML export is broken: as a member involved in the Gephi community I have seen no report on that. So I just tried exporting a network from Gephi in the GraphML format, then opening this GraphML file into NodeXL (another GraphML reader by the way!), and the network displayed fine. Maybe that something is wrong with yED importer then?Sheugh
H
2

Just replace every occurrence of GmlExporter with GraphMLExporter in your code. That should work.

Haskins answered 8/12, 2014 at 21:53 Comment(0)
D
1

I´m using de Prefuse library and you can generate a GraphML file from a Graph object with de class GraphMLWriter.

Danette answered 9/12, 2016 at 3:0 Comment(0)
B
0

I created a little Tutorial/Github Repo and sample code on how to work with the classes of JgraphT to export to GraphML and GML and how the results could look like in yED.

As already mentioned in another answer, if you don't want to do much configuration yourself, GML-Writer-for-yED might be handy.

Briolette answered 30/4, 2022 at 17:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.