pytextrank
pytextrank copied to clipboard
fix information loss in undirected graph
trafficstars
In an undirected graph, when we add duplicate edges, the associated weight is overwritten instead of accumulated. As per networkx documentation:
Adding the same edge twice has no effect but any edge data will be updated when each duplicate edge is added.
For a hypothetical example:
weighted_edges = [
("play", "with", {'weight': 2.0}),
("with", "play", {'weight': 11.0}),
]
graph= nx.Graph()
graph.add_edges_from(weighted_edges)
current code leads to(overwriting):
("play", "with", 11.0)
Desired behaviour(accumulation):
("play", "with", 13.0)
Thanks to @yamika-g for pointing it out here: