|
1 |
| -CREATE QUERY tg_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, |
2 |
| - INT top_k=100, BOOL print_results = TRUE, STRING result_attribute = "",STRING file_path = "") SYNTAX V1 { |
3 |
| - |
| 1 | +CREATE QUERY tg_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 { |
4 | 2 | /*
|
5 |
| - First Author: <First Author Name> |
6 |
| - First Commit Date: <First Commit Date> |
7 |
| - |
8 |
| - Recent Author: <Recent Commit Author Name> |
9 |
| - Recent Commit Date: <Recent Commit Date> |
| 3 | + First Author: <First Author Name> |
| 4 | + First Commit Date: <First Commit Date> |
10 | 5 |
|
| 6 | + Recent Author: Rob Rossmiller |
| 7 | + Recent Commit Date: 05/2024 |
11 | 8 |
|
12 |
| - Repository: |
13 |
| - https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Centrality |
14 | 9 |
|
15 |
| - Maturity: |
16 |
| - Production |
| 10 | + Repository: |
| 11 | + https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Centrality |
17 | 12 |
|
18 |
| - Description: |
19 |
| - Compute degree Centrality for each VERTEX. |
20 |
| - for undirected graph, you only need to set e_type_set and indegree |
| 13 | + Maturity: |
| 14 | + Production |
21 | 15 |
|
22 |
| - Publications: |
23 |
| - NA |
| 16 | + Description: |
| 17 | + Compute degree Centrality for each VERTEX. |
| 18 | + for undirected graph, you only need to set e_type_set and indegree |
24 | 19 |
|
25 |
| - TigerGraph Documentation: |
26 |
| - https://docs.tigergraph.com/graph-ml/current/centrality-algorithms/degree-centrality |
| 20 | + Publications: |
| 21 | + NA |
27 | 22 |
|
28 |
| - Parameters: |
29 |
| - v_type_set: |
30 |
| - vertex types to traverse |
31 |
| - e_type_set: |
32 |
| - edge types to traverse |
33 |
| - reverse_e_type_set: |
34 |
| - for indegree use |
35 |
| - in_degree: |
36 |
| - If True, count incoming relationships |
37 |
| - out_degree: |
38 |
| - If True, count outcoming relationships |
39 |
| - top_k: |
40 |
| - report only this many top scores |
41 |
| - print_results: |
42 |
| - If True, print the result |
43 |
| - result_attribute: |
44 |
| - attribute to write result to |
45 |
| - file_path: |
46 |
| - file to write CSV output to |
| 23 | + TigerGraph Documentation: |
| 24 | + https://docs.tigergraph.com/graph-ml/current/centrality-algorithms/degree-centrality |
47 | 25 |
|
| 26 | + Parameters: |
| 27 | + v_type_set: |
| 28 | + vertex types to traverse |
| 29 | + e_type_set: |
| 30 | + edge types to traverse |
| 31 | + reverse_e_type_set: |
| 32 | + for indegree use |
| 33 | + in_degree: |
| 34 | + If True, count incoming relationships |
| 35 | + out_degree: |
| 36 | + If True, count outcoming relationships |
| 37 | + top_k: |
| 38 | + report only this many top scores |
| 39 | + print_results: |
| 40 | + If True, print the result |
| 41 | + result_attribute: |
| 42 | + attribute to write result to |
| 43 | + file_path: |
| 44 | + file to write CSV output to |
| 45 | + normailize: |
| 46 | + If True, return the normalized centrality. Default: True |
48 | 47 | */
|
49 | 48 |
|
50 | 49 | TYPEDEF TUPLE<VERTEX Vertex_ID, FLOAT score> Vertex_Score;
|
51 | 50 | HeapAccum<Vertex_Score>(top_k, score DESC) @@top_scores_heap;
|
52 |
| - SumAccum<INT> @sum_degree_score; |
| 51 | + SumAccum<DOUBLE> @sum_degree_score; |
53 | 52 | FILE f (file_path);
|
54 | 53 |
|
55 | 54 | all = {v_type_set};
|
56 | 55 | sll = SELECT s
|
57 | 56 | FROM all:s
|
58 |
| - ACCUM IF in_degree THEN |
59 |
| - FOREACH edge_type in reverse_e_type_set DO |
60 |
| - s.@sum_degree_score+=s.outdegree(edge_type) |
61 |
| - END |
62 |
| - END, |
63 |
| - IF out_degree THEN |
64 |
| - FOREACH edge_type in e_type_set DO |
65 |
| - s.@sum_degree_score+=s.outdegree(edge_type) |
66 |
| - END |
67 |
| - END; |
| 57 | + ACCUM |
| 58 | + IF in_degree THEN |
| 59 | + s.@sum_degree_score += s.outdegree(reverse_e_type_set) |
| 60 | + END, |
| 61 | + IF out_degree THEN |
| 62 | + s.@sum_degree_score += s.outdegree(e_type_set) |
| 63 | + END |
| 64 | + POST-ACCUM |
| 65 | + IF normalize THEN |
| 66 | + s.@sum_degree_score = s.@sum_degree_score / (all.size() - 1) |
| 67 | + END; |
| 68 | + |
68 | 69 | #Output
|
69 | 70 | IF file_path != "" THEN
|
70 | 71 | f.println("Vertex_ID", "Degree");
|
|
0 commit comments