Processing yEd image file in python

I want to get a list of all nodes and some attributes (for example, the name of the label) in the yEd generated graphic file, regardless of where they are located on the chart. It has already been partially considered ( Processing an XML file using networkx in python and How to iterate over a GraphML file using lxml ), but not when you group "nodes in yEd", and I have many groupings inside groupings.

We tried networkx and lxml, but did not get a complete set of results using simple approaches - any suggestions for an elegant way to solve and which library to use non-recursively iterate through the tree, as well as determine the nodes of the group and drill again.

Example:

Example output for a very simple graph using networkx when grouping:

('n0', {})
('n1', {'y': '0.0', 'x': '26.007967509920633', 'label': 'A'})
('n0::n0', {})
('n0::n1', {})

Simple representation of the graph

+7
source share
2 answers

After testing networkx, lxml, and pygraphml, I decided that they would not do the job at all. I use BeautifulSoup and write everything from scratch:

from bs4 import BeautifulSoup

fp = "files/tes.graphml"

with open(fp) as file:
    soup = BeautifulSoup(file, "lxml")

    nodes = soup.findAll("node", {"yfiles.foldertype":""})
    groups = soup.find_all("node", {"yfiles.foldertype":"group"})
    edges = soup.findAll("edge")

Then you will get the following results:

print " --- Groups --- "
for group in groups:
    print group['id']
    print group.find("y:nodelabel").text.strip()

print " --- Nodes --- "
for node in nodes:
    print node['id']
    print node.find("y:nodelabel").text.strip()

That should make you. You can create Group, Node, and Edge objects and use them for some processing.

I can open the source library I'm working on, as it will be used for a greater purpose than just analyzing graphs.

enter image description here

And the conclusion:

 --- Groups --- 
n0 / SimpleApp
 --- Nodes --- 
n0::n0 / main
n0::n1 / say hello
n1 / Exit
 --- Edges --- 
n0::e0 / n0::n0 / n0::n1 / str:username, int:age
e0 / n0::n1 / n1 / None
+1
source

I think you can try this.

This is a Python library which, according to the author ...

, , graphML, yEd.

https://github.com/jamesscottbrown/pyyed

, !

!

0

All Articles