Spaces:
Running
Running
github-actions[bot]
commited on
Commit
·
f851e18
1
Parent(s):
3389c47
Auto-sync from demo at Thu Jan 8 15:34:14 UTC 2026
Browse files
graphgen/bases/base_partitioner.py
CHANGED
|
@@ -39,14 +39,17 @@ class BasePartitioner(ABC):
|
|
| 39 |
if node_data:
|
| 40 |
nodes_data.append((node, node_data))
|
| 41 |
edges_data = []
|
| 42 |
-
for
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
if edge_data:
|
| 45 |
edges_data.append((u, v, edge_data))
|
| 46 |
-
else:
|
| 47 |
-
edge_data = g.get_edge(v, u)
|
| 48 |
-
if edge_data:
|
| 49 |
-
edges_data.append((v, u, edge_data))
|
| 50 |
return nodes_data, edges_data
|
| 51 |
|
| 52 |
@staticmethod
|
|
@@ -61,9 +64,11 @@ class BasePartitioner(ABC):
|
|
| 61 |
"""
|
| 62 |
adj: dict[str, List[str]] = {n[0]: [] for n in nodes}
|
| 63 |
edge_set: set[tuple[str, str]] = set()
|
| 64 |
-
for
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
| 69 |
return adj, edge_set
|
|
|
|
| 39 |
if node_data:
|
| 40 |
nodes_data.append((node, node_data))
|
| 41 |
edges_data = []
|
| 42 |
+
for edge in edges:
|
| 43 |
+
# Filter out self-loops and invalid edges
|
| 44 |
+
if not isinstance(edge, tuple) or len(edge) != 2:
|
| 45 |
+
continue
|
| 46 |
+
u, v = edge
|
| 47 |
+
if u == v:
|
| 48 |
+
continue
|
| 49 |
+
|
| 50 |
+
edge_data = g.get_edge(u, v) or g.get_edge(v, u)
|
| 51 |
if edge_data:
|
| 52 |
edges_data.append((u, v, edge_data))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
return nodes_data, edges_data
|
| 54 |
|
| 55 |
@staticmethod
|
|
|
|
| 64 |
"""
|
| 65 |
adj: dict[str, List[str]] = {n[0]: [] for n in nodes}
|
| 66 |
edge_set: set[tuple[str, str]] = set()
|
| 67 |
+
for u, v, _ in edges:
|
| 68 |
+
if u == v:
|
| 69 |
+
continue
|
| 70 |
+
adj[u].append(v)
|
| 71 |
+
adj[v].append(u)
|
| 72 |
+
edge_set.add((u, v))
|
| 73 |
+
edge_set.add((v, u))
|
| 74 |
return adj, edge_set
|
graphgen/models/partitioner/bfs_partitioner.py
CHANGED
|
@@ -63,9 +63,7 @@ class BFSPartitioner(BasePartitioner):
|
|
| 63 |
if it in used_e:
|
| 64 |
continue
|
| 65 |
used_e.add(it)
|
| 66 |
-
|
| 67 |
-
u, v = it
|
| 68 |
-
comm_e.append((u, v))
|
| 69 |
cnt += 1
|
| 70 |
# push nodes that are not visited
|
| 71 |
for n in it:
|
|
|
|
| 63 |
if it in used_e:
|
| 64 |
continue
|
| 65 |
used_e.add(it)
|
| 66 |
+
comm_e.append(tuple(sorted(it)))
|
|
|
|
|
|
|
| 67 |
cnt += 1
|
| 68 |
# push nodes that are not visited
|
| 69 |
for n in it:
|
graphgen/models/partitioner/dfs_partitioner.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import random
|
| 2 |
from collections.abc import Iterable
|
| 3 |
-
from typing import Any
|
| 4 |
|
| 5 |
from graphgen.bases import BaseGraphStorage, BasePartitioner
|
| 6 |
from graphgen.bases.datatypes import Community
|
|
@@ -42,7 +42,8 @@ class DFSPartitioner(BasePartitioner):
|
|
| 42 |
):
|
| 43 |
continue
|
| 44 |
|
| 45 |
-
comm_n
|
|
|
|
| 46 |
stack = [(kind, seed)]
|
| 47 |
cnt = 0
|
| 48 |
|
|
@@ -63,7 +64,7 @@ class DFSPartitioner(BasePartitioner):
|
|
| 63 |
if it in used_e:
|
| 64 |
continue
|
| 65 |
used_e.add(it)
|
| 66 |
-
comm_e.append(tuple(it))
|
| 67 |
cnt += 1
|
| 68 |
# push neighboring nodes
|
| 69 |
for n in it:
|
|
|
|
| 1 |
import random
|
| 2 |
from collections.abc import Iterable
|
| 3 |
+
from typing import Any, List
|
| 4 |
|
| 5 |
from graphgen.bases import BaseGraphStorage, BasePartitioner
|
| 6 |
from graphgen.bases.datatypes import Community
|
|
|
|
| 42 |
):
|
| 43 |
continue
|
| 44 |
|
| 45 |
+
comm_n: List[str] = []
|
| 46 |
+
comm_e: List[tuple[str, str]] = []
|
| 47 |
stack = [(kind, seed)]
|
| 48 |
cnt = 0
|
| 49 |
|
|
|
|
| 64 |
if it in used_e:
|
| 65 |
continue
|
| 66 |
used_e.add(it)
|
| 67 |
+
comm_e.append(tuple(sorted(it)))
|
| 68 |
cnt += 1
|
| 69 |
# push neighboring nodes
|
| 70 |
for n in it:
|
graphgen/models/partitioner/ece_partitioner.py
CHANGED
|
@@ -142,7 +142,7 @@ class ECEPartitioner(BFSPartitioner):
|
|
| 142 |
return Community(
|
| 143 |
id=seed_unit[1],
|
| 144 |
nodes=list(community_nodes.keys()),
|
| 145 |
-
edges=[tuple(
|
| 146 |
)
|
| 147 |
|
| 148 |
for unit in tqdm(all_units, desc="ECE partition"):
|
|
|
|
| 142 |
return Community(
|
| 143 |
id=seed_unit[1],
|
| 144 |
nodes=list(community_nodes.keys()),
|
| 145 |
+
edges=[tuple(sorted(e)) for e in community_edges]
|
| 146 |
)
|
| 147 |
|
| 148 |
for unit in tqdm(all_units, desc="ECE partition"):
|
graphgen/utils/help_nltk.py
CHANGED
|
@@ -3,13 +3,14 @@ import os
|
|
| 3 |
from typing import Dict, List, Final, Optional
|
| 4 |
import warnings
|
| 5 |
import nltk
|
| 6 |
-
import jieba
|
| 7 |
-
|
| 8 |
warnings.filterwarnings(
|
| 9 |
"ignore",
|
| 10 |
category=UserWarning,
|
| 11 |
module=r"jieba\._compat"
|
| 12 |
)
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
class NLTKHelper:
|
| 15 |
"""
|
|
|
|
| 3 |
from typing import Dict, List, Final, Optional
|
| 4 |
import warnings
|
| 5 |
import nltk
|
|
|
|
|
|
|
| 6 |
warnings.filterwarnings(
|
| 7 |
"ignore",
|
| 8 |
category=UserWarning,
|
| 9 |
module=r"jieba\._compat"
|
| 10 |
)
|
| 11 |
+
# pylint: disable=wrong-import-position
|
| 12 |
+
import jieba
|
| 13 |
+
|
| 14 |
|
| 15 |
class NLTKHelper:
|
| 16 |
"""
|