I have some connected components displayed. One of the components have five nodes in which the middle node is a common node. How can I obtain the index of each node in that component so that I can merge the other nodes along with a conjunction.
for component in nx.connected_components(graph):
num_nodes=len(component)
print num_nodes
g=(
filter(
lambda x: x[0] in component and x[1] in component,
graph.edges
)
)
if num_nodes == 5:
pl = []
pl = ''.join(item for tuple_ in g for item in tuple_)
print 'Merged nodes'
print pl
sentences.append(pl)
Input sentence is: शर्मान एक विकेट घेतली. मयंकान तीन विकेट घेतली
Output is: घेतली तीन विकेट घेतली एक विकेट एक विकेट शर्मान तीन विकेट मयंकान
Expected Output:शर्मान एक विकेट आनी मयंकान तीन विकेट घेतली
आनी has to be added to combine the nodes. Output of connected components