Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix information loss in undirected graph #283

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pytextrank/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def edge_list (
returns:
list of weighted edges
"""
edges: typing.List[typing.Tuple[Lemma, Lemma]] = []
edges: typing.List[typing.Tuple[Lemma, ...]] = []

for sent in self.doc.sents:
h = [
Expand All @@ -510,11 +510,12 @@ def edge_list (
for hop in range(self.token_lookback):
for idx, node in enumerate(h[: -1 - hop]):
nbor = h[hop + idx + 1]
edges.append((node, nbor))
sorted_edge = tuple(sorted([node, nbor], key=lambda x: x.lemma))
edges.append(sorted_edge)

# include weight on the edge: (2, 3, {'weight': 3.1415})
weighted_edges: typing.List[typing.Tuple[Lemma, Lemma, typing.Dict[str, float]]] = [
(*n, {"weight": w * self.edge_weight}) for n, w in Counter(edges).items()
(node1, node2, {"weight": w * self.edge_weight}) for (node1, node2), w in Counter(edges).items()
]

return weighted_edges
Expand Down
Loading