当前位置: 首页>>代码示例>>Python>>正文


Python networkx.read_gexf方法代码示例

本文整理汇总了Python中networkx.read_gexf方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.read_gexf方法的具体用法?Python networkx.read_gexf怎么用?Python networkx.read_gexf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx的用法示例。


在下文中一共展示了networkx.read_gexf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def read_graph(self, subgraph_file=None):
        if subgraph_file is None:
            subraph_file = self.context_graph_file
        logging.info("Writing graph.")
        # write the graph out
        file_format = subgraph_file.split(".")[-1]
        if file_format == "graphml":
            return nx.read_graphml(subgraph_file)
        elif file_format == "gml":
            return nx.read_gml(subgraph_file)
        elif file_format == "gexf":
            return nx.read_gexf(subgraph_file)
        elif file_format == "net":
            return nx.read_pajek(subgraph_file)
        elif file_format == "yaml":
            return nx.read_yaml(subgraph_file)
        elif file_format == "gpickle":
            return nx.read_gpickle(subgraph_file)
        else:
            logging.warning("File format not found, returning empty graph.")
        return nx.MultiDiGraph() 
开发者ID:vz-risk,项目名称:Verum,代码行数:23,代码来源:networkx.py

示例2: test_directed_edge_in_undirected

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def test_directed_edge_in_undirected(self):
        s="""<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.1draft" version="1.1">
    <graph mode="static" defaultedgetype="undirected">
        <nodes>
            <node id="0" label="Hello" />
            <node id="1" label="Word" />
        </nodes>
        <edges>
            <edge id="0" source="0" target="1" type="directed"/>
        </edges>
    </graph>
</gexf>
"""
        fh = io.BytesIO(s.encode('UTF-8'))
        assert_raises(nx.NetworkXError,nx.read_gexf,fh) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:18,代码来源:test_gexf.py

示例3: test_key_error

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def test_key_error(self):
        s="""<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.1draft" version="1.1">
    <graph mode="static" defaultedgetype="directed">
        <nodes>
            <node id="0" label="Hello">
              <attvalues>
                <attvalue for='0' value='1'/>
              </attvalues>
            </node>
            <node id="1" label="Word" />
        </nodes>
        <edges>
            <edge id="0" source="0" target="1" type="undirected"/>
        </edges>
    </graph>
</gexf>
"""
        fh = io.BytesIO(s.encode('UTF-8'))
        assert_raises(nx.NetworkXError,nx.read_gexf,fh) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:22,代码来源:test_gexf.py

示例4: test_relabel

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def test_relabel(self):
        s="""<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.1draft" version="1.1">
    <graph mode="static" defaultedgetype="directed">
        <nodes>
            <node id="0" label="Hello" />
            <node id="1" label="Word" />
        </nodes>
        <edges>
            <edge id="0" source="0" target="1"/>
        </edges>
    </graph>
</gexf>
"""
        fh = io.BytesIO(s.encode('UTF-8'))
        G=nx.read_gexf(fh,relabel=True)
        assert_equal(sorted(G.nodes()),["Hello","Word"]) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:19,代码来源:test_gexf.py

示例5: test_default_attribute

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def test_default_attribute(self):
        G=nx.Graph()
        G.add_node(1,label='1',color='green')
        G.add_path([0,1,2,3])
        G.add_edge(1,2,foo=3)
        G.graph['node_default']={'color':'yellow'}
        G.graph['edge_default']={'foo':7}
        fh = io.BytesIO()
        nx.write_gexf(G,fh)
        fh.seek(0)
        H=nx.read_gexf(fh,node_type=int)
        assert_equal(sorted(G.nodes()),sorted(H.nodes()))
        assert_equal(
            sorted(sorted(e) for e in G.edges()),
            sorted(sorted(e) for e in H.edges()))
        # Reading a gexf graph always sets mode attribute to either
        # 'static' or 'dynamic'. Remove the mode attribute from the
        # read graph for the sake of comparing remaining attributes.
        del H.graph['mode']
        assert_equal(G.graph,H.graph) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:22,代码来源:test_gexf.py

示例6: test_directed_edge_in_undirected

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def test_directed_edge_in_undirected(self):
        s = """<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.2draft" version='1.2'>
    <graph mode="static" defaultedgetype="undirected" name="">
        <nodes>
            <node id="0" label="Hello" />
            <node id="1" label="Word" />
        </nodes>
        <edges>
            <edge id="0" source="0" target="1" type="directed"/>
        </edges>
    </graph>
</gexf>
"""
        fh = io.BytesIO(s.encode('UTF-8'))
        assert_raises(nx.NetworkXError, nx.read_gexf, fh) 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_gexf.py

示例7: test_key_raises

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def test_key_raises(self):
        s = """<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.2draft" version='1.2'>
    <graph mode="static" defaultedgetype="directed" name="">
        <nodes>
            <node id="0" label="Hello">
              <attvalues>
                <attvalue for='0' value='1'/>
              </attvalues>
            </node>
            <node id="1" label="Word" />
        </nodes>
        <edges>
            <edge id="0" source="0" target="1" type="undirected"/>
        </edges>
    </graph>
</gexf>
"""
        fh = io.BytesIO(s.encode('UTF-8'))
        assert_raises(nx.NetworkXError, nx.read_gexf, fh) 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:test_gexf.py

