1

I'm creating graph using networkx library and also storing that graph as graphml file (using write_graphml function of networkx library).

In my graph, each node have 8 different attribute and edge have one attribute. (Total no of attributes = 9)

Problem is, each time I run code and generate graphml file. Graphml file structure have different ordering of node attributes.

For example, in first run,

<key attr.name="key" attr.type="long" for="edge" id="d8" />
<key attr.name="lemma" attr.type="string" for="node" id="d7" />
<key attr.name="cng" attr.type="long" for="node" id="d6" />
<key attr.name="chunk_no" attr.type="long" for="node" id="d5" />
<key attr.name="pre_verb" attr.type="string" for="node" id="d4" />
<key attr.name="length_word" attr.type="long" for="node" id="d3" />
<key attr.name="morph" attr.type="string" for="node" id="d2" />
<key attr.name="word" attr.type="string" for="node" id="d1" />
<key attr.name="position" attr.type="long" for="node" id="d0" />
<graph edgedefault="directed">

On second Run,

<key attr.name="key" attr.type="long" for="edge" id="d8" />
<key attr.name="length_word" attr.type="long" for="node" id="d7" />
<key attr.name="chunk_no" attr.type="long" for="node" id="d6" />
<key attr.name="cng" attr.type="long" for="node" id="d5" />
<key attr.name="position" attr.type="long" for="node" id="d4" />
<key attr.name="pre_verb" attr.type="string" for="node" id="d3" />
<key attr.name="lemma" attr.type="string" for="node" id="d2" />
<key attr.name="morph" attr.type="string" for="node" id="d1" />
<key attr.name="word" attr.type="string" for="node" id="d0" />
<graph edgedefault="directed">

As we can see, In first run of code I got id="d0" for node attribute "position" and for second run I got id="d0" for node attribute "word".

Can we make ordering of node attribute consistent in any way ?

  • The ordering of attributes in the graphml file should not be important when loading the graph with `read_graphml`. That is, you should get the same graph for both graphml files since node and edge attributes are stored in a dictionary (which is not ordered). – edo Jan 14 '17 at 13:55
  • Want to make it global so that anyone can use any other library(other than networkx) to load and get consistent output. – Bhumi Faldu Jan 15 '17 at 11:15

0 Answers0