#import pydot import re #graph = pydot.graph_from_dot_file("out/014_dg_0_11100.dot") #for edge in graph: #dir(edge) HYPERGRAPH = { 213: ([], ['Butadien']), } with open('014_dg_0_11100.dot', 'r') as file: graph = file.read() #print(re.findall( "// id = [0-9]+\\{ ('Butadien' |'p_\\{0,[0-9]\\} ){1,2}\\}, 'r_\\{[0|1]\\}', \\{ ('Butadien' |'p_\\{0,[0-9]\\} ){1,2}\\}", graph)[0]) for edge in re.findall("// id = [0-9]+\\{ [A-Za-z0-9_,{} ']+ \\}, 'r_\\{[0|1]\\}', \\{ [A-Za-z0-9_,{} ']+ \\}", graph): #print(edge) index = int(re.findall("(?<=id = )(.*?)(?=\\{)", edge)[0]) educts = re.findall("(?<=\\{)(.*?)(?=\\}, 'r_\\{[0-1]\\}',)", edge)[0] educt = re.findall("(?<= ')(.*?)(?=' )", educts) products = re.findall("(?<='r_\\{[0-1]\\}', \\{)(.*?)(?=\\ })", edge)[0] product = re.findall("(?<= ')(.*?)(?=')", products) if product == educt: continue HYPERGRAPH[index] = (educt, product) for outflow in re.findall("// id = [0-9]+, graphName = [A-Za-z0-9_,\\{\\} ']+", graph): index = int(re.findall("(?<=id = )(.*?)(?=,)", outflow)[0]) mol = re.findall("(?<=graphName = )Butadien|p_\\{0,[0-9]+\\}", outflow)[0] HYPERGRAPH[index] = ([f'{mol}'], []) HYPERGRAPH = dict(sorted(HYPERGRAPH.items())) with open('hypergraph.txt', 'w') as f: f.write("HYPERGRAPH = {\n") for edge, (head, tail) in HYPERGRAPH.items(): f.write(f'\t {edge}: ({head}, {tail}),\n') f.write('}') f.close