1

Pythonのnetworkxライブラリが有効なGEXFファイルとして生成するこのコードを指定してください。ドキュメント内で、xmlns:ns0を代わりにxmlns:viz...GEXF準拠の名前空間に変更した場所が見つかりません。

<?xml version="1.0" encoding="utf-8"?><gexf xmlns:ns0="http://www.gexf.net/1.1draft/viz"     
version="1.1" xmlns="http://www.gexf.net/1.1draft" xmlns:viz="http://www.gexf.net/1.1draft/viz"    
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance">

  <graph defaultedgetype="directed" mode="static">
<attributes class="node" mode="static">
  <attribute id="0" title="origin" type="double" />
  <attribute id="1" title="size" type="integer" />
</attributes>
<nodes>
  <node id="0" label="Vijana Amani Pamoja (VAP)">
    <ns0:color b="70" g="11" r="160" />
    <ns0:size value="10" />
    <attvalues>
      <attvalue for="0" value="1.25" />
      <attvalue for="1" value="10" />
    </attvalues>
  </node>

networkxのwrite_gexf関数のデフォルトの名前空間のVIZ部分をどこかでオーバーライドした可能性がありますが、どこでオーバーライドしたかもわかりません。そのため、ここで質問します。

networkx.write_gexf(G,f) # G is the graph and f is the file to write.

(編集済み):GEXFドキュメントに示されているように、ノードはns0:...と言いますがviz:...とは言いません。これにより、vizパラメーターを使用する(そしてそれらを見つけることができない)他のGEXFライブラリーとの互換性の問題が発生します。

4

1 に答える 1

0

同じ問題が発生し、gexf.pyのクラスGEXFWriterの「add_viz」関数を次のように更新しました。

 def add_viz(self,element,node_data):
    viz=node_data.pop('viz',False)
    if viz:
        color=viz.get('color')
        if color is not None:
            e=Element("viz:color")
            e.attrib['r']=str(color.get('r'))
            e.attrib['g']=str(color.get('g'))
            e.attrib['b']=str(color.get('b'))
            if self.VERSION!='1.1':
                e.attrib['a']=str(color.get('a'))
            e.text=" "
            element.append(e)
        size=viz.get('size')
        if size is not None:
            e=Element("viz:size")
            e.attrib['value']=str(size)
            e.text=" "
            element.append(e)

        thickness=viz.get('thickness')
        if thickness is not None:
            e=Element("viz:thickness")
            e.attrib['value']=str(thickness)
            e.text=" "
            element.append(e)

        shape=viz.get('shape')
        if shape is not None:
            if shape.startswith('http'):
                e=Element("viz:shape")
                e.attrib['value']= 'image'
                e.attrib['uri']= str(shape)
            else:
                e=Element("viz:shape")
                e.attrib['value']= str(shape)
            e.text=" "
            element.append(e)

        position=viz.get('position')
        if position is not None:
            e=Element("viz:position")
            e.attrib['x']= str(position.get('x'))
            e.attrib['y']= str(position.get('y'))
            e.attrib['z']= str(position.get('z'))
            e.text=" "
            element.append(e)
    return node_data

これにより、使用しているGEXFライブラリ/ツールとの互換性の問題が解決しました。

ベスト、ZP

于 2015-02-12T11:08:32.307 に答える