@@ -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"
@@ -60,6 +61,7 @@ anomaly_detection_features() {
6061 execute_cypher_queries_until_results " ${ANOMALY_DETECTION_FEATURE_CYPHER_DIR} /AnomalyDetectionFeature-ArticleRank-Exists.cypher" \
6162 " ${ANOMALY_DETECTION_FEATURE_CYPHER_DIR} /AnomalyDetectionFeature-ArticleRank-Write.cypher" " ${@ } "
6263}
64+
6365# Run queries to find anomalies in the graph.
6466#
6567# Required Parameters:
@@ -85,6 +87,28 @@ anomaly_detection_queries() {
8587 execute_cypher " ${ANOMALY_DETECTION_QUERY_CYPHER_DIR} /AnomalyDetectionUnexpectedCentralNodes.cypher" " ${@ } " > " ${FULL_REPORT_DIRECTORY} /${language} _${nodeLabel} _AnomalyDetection_UnexpectedCentralNodes.csv"
8688}
8789
90+ # Label code units with top anomalies by archetype.
91+ #
92+ # Required Parameters:
93+ # - projection_node_label=...
94+ # Label of the nodes that will be used for the projection. Example: "Package"
95+ anomaly_detection_labels () {
96+ local nodeLabel
97+ nodeLabel=$( extractQueryParameter " projection_node_label" " ${@ } " )
98+
99+ local language
100+ language=$( extractQueryParameter " projection_language" " ${@ } " )
101+
102+ echo " anomalyDetectionCsv: $( date +' %Y-%m-%dT%H:%M:%S%z' ) Labelling ${language} ${nodeLabel} anomalies..."
103+ execute_cypher " ${ANOMALY_DETECTION_LABEL_CYPHER_DIR} /AnomalyDetectionArchetypeRemoveLabels.cypher" " ${@ } "
104+ execute_cypher " ${ANOMALY_DETECTION_LABEL_CYPHER_DIR} /AnomalyDetectionArchetypeAuthority.cypher" " ${@ } " > " ${FULL_REPORT_DIRECTORY} /${language} _${nodeLabel} _AnomalyArchetypeTopAuthority.csv"
105+ execute_cypher " ${ANOMALY_DETECTION_LABEL_CYPHER_DIR} /AnomalyDetectionArchetypeBottleneck.cypher" " ${@ } " > " ${FULL_REPORT_DIRECTORY} /${language} _${nodeLabel} _AnomalyArchetypeTopBottleneck.csv"
106+ execute_cypher " ${ANOMALY_DETECTION_LABEL_CYPHER_DIR} /AnomalyDetectionArchetypeHub.cypher" " ${@ } " > " ${FULL_REPORT_DIRECTORY} /${language} _${nodeLabel} _AnomalyArchetypeTopHub.csv"
107+ # The following two label types require Python scripts to run first and are skipped here intentionally:
108+ # execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeBridge.cypher" "${@}"
109+ # execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeOutlier.cypher" "${@}"
110+ }
111+
88112# Run the anomaly detection pipeline.
89113#
90114# Required Parameters:
@@ -97,6 +121,7 @@ anomaly_detection_queries() {
97121anomaly_detection_csv_reports () {
98122 time anomaly_detection_features " ${@ } "
99123 time anomaly_detection_queries " ${@ } "
124+ time anomaly_detection_labels " ${@ } "
100125}
101126
102127# Create report directory
0 commit comments