Skip to content

Commit fe9f6a1

Browse files
committed
Add anomaly archetype labels and reports
1 parent 485ca7d commit fe9f6a1

9 files changed

+615
-4
lines changed

domains/anomaly-detection/anomalyDetectionCsv.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ SCRIPTS_DIR=${SCRIPTS_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/../../scripts"} # Re
2525
# Get the "cypher" query directory for gathering features.
2626
ANOMALY_DETECTION_FEATURE_CYPHER_DIR=${ANOMALY_DETECTION_FEATURE_CYPHER_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/features"}
2727
ANOMALY_DETECTION_QUERY_CYPHER_DIR=${ANOMALY_DETECTION_QUERY_CYPHER_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/queries"}
28+
ANOMALY_DETECTION_LABEL_CYPHER_DIR=${ANOMALY_DETECTION_LABEL_CYPHER_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/labels"}
2829

29-
# Define functions to execute a cypher query from within a given file (first and only argument) like "execute_cypher"
30+
# Define functions to execute a cypher query from within a given file (first and only argument) like "execute_cypher" and "execute_cypher_summarized"
3031
source "${SCRIPTS_DIR}/executeQueryFunctions.sh"
3132

3233
# Define functions to create and delete Graph Projections like "createUndirectedDependencyProjection"
@@ -63,6 +64,7 @@ anomaly_detection_features() {
6364
execute_cypher_queries_until_results "${ANOMALY_DETECTION_FEATURE_CYPHER_DIR}/AnomalyDetectionFeature-HyperlinkInducedTopicSearch-HITS-Exists.cypher" \
6465
"${ANOMALY_DETECTION_FEATURE_CYPHER_DIR}/AnomalyDetectionFeature-HyperlinkInducedTopicSearch-HITS-Write.cypher" "${@}"
6566
}
67+
6668
# Run queries to find anomalies in the graph.
6769
#
6870
# Required Parameters:
@@ -88,6 +90,28 @@ anomaly_detection_queries() {
8890
execute_cypher "${ANOMALY_DETECTION_QUERY_CYPHER_DIR}/AnomalyDetectionUnexpectedCentralNodes.cypher" "${@}" > "${FULL_REPORT_DIRECTORY}/${language}_${nodeLabel}_AnomalyDetection_UnexpectedCentralNodes.csv"
8991
}
9092

93+
# Label code units with top anomalies by archetype.
94+
#
95+
# Required Parameters:
96+
# - projection_node_label=...
97+
# Label of the nodes that will be used for the projection. Example: "Package"
98+
anomaly_detection_labels() {
99+
local nodeLabel
100+
nodeLabel=$( extractQueryParameter "projection_node_label" "${@}" )
101+
102+
local language
103+
language=$( extractQueryParameter "projection_language" "${@}" )
104+
105+
echo "anomalyDetectionCsv: $(date +'%Y-%m-%dT%H:%M:%S%z') Labelling ${language} ${nodeLabel} anomalies..."
106+
execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeRemoveLabels.cypher" "${@}"
107+
execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeAuthority.cypher" "${@}" > "${FULL_REPORT_DIRECTORY}/${language}_${nodeLabel}_AnomalyArchetypeTopAuthority.csv"
108+
execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeBottleneck.cypher" "${@}" > "${FULL_REPORT_DIRECTORY}/${language}_${nodeLabel}_AnomalyArchetypeTopBottleneck.csv"
109+
execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeHub.cypher" "${@}" > "${FULL_REPORT_DIRECTORY}/${language}_${nodeLabel}_AnomalyArchetypeTopHub.csv"
110+
# The following two label types require Python scripts to run first and are skipped here intentionally:
111+
# execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeBridge.cypher" "${@}"
112+
# execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeOutlier.cypher" "${@}"
113+
}
114+
91115
# Run the anomaly detection pipeline.
92116
#
93117
# Required Parameters:
@@ -100,6 +124,7 @@ anomaly_detection_queries() {
100124
anomaly_detection_csv_reports() {
101125
time anomaly_detection_features "${@}"
102126
time anomaly_detection_queries "${@}"
127+
time anomaly_detection_labels "${@}"
103128
}
104129

105130
# Create report directory

domains/anomaly-detection/anomalyDetectionPython.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ SCRIPTS_DIR=${SCRIPTS_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/../../scripts"} # Re
2525
# Get the "cypher" query directory for gathering features.
2626
ANOMALY_DETECTION_FEATURE_CYPHER_DIR=${ANOMALY_DETECTION_FEATURE_CYPHER_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/features"}
2727
ANOMALY_DETECTION_QUERY_CYPHER_DIR=${ANOMALY_DETECTION_QUERY_CYPHER_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/queries"}
28+
ANOMALY_DETECTION_LABEL_CYPHER_DIR=${ANOMALY_DETECTION_LABEL_CYPHER_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/labels"}
2829

2930
# Function to display script usage
3031
usage() {
@@ -141,6 +142,27 @@ anomaly_detection_using_python() {
141142
execute_cypher "${ANOMALY_DETECTION_FEATURE_CYPHER_DIR}/AnomalyDetectionFeatures.cypher" "${@}" > "${FULL_REPORT_DIRECTORY}/${language}_${nodeLabel}AnomalyDetection_Features.csv"
142143
}
143144

145+
# Label code units with top anomalies by archetype.
146+
#
147+
# Required Parameters:
148+
# - projection_node_label=...
149+
# Label of the nodes that will be used for the projection. Example: "Package"
150+
anomaly_detection_labels() {
151+
local nodeLabel
152+
nodeLabel=$( extractQueryParameter "projection_node_label" "${@}" )
153+
154+
local language
155+
language=$( extractQueryParameter "projection_language" "${@}" )
156+
157+
echo "anomalyDetectionPython: $(date +'%Y-%m-%dT%H:%M:%S%z') Labelling ${language} ${nodeLabel} anomalies..."
158+
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeRemoveLabels.cypher" "${@}"
159+
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeAuthority.cypher" "${@}"
160+
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeBottleneck.cypher" "${@}"
161+
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeHub.cypher" "${@}"
162+
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeBridge.cypher" "${@}"
163+
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeOutlier.cypher" "${@}"
164+
}
165+
144166
# Run the anomaly detection pipeline.
145167
#
146168
# Required Parameters:
@@ -153,6 +175,7 @@ anomaly_detection_using_python() {
153175
anomaly_detection_python_reports() {
154176
time anomaly_detection_features "${@}"
155177
anomaly_detection_using_python "${@}"
178+
time anomaly_detection_labels "${@}"
156179
}
157180

158181
# Create report directory

0 commit comments

Comments
 (0)