@@ -25,8 +25,9 @@ SCRIPTS_DIR=${SCRIPTS_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/../../scripts"} # Re
2525# Get the "cypher" query directory for gathering features.
2626ANOMALY_DETECTION_FEATURE_CYPHER_DIR=${ANOMALY_DETECTION_FEATURE_CYPHER_DIR:- " ${ANOMALY_DETECTION_SCRIPT_DIR} /features" }
2727ANOMALY_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"
3031source " ${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() {
100124anomaly_detection_csv_reports () {
101125 time anomaly_detection_features " ${@ } "
102126 time anomaly_detection_queries " ${@ } "
127+ time anomaly_detection_labels " ${@ } "
103128}
104129
105130# Create report directory
0 commit comments