示例8: test_relabel

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def test_relabel(self):
        s = """<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.2draft" version='1.2'>
    <graph mode="static" defaultedgetype="directed" name="">
        <nodes>
            <node id="0" label="Hello" />
            <node id="1" label="Word" />
        </nodes>
        <edges>
            <edge id="0" source="0" target="1"/>
        </edges>
    </graph>
</gexf>
"""
        fh = io.BytesIO(s.encode('UTF-8'))
        G = nx.read_gexf(fh, relabel=True)
        assert_equal(sorted(G.nodes()), ["Hello", "Word"]) 
开发者ID:holzschu,项目名称:Carnets,代码行数:19,代码来源:test_gexf.py

示例9: test_default_attribute

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def test_default_attribute(self):
        G = nx.Graph()
        G.add_node(1, label='1', color='green')
        nx.add_path(G, [0, 1, 2, 3])
        G.add_edge(1, 2, foo=3)
        G.graph['node_default'] = {'color': 'yellow'}
        G.graph['edge_default'] = {'foo': 7}
        fh = io.BytesIO()
        nx.write_gexf(G, fh)
        fh.seek(0)
        H = nx.read_gexf(fh, node_type=int)
        assert_equal(sorted(G.nodes()), sorted(H.nodes()))
        assert_equal(
            sorted(sorted(e) for e in G.edges()),
            sorted(sorted(e) for e in H.edges()))
        # Reading a gexf graph always sets mode attribute to either
        # 'static' or 'dynamic'. Remove the mode attribute from the
        # read graph for the sake of comparing remaining attributes.
        del H.graph['mode']
        assert_equal(G.graph, H.graph) 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:test_gexf.py

示例10: ReadGraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def ReadGraph(graphName):
    if (graphName.find("gml") >= 0):
        g= nx.read_gml(graphName)
    elif (graphName.find("gexf") >= 0):
        g= nx.read_gexf(graphName)
    elif (graphName.find("graphml") >= 0):
        g=nx.read_graphml(graphName)
    else:
        print "ERROR, could not determine graph format " + graphName
        sys.exit(0)
    return g 
开发者ID:mrvollger,项目名称:SDA,代码行数:13,代码来源:ABPUtils.py

示例11: test_read_simple_directed_graphml

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def test_read_simple_directed_graphml(self):
        G=self.simple_directed_graph
        H=nx.read_gexf(self.simple_directed_fh)
        assert_equal(sorted(G.nodes()),sorted(H.nodes()))
        assert_equal(sorted(G.edges()),sorted(H.edges()))
        assert_equal(sorted(G.edges(data=True)),
                     sorted(H.edges(data=True)))
        self.simple_directed_fh.seek(0) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:10,代码来源:test_gexf.py

示例12: test_write_read_simple_directed_graphml

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def test_write_read_simple_directed_graphml(self):
        G=self.simple_directed_graph
        fh=io.BytesIO()
        nx.write_gexf(G,fh)
        fh.seek(0)
        H=nx.read_gexf(fh)
        assert_equal(sorted(G.nodes()),sorted(H.nodes()))
        assert_equal(sorted(G.edges()),sorted(H.edges()))
        assert_equal(sorted(G.edges(data=True)),
                     sorted(H.edges(data=True)))
        self.simple_directed_fh.seek(0) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:13,代码来源:test_gexf.py

示例13: test_read_simple_undirected_graphml

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def test_read_simple_undirected_graphml(self):
        G=self.simple_undirected_graph
        H=nx.read_gexf(self.simple_undirected_fh)
        assert_equal(sorted(G.nodes()),sorted(H.nodes()))
        assert_equal(
            sorted(sorted(e) for e in G.edges()),
            sorted(sorted(e) for e in H.edges()))
        self.simple_undirected_fh.seek(0) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:10,代码来源:test_gexf.py

示例14: test_read_attribute_graphml

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def test_read_attribute_graphml(self):
        G=self.attribute_graph
        H=nx.read_gexf(self.attribute_fh)
        assert_equal(sorted(G.nodes(True)),sorted(H.nodes(data=True)))
        ge=sorted(G.edges(data=True))
        he=sorted(H.edges(data=True))
        for a,b in zip(ge,he):
            assert_equal(a,b)
        self.attribute_fh.seek(0) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:11,代码来源:test_gexf.py

示例15: test_serialize_ints_to_strings

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gexf [as 别名]
def test_serialize_ints_to_strings(self):
        G=nx.Graph()
        G.add_node(1,id=7,label=77)
        fh = io.BytesIO()
        nx.write_gexf(G,fh)
        fh.seek(0)
        H=nx.read_gexf(fh,node_type=int)
        assert_equal(H.nodes(),[7])
        assert_equal(H.node[7]['label'],'77') 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:11,代码来源:test_gexf.py


注:本文中的networkx.read_gexf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。