Mercurial > repos > bernhardlutz > graphconverter
comparison convert_graph.py @ 3:b7cdfd11614a draft default tip
Uploaded
| author | bernhardlutz |
|---|---|
| date | Tue, 04 Mar 2014 16:50:32 -0500 |
| parents | 89b606a49225 |
| children |
comparison
equal
deleted
inserted
replaced
| 2:89b606a49225 | 3:b7cdfd11614a |
|---|---|
| 20 | 20 |
| 21 #completely supported types by networkx | 21 #completely supported types by networkx |
| 22 completely_supported_types = ["gml", "gexf", "yaml", "graphml", "pajek"] | 22 completely_supported_types = ["gml", "gexf", "yaml", "graphml", "pajek"] |
| 23 | 23 |
| 24 def read_gspan(infile): | 24 def read_gspan(infile): |
| 25 G = nx.Graph() | 25 G = nx.DiGraph() |
| 26 idoffset=0 | 26 idoffset=0 |
| 27 old_id_start=0 | 27 old_id_start=0 |
| 28 for line in infile: | 28 for line in infile: |
| 29 line_split=line.split(" ") | 29 line_split=line.split(" ") |
| 30 length_split=len(line_split) | 30 length_split=len(line_split) |
| 75 outfile.write("e "+str(node_dict[e[0]])+" "+str(node_dict[e[1]])) | 75 outfile.write("e "+str(node_dict[e[0]])+" "+str(node_dict[e[1]])) |
| 76 | 76 |
| 77 id_count+=1 | 77 id_count+=1 |
| 78 def read_json(file): | 78 def read_json(file): |
| 79 json_string=file.read() | 79 json_string=file.read() |
| 80 print(json_string) | 80 #print(json_string) |
| 81 json_dict=json.loads(json_string) | 81 json_dict=json_graph.loads(json_string) |
| 82 print(json_dict) | 82 #print(json_dict) |
| 83 return nx.Graph() | 83 #return json_graph.node_link_graph(json_dict, True, False) |
| 84 | 84 return json_dict |
| 85 | |
| 85 def write_json(graph, outfile): | 86 def write_json(graph, outfile): |
| 86 json_dict=json_graph.node_link_data(graph) | 87 json_dict=json_graph.node_link_data(graph) |
| 87 json_string=json.dumbs(json_dict) | 88 json_string=json_graph.dumps(json_dict) |
| 88 outfile.write(json_string) | 89 outfile.write(json_string) |
| 89 print("did it") | 90 #print("did it") |
| 90 | 91 |
| 91 def main( args ): | 92 def main( args ): |
| 92 | 93 |
| 93 if args.informat not in graph_types: | 94 if args.informat not in graph_types: |
| 94 print "EXCEPTION COMPUTER EXPLODING" | 95 print "EXCEPTION COMPUTER EXPLODING" |
