-
Notifications
You must be signed in to change notification settings - Fork 1
/
louvain.py
51 lines (42 loc) · 1.18 KB
/
louvain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import Neo4jConnection as con
made_louvain_graph = '''
CALL gds.graph.project(
$name,
'Stop',
{
ROUTE_SEGMENT: {
orientation: 'UNDIRECTED',
properties: 'length'
}
}
)
'''
community_louvain_graph = '''
CALL gds.louvain.stream(
$name,
{
relationshipWeightProperty: 'length'
}
)
YIELD nodeId, communityId
RETURN communityId, COUNT(DISTINCT nodeId) AS members
ORDER BY members DESC
'''
write_louvain_graph = '''
CALL gds.louvain.write(
$name,
{
writeProperty: 'louvain_community'
}
)
YIELD communityCount, modularity, modularities
'''
NEO4J_URI = "bolt://localhost:7687"
NEO4J_USER = "neo4j"
NEO4J_PASSWORD = "123456789"
conn = con.Neo4jConnection(uri=NEO4J_URI, user=NEO4J_USER, pwd=NEO4J_PASSWORD)
def louvain_clustering(graph_name):
conn.query(made_louvain_graph, {"name": graph_name})
conn.query(community_louvain_graph, {"name": graph_name})
conn.query(write_louvain_graph, {"name": graph_name})
louvain_clustering("louvainAlgoritmGraph")