Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python中的networkx库对Graphml文件中的节点属性进行一致排序_Python_Python 3.x_Networkx_Graphml - Fatal编程技术网

使用Python中的networkx库对Graphml文件中的节点属性进行一致排序

使用Python中的networkx库对Graphml文件中的节点属性进行一致排序,python,python-3.x,networkx,graphml,Python,Python 3.x,Networkx,Graphml,我正在使用networkx库创建图形,并将该图形存储为graphml文件(使用networkx库的write_graphml函数) 在我的图中,每个节点有8个不同的属性,边有一个属性。(属性总数=9) 问题是,每次我运行代码并生成graphml文件时。Graphml文件结构具有不同的节点属性顺序 例如,在第一次运行中 <key attr.name="key" attr.type="long" for="edge" id="d8" /> <key attr.name="lemma

我正在使用networkx库创建图形,并将该图形存储为graphml文件(使用networkx库的write_graphml函数)

在我的图中,每个节点有8个不同的属性,边有一个属性。(属性总数=9)

问题是,每次我运行代码并生成graphml文件时。Graphml文件结构具有不同的节点属性顺序

例如,在第一次运行中

<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">

在第二次运行时

<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">

正如我们所看到的,在第一次运行代码时,我得到了节点属性“position”的id=“d0”,在第二次运行代码时,我得到了节点属性“word”的id=“d0”


我们能以任何方式使节点属性的顺序保持一致吗

当使用
read\u graphml
加载图形时,graphml文件中属性的顺序应该不重要。也就是说,由于节点和边属性存储在字典中(没有顺序),因此两个graphml文件的图形应该相同。是否将其设置为全局,以便任何人都可以使用任何其他库(networkx除外)加载并获得一致的输出。当使用
read\u graphml
加载图形时,graphml文件中属性的顺序应该不重要。也就是说,您应该为两个graphml文件获得相同的图形,因为节点和边属性存储在字典中(没有顺序)。要使其全局化,以便任何人都可以使用任何其他库(networkx除外)加载并获得一致的输出。