Networkx parse gml writing unusable gml files

江枫思渺然 提交于 2020-01-05 07:48:12

问题


I've been trying to parse in some additional attributes to a networkx gml for use later on, and I've run into an issue.

When given a gml file from Cytoscape, networkx outputs a gml file that it itself can't read.

I.e. Cytoscape -> Into networkx -> Output -> Into networkx -> Error:

pyparsing.ParseException: Expected "]" (at char 1116756), (line:71732, col:3)

Now that error requests an additional ] after the nodes (AKA making the graph ignore the edges), if you do this, the graph works. However, it no longer has any edges.

To fully test this I did the 'Cytoscape -> Into networkx -> Output' without changing the code at all, just:

DG = nx.read_gml("KeggComplete.gml", relabel = True)
nx.write_gml(DG, "KeggCompleteEng.gml")
exit()

and then read in with:

BasicGraph = nx.read_gml("KeggCompleteEng.gml", relabel = True)

And the error is still reproducible. So I assume it's to do with how networkx is writing gml files.

The two files I'm using are:

  • Original from Cytoscape
  • Networkx output

If someone could give some insight into why this might be happening it would be most appreciated!


回答1:


This is a bug in NetworkX when generating nested attributes (edge graphics data in this case). An extra set of quotes was incorrectly added to the "Line" attribute.

The fix has been merged as part of this pull request: https://github.com/networkx/networkx/pull/981




回答2:


Pyparsing is not the smartest library when it comes to identifying when parsing errors occur. More recent versions of the library do support some better error identification, but they require some updates to the parsers to get this information.

Without seeing the parser, from your description, it sounds like the parser expects to see something like:

[
  [
  bunch of nodes...
  ]
  [
  optional bunch of edges...
  ]
]

What happens is that it successfully gets past the "bunch of nodes...", then finds some syntax problem in one of the edges in the "optional bunch of edges..." part. Since this is optional, things would still be valid if only there was a closing ']' after the nodes. That's why you get that pyparsing exception message. But the real problem is that one of the edges has a typo.

To diagnose this, try giving the parser just the first few edges. Then keep adding more and more edges until you get the pyparsing error - the most recently added edges contain the critical syntax error.



来源:https://stackoverflow.com/questions/19352960/networkx-parse-gml-writing-unusable-gml-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!