creating a graph out of text

Pippo adm2303.2304 at gmail.com
Tue Apr 14 15:13:59 CEST 2015


Hi,

I am not sure why my code doesn't show the graph. It clearly creates the right nodes and edges but it doesn't show them. Any idea?

mport re 
from Tkinter import * 
import tkFileDialog 
import testpattern 
import networkx as nx 
import matplotlib.pyplot as plt 

patternresult =[] 
nodes = {} 
edges = {} 

pattern = ['(#P\[\w*\])', '(#C\[\w*[\s\(\w\,\s\|\)]+\])', 
           '(#ST\[\w*[\s\(\w\,\s\|\)]+\])', '(#A\[\w*[\s\(\w\,\s\|\)]+\])'] 


patternresult = testpattern.patternfinder() 

G=nx.Graph() 


for patres in patternresult: 
    G.add_node(patres) 
    if patres[1] == "P": 
        first_node = patres 
    

for patres in patternresult: 
    
    if patres[1:3] == "ST": 
        G.add_edge(first_node, patres, label="Sub-type") 
    elif patres[1:2] == "C": 
        G.add_edge(first_node, patres, label="Constraint_by") 
    elif patres[1:3] == "A": 
        G.add_edge(first_node, patres, label="Created_by") 
    
#graph = G.edge() 
pos = nx.shell_layout(G) 
#nx.draw(G, pos) 


nx.draw_networkx_nodes(G, pos, nodelist=None, 
                       node_size=300, node_color='r', 
                       node_shape='o', alpha=1.0, 
                       cmap=None, vmin=None, vmax=None, 
                       ax=None, linewidths=None) 
nx.draw_networkx_edges(G, pos, edgelist=None, width=1.0, edge_color='k', 
                       style='solid',alpha=None, edge_cmap=None, 
                       edge_vmin=None, edge_vmax=None,ax=None, arrows=True) 
nx.draw_networkx_labels(G, pos,font_size=10, font_family='sans-serif') 

plt.show() 

#plt.savefig("path.png") 

I think the problem starts from nx.draw....

This is what I want to create graph for:
#C[Health]
#P[Information]
#ST[genetic information]
#C[oral | (recorded in (any form | medium))]
#C[Is created or received by]
#A[health care provider | health plan | public health authority | employer | life insurer | school | university | or health care clearinghouse]
#C[Relates to]
#C[the past, present, or future physical | mental health | condition of an individual]
#C[the provision of health care to an individual]
#C[the past, present, or future payment for the provision of health care to an individual]

This also shows all of the edges that are created...

{'#C[the past, present, or future payment for the provision of health care to an individual]': 1, '#A[health care provider | health plan | public health authority | employer | life insurer | school | university | or health care clearinghouse]': 0, '#C[Relates to]': 1, '#C[the past, present, or future physical | mental health | condition of an individual]': 1, '#C[Is created or received by]': 1, '#C[the provision of health care to an individual]': 1, '#C[Health]': 1, '#C[oral | (recorded in (any form | medium))]': 1, '#ST[genetic information]': 1, '#P[Information]': 8}



More information about the Python-list mailing list