graphml and list types

929 views
Skip to first unread message

tcb

unread,
Feb 9, 2013, 5:35:46 AM2/9/13
to networkx...@googlegroups.com
Hi,

I have some graphml files which come from graph-tool and they have properties which networkx cannot read. The properties are node positions- a list of floats- and it seems list types are not supported by networkx graphml at all (reading or writing).

This is what I get when I try to write a list type to graphml

G=nx.Graph()
G.add_node(1, pos=[1,2])
nx.write_graphml(G, '/tmp/g.xml')
networkx/readwrite/graphml.py in add_data(self, name, element_type, value, scope, default)
    241         if element_type not in self.xml_type:
    242             raise nx.NetworkXError('GraphML writer does not support '
--> 243                                    '%s as data values.'%element_type)
    244         key_id = self.get_key(name, self.xml_type[element_type], scope, default)
    245         data_element = Element("data", key=key_id)

NetworkXError: GraphML writer does not support <type 'list'> as data values.

And the graphml file I would like read looks something like this:

 <!-- property keys --> 
 <key id="key0" for="node" attr.name="centrality" attr.type="int" /> 
 <key id="key1" for="node" attr.name="pos" attr.type="vector_float" /> 
 <graph id="G" edgedefault="undirected" parse.nodeids="canonical" parse.edgeids="canonical" parse.order="nodesfirst"> 
 <!-- graph properties --> 
 <!-- vertices --> 
 <node id="n0"> <data key="key0">2</data> <data key="key1">0x1.54206f8b25c6cp+3, 0x1.489af2ba23c76p+3</data> </node> 
So the 'pos' attribute is a 2d list of floats with type 'vector_double'.

and when I try to read this I get:

networkx/readwrite/graphml.py in find_graphml_keys(self, graph_element)
    512             graphml_keys[attr_id] = {
    513                 "name":attr_name,
--> 514                 "type":self.python_type[attr_type],
    515                 "for":k.get("for")}
    516             # check for "default" subelement of key element

KeyError: 'vector_float'

graph-tool (http://projects.skewed.de/graph-tool/) seems to read/write only graphml, so the easiest solution for me would be if networkx could read/write these graphml attributes properly. I'm happy to have a look at it myself, but I would appreciate some guidance on what's the best way to go about adding this support.

thanks

-



Aric Hagberg

unread,
Feb 9, 2013, 9:39:55 AM2/9/13
to networkx...@googlegroups.com
I guess the attr.type "vector_float" must be an extension to the
GraphML standard? There must be some schema (listed in your file
header) that describes that. See
http://graphml.graphdrawing.org/primer/graphml-primer.html#EXT for
some info
If you want to add support for that open an issue at the github site
and we can comment there.
Aric

tcb

unread,
Feb 9, 2013, 10:56:24 AM2/9/13
to networkx...@googlegroups.com

no problem:



Aric

--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.
To post to this group, send email to networkx...@googlegroups.com.
Visit this group at http://groups.google.com/group/networkx-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



Reply all
Reply to author
Forward
0 new messages