Closed amedury closed 6 years ago
@amedury there's a bug in networkx 2.1. To calculate centrality on a line graph, use either nx 2.0 or the unreleased release candidate of 2.2. Will be formally resolved whenever nx 2.2 is released. See also https://github.com/gboeing/osmnx-examples/issues/6
I'm running 2.2 and I am getting the error code NetworkXNotImplemented: not implemented for undirected type when I attempt to run centrality on a directed graph I generated from the from_pandas_edgelist function.
What is the type(G)
of the graph G you're passing in to the line_graph function?
networkx.classes.graph.Graph I generated it from
def picturefeeder(text,function):
keywords = []
sentences = [x + '.' for x in text.replace('?','.').replace('!','.').split('.')]
for n in [*range(0,len(sentences)-1)]:
# Build your graph
G=nx.from_pandas_edgelist(spacyfunction(sentences[n]),source='textnum',target='parentnum')
comm = pd.DataFrame(function(G))
centraldata = pd.merge(pd.DataFrame(comm.mean()),spacyfunction(sentences[n]), left_index=True,right_on='textnum')
bestnoun = centraldata[centraldata['pos'].isin(['NOUN','PRON'])].sort_values(0,ascending=False).head(1)
#keywords.append([*bestnoun['text']])
#keywordsa.append([*bestnoun['textnum']])
childnodes = centraldata[centraldata['parentnum'] == [*bestnoun['textnum']][0]]
childnodes = childnodes[childnodes['pos'] != 'PUNCT'][childnodes['pos'] != 'ADP']
feeder = pd.concat([childnodes,bestnoun])
#keywords.append([[*bestnoun['text']],[*centraldata[centraldata['parentnum'] == [*bestnoun['textnum']][0]]['text']]])
keywords.append(' '.join([*feeder.sort_index()['text']]))
keywords = [x.strip() for x in keywords]
return keywords
hydrangea is a string made of multiple sentences. spacyfunction is a function which takes that sentence and uses spacy to find its parts of speech, saving as a Pandas Dataframe.
@matthewstidham I'm not seeing what your code snippet has to do with OSMnx or the Jupyter notebook that this issue was opened for.
I am new to this package, and network analysis on python generally. As I was replicating the commands in the first example notebook, I ran in to the following issue:
edge_centrality = nx.closeness_centrality(nx.line_graph(G))
I imagine this is something to do with the networkx package, but I was wondering if anyone else has any suggestions to overcome this problem.
Thanks!