@@ -67,6 +67,8 @@ anomaly_detection_features() {
67
67
# Required Parameters:
68
68
# - projection_node_label=...
69
69
# Label of the nodes that will be used for the projection. Example: "Package"
70
+ # - projection_language=...
71
+ # Name of the associated programming language. Default: "Java". Example: "Typescript"
70
72
anomaly_detection_queries () {
71
73
local nodeLabel
72
74
nodeLabel=$( extractQueryParameter " projection_node_label" " ${@ } " )
@@ -92,6 +94,8 @@ anomaly_detection_queries() {
92
94
# Required Parameters:
93
95
# - projection_node_label=...
94
96
# Label of the nodes that will be used for the projection. Example: "Package"
97
+ # - projection_language=...
98
+ # Name of the associated programming language. Examples: "Java", "Typescript"
95
99
anomaly_detection_labels () {
96
100
local nodeLabel
97
101
nodeLabel=$( extractQueryParameter " projection_node_label" " ${@ } " )
@@ -109,6 +113,63 @@ anomaly_detection_labels() {
109
113
# execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeOutlier.cypher" "${@}"
110
114
}
111
115
116
+ # TODO delete if not needed anymore
117
+ # # Initialize anomaly detail (Markdown) report.
118
+ # # Intended to be run the before the first call of "anomaly_detection_detail_report".
119
+ # initialize_anomaly_detection_detail_report() {
120
+ # archetype_summary_directory=${FULL_REPORT_DIRECTORY}/archetype-summary-${language}-${nodeLabel}
121
+ # rm -rf "${archetype_summary_directory}"
122
+ # }
123
+
124
+ # Appends a Markdown table to an existing file and
125
+ # removes redundant header + separator rows.
126
+ #
127
+ # Usage:
128
+ # cat newTable.md | append_table myMarkdownFile.md
129
+ #
130
+ # append_table myMarkdownFile.md <<'EOF'
131
+ # | Name | Score | Archetype |
132
+ # | --- | --- | --- |
133
+ # | Bar | 0.9 | Something |
134
+ # EOF
135
+ #
136
+ # Behavior:
137
+ # - Keeps the first header row and its following separator row.
138
+ # - Removes all subsequent duplicate header + separator pairs.
139
+ # - Leaves all data rows untouched.
140
+ append_to_markdown_table () {
141
+ local file=" $1 "
142
+
143
+ # Append stdin to the target file
144
+ cat >> " ${file} "
145
+
146
+ # Clean up duplicate headers (header row + --- row)
147
+ awk ' !seen[$0]++ || NR <= 2' " ${file} " > " ${file} .tmp" && mv " ${file} .tmp" " ${file} "
148
+ }
149
+
150
+ # Aggregates all results in a Markdown report.
151
+ # Note: Call "initialize_anomaly_detection_detail_report" before the first call of this function.
152
+ #
153
+ # Required Parameters:
154
+ # - projection_node_label=...
155
+ # Label of the nodes that will be used for the projection. Example: "Package"
156
+ # - projection_language=...
157
+ # Name of the associated programming language. Examples: "Java", "Typescript"
158
+ anomaly_detection_detail_report () {
159
+ local nodeLabel
160
+ nodeLabel=$( extractQueryParameter " projection_node_label" " ${@ } " )
161
+
162
+ local language
163
+ language=$( extractQueryParameter " projection_language" " ${@ } " )
164
+
165
+ echo " anomalyDetectionCsv: $( date +' %Y-%m-%dT%H:%M:%S%z' ) Creating ${language} ${nodeLabel} anomaly summary Markdown report..."
166
+
167
+ archetype_summary_directory=${FULL_REPORT_DIRECTORY} /archetype-summary-${language} -${nodeLabel}
168
+ mkdir -p " ${archetype_summary_directory} "
169
+ # execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeSummary.cypher" "${@}" --output-markdown-table | append_to_markdown_table "${FULL_REPORT_DIRECTORY}/TopAnomaliesByArchetype.md"
170
+ execute_cypher " ${ANOMALY_DETECTION_LABEL_CYPHER_DIR} /AnomalyDetectionArchetypeSummary.cypher" " ${@ } " --output-markdown-table > " ${archetype_summary_directory} /TopAnomaliesByArchetype.md"
171
+ }
172
+
112
173
# Run the anomaly detection pipeline.
113
174
#
114
175
# Required Parameters:
@@ -118,10 +179,13 @@ anomaly_detection_labels() {
118
179
# Label of the nodes that will be used for the projection. Example: "Package"
119
180
# - projection_weight_property=...
120
181
# Name of the node property that contains the dependency weight. Example: "weight"
182
+ # - projection_language=...
183
+ # Name of the associated programming language. Examples: "Java", "Typescript"
121
184
anomaly_detection_csv_reports () {
122
185
time anomaly_detection_features " ${@ } "
123
186
time anomaly_detection_queries " ${@ } "
124
187
time anomaly_detection_labels " ${@ } "
188
+ time anomaly_detection_detail_report " ${@ } "
125
189
}
126
190
127
191
# Create report directory
@@ -146,6 +210,9 @@ ALGORITHM_LANGUAGE="projection_language"
146
210
COMMUNITY_PROPERTY=" community_property=communityLeidenIdTuned"
147
211
EMBEDDING_PROPERTY=" embedding_property=embeddingsFastRandomProjectionTunedForClustering"
148
212
213
+ # TODO delete if not needed anymore
214
+ # initialize_anomaly_detection_detail_report
215
+
149
216
# -- Java Artifact Node Embeddings -------------------------------
150
217
151
218
if createUndirectedDependencyProjection " ${PROJECTION_NAME} =artifact-anomaly-detection" " ${PROJECTION_NODE} =Artifact" " ${PROJECTION_WEIGHT} =weight" " ${PROJECTION_LANGUAGE} =Java" ; then
0 commit comments