-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathdegree_cent.gsql
93 lines (78 loc) · 2.89 KB
/
degree_cent.gsql
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
CREATE TEMPLATE QUERY GDBMS_ALGO.centrality.degree_cent(SET<STRING> v_type_set, SET<STRING> e_type_set, SET<STRING> reverse_e_type_set, BOOL in_degree = TRUE, BOOL out_degree = TRUE,
INT top_k=100, BOOL print_results = TRUE, STRING result_attribute = "",STRING file_path = "", BOOL normalize = TRUE) SYNTAX V1 {
/*
First Author: <First Author Name>
First Commit Date: <First Commit Date>
Recent Author: Rob Rossmiller
Recent Commit Date: 05/2024
Repository:
https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Centrality
Maturity:
Production
Description:
Compute degree Centrality for each VERTEX.
for undirected graph, you only need to set e_type_set and indegree
Publications:
NA
TigerGraph Documentation:
https://docs.tigergraph.com/graph-ml/current/centrality-algorithms/degree-centrality
Parameters:
v_type_set:
vertex types to traverse
e_type_set:
edge types to traverse
reverse_e_type_set:
for indegree use
in_degree:
If True, count incoming relationships
out_degree:
If True, count outcoming relationships
top_k:
report only this many top scores
print_results:
If True, print the result
result_attribute:
attribute to write result to
file_path:
file to write CSV output to
normailize:
If True, return the normalized centrality. Default: True
*/
TYPEDEF TUPLE<VERTEX Vertex_ID, FLOAT score> Vertex_Score;
HeapAccum<Vertex_Score>(top_k, score DESC) @@top_scores_heap;
SumAccum<DOUBLE> @sum_degree_score;
FILE f (file_path);
all = {v_type_set};
sll = SELECT s
FROM all:s
ACCUM
IF in_degree THEN
s.@sum_degree_score += s.outdegree(reverse_e_type_set)
END,
IF out_degree THEN
s.@sum_degree_score += s.outdegree(e_type_set)
END
POST-ACCUM
IF normalize THEN
s.@sum_degree_score = s.@sum_degree_score / (all.size() - 1)
END;
#Output
IF file_path != "" THEN
f.println("Vertex_ID", "Degree");
END;
Start = SELECT s
FROM all:s
POST-ACCUM
IF result_attribute != "" THEN
s.setAttr(result_attribute, s.@sum_degree_score)
END,
IF print_results THEN
@@top_scores_heap += Vertex_Score(s, s.@sum_degree_score)
END,
IF file_path != "" THEN
f.println(s, s.@sum_degree_score)
END;
IF print_results THEN
PRINT @@top_scores_heap AS top_scores;
END;
}