reading a GML file with networkx (python) without labels for the nodes -
i have long gml file (graph modelling language) trying read networkx in python. in gml file, nodes don't have label, this:
graph [ node [ id 1 ] node [ id 2 ] edge [ source 2 target 1 ] ]
i error when reading file: g = nx.read_gml('simple_graph.gml')
--------------------------------------------------------------------------- networkxerror traceback (most recent call last) <ipython-input-39-b1b319a08668> in <module>() ----> 1 g = nx.read_gml('simple_graph.gml') <decorator-gen-319> in read_gml(path, label, destringizer) /usr/lib/python2.7/dist-packages/networkx/utils/decorators.pyc in _open_file(func, *args, **kwargs) 218 # finally, call original function, making sure close fobj. 219 try: --> 220 result = func(*new_args, **kwargs) 221 finally: 222 if close_fobj: /usr/lib/python2.7/dist-packages/networkx/readwrite/gml.pyc in read_gml(path, label, destringizer) 208 yield line 209 --> 210 g = parse_gml_lines(filter_lines(path), label, destringizer) 211 return g 212 /usr/lib/python2.7/dist-packages/networkx/readwrite/gml.pyc in parse_gml_lines(lines, label, destringizer) 407 raise networkxerror('node id %r duplicated' % (id,)) 408 if label != 'id': --> 409 label = pop_attr(node, 'node', 'label', i) 410 if label in labels: 411 raise networkxerror('node label %r duplicated' % (label,)) /usr/lib/python2.7/dist-packages/networkx/readwrite/gml.pyc in pop_attr(dct, type, attr, i) 397 except keyerror: 398 raise networkxerror( --> 399 "%s #%d has no '%s' attribute" % (type, i, attr)) 400 401 nodes = graph.get('node', []) networkxerror: node #0 has no 'label' attribute
i see complains because nodes don't have labels. documentation of gml thought labels not obligatory (maybe i'm wrong?). there way read such file without labels? or should change gml file? thank help!
if want use id
attribute in gml labeling nodes, can designate label attribute nx.read_gml
argument follows.
g = nx.read_gml('simple_graph.gml', label='id')
Comments
Post a Comment