Python networkx.read_gexf() Examples
The following are 30
code examples of networkx.read_gexf().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
networkx
, or try the search function
.
Example #1
Source File: test_gexf.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 6 votes |
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"])
Example #2
Source File: test_gexf.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
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"])
Example #3
Source File: test_gexf.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #4
Source File: test_gexf.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #5
Source File: test_gexf.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #6
Source File: test_gexf.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 6 votes |
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)
Example #7
Source File: test_gexf.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 6 votes |
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)
Example #8
Source File: test_gexf.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 6 votes |
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)
Example #9
Source File: test_gexf.py From aws-kube-codesuite with Apache License 2.0 | 6 votes |
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)
Example #10
Source File: test_gexf.py From aws-kube-codesuite with Apache License 2.0 | 6 votes |
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)
Example #11
Source File: test_gexf.py From aws-kube-codesuite with Apache License 2.0 | 6 votes |
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"])
Example #12
Source File: test_gexf.py From aws-kube-codesuite with Apache License 2.0 | 6 votes |
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)
Example #13
Source File: test_gexf.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
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)
Example #14
Source File: test_gexf.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #15
Source File: test_gexf.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
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)
Example #16
Source File: test_gexf.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
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)
Example #17
Source File: test_gexf.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
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)
Example #18
Source File: test_gexf.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_bool(self): G = nx.Graph() G.add_node(1, testattr=True) fh = io.BytesIO() nx.write_gexf(G, fh) fh.seek(0) H = nx.read_gexf(fh, node_type=int) assert_equal(H.nodes[1]['testattr'], True)
Example #19
Source File: test_gexf.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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(list(H), [7]) assert_equal(H.nodes[7]['label'], '77')
Example #20
Source File: test_gexf.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
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(list(H), [7]) assert_equal(H.nodes[7]['label'], '77')
Example #21
Source File: test_gexf.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_bool(self): G = nx.Graph() G.add_node(1, testattr=True) fh = io.BytesIO() nx.write_gexf(G, fh) fh.seek(0) H = nx.read_gexf(fh, node_type=int) assert_equal(H.nodes[1]['testattr'], True)
Example #22
Source File: test_gexf.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #23
Source File: test_gexf.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #24
Source File: test_gexf.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #25
Source File: test_gexf.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
def test_bool(self): G=nx.Graph() G.add_node(1, testattr=True) fh = io.BytesIO() nx.write_gexf(G,fh) fh.seek(0) H=nx.read_gexf(fh,node_type=int) assert_equal(H.node[1]['testattr'], True)
Example #26
Source File: test_gexf.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
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')
Example #27
Source File: test_gexf.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
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)
Example #28
Source File: test_gexf.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
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)
Example #29
Source File: test_gexf.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
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)
Example #30
Source File: test_gexf.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
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)