Skip to content

Commit 7703709

Browse files
committed
Refactor Cypher queries to utilize codeUnit.projectName instead of artifact and projectName variables
1 parent 65dabf5 commit 7703709

31 files changed

Lines changed: 9359 additions & 270 deletions

File tree

domains/anomaly-detection/explore/AnomalyDetectionExploration.ipynb

Lines changed: 4742 additions & 63 deletions
Large diffs are not rendered by default.

domains/anomaly-detection/explore/AnomalyDetectionIsolationForestExploration.ipynb

Lines changed: 4588 additions & 60 deletions
Large diffs are not rendered by default.

domains/anomaly-detection/features/AnomalyDetectionFeatures.cypher

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,11 @@
2828
// AND codeUnit.anomalyTopFeatureSHAPValue3 IS NOT NULL
2929
AND codeUnit.embeddingsFastRandomProjectionTunedForClusteringVisualizationX IS NOT NULL
3030
AND codeUnit.embeddingsFastRandomProjectionTunedForClusteringVisualizationY IS NOT NULL
31-
OPTIONAL MATCH (artifact:Java:Artifact)-[:CONTAINS]->(codeUnit)
32-
WITH *, artifact.name AS artifactName
33-
OPTIONAL MATCH (projectRoot:Directory)<-[:HAS_ROOT]-(proj:TS:Project)-[:CONTAINS]->(codeUnit)
34-
WITH *, last(split(projectRoot.absoluteFileName, '/')) AS projectName
3531
RETURN DISTINCT
3632
coalesce(codeUnit.fqn, codeUnit.globalFqn, codeUnit.fileName, codeUnit.signature, codeUnit.name) AS codeUnitName
3733
,codeUnit.name AS shortCodeUnitName
3834
,elementId(codeUnit) AS nodeElementId
39-
,coalesce(artifactName, projectName, "") AS projectName
35+
,coalesce(codeUnit.projectName, '') AS projectName
4036
,codeUnit.incomingDependencies AS incomingDependencies
4137
,codeUnit.outgoingDependencies AS outgoingDependencies
4238
,codeUnit[$community_property] AS communityId

domains/anomaly-detection/labels/AnomalyDetectionArchetypeBridge.cypher

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
MATCH (codeUnit)
55
WHERE $projection_node_label IN labels(codeUnit)
66
AND codeUnit.anomalyNodeEmbeddingSHAPSum < 0
7-
OPTIONAL MATCH (artifact:Java:Artifact)-[:CONTAINS]->(codeUnit)
8-
WITH *, artifact.name AS artifactName
9-
OPTIONAL MATCH (projectRoot:Directory)<-[:HAS_ROOT]-(proj:TS:Project)-[:CONTAINS]->(codeUnit)
10-
WITH *, last(split(projectRoot.absoluteFileName, '/')) AS projectName
11-
WITH *, coalesce(artifactName, projectName) AS projectName
7+
WITH *, coalesce(codeUnit.projectName, '') AS projectName
128
ORDER BY codeUnit.anomalyNodeEmbeddingSHAPSum ASC
139
LIMIT 10
1410
WITH collect([codeUnit, projectName]) AS results

domains/anomaly-detection/labels/AnomalyDetectionArchetypeOutlier.cypher

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
WITH *
1313
WHERE codeUnit.clusteringHDBSCANNormalizedDistanceToMedoid >= distanceToMedoidThreshold
1414
AND codeUnit.clusteringHDBSCANProbability <= clusteringProbabilityThreshold
15-
OPTIONAL MATCH (artifact:Java:Artifact)-[:CONTAINS]->(codeUnit)
16-
WITH *, artifact.name AS artifactName
17-
OPTIONAL MATCH (projectRoot:Directory)<-[:HAS_ROOT]-(proj:TS:Project)-[:CONTAINS]->(codeUnit)
18-
WITH *, last(split(projectRoot.absoluteFileName, '/')) AS projectName
19-
WITH *, coalesce(artifactName, projectName) AS projectName
15+
WITH *, coalesce(codeUnit.projectName, '') AS projectName
2016
ORDER BY codeUnit.clusteringHDBSCANNormalizedDistanceToMedoid DESC, codeUnit.clusteringHDBSCANProbability ASC
2117
LIMIT 10
2218
WITH collect([codeUnit, projectName]) AS results

domains/anomaly-detection/labels/AnomalyDetectionTopAnomalies.cypher

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
AND codeUnit.anomalyLabel = 1
77
ORDER BY codeUnit.anomalyScore DESC
88
LIMIT 50
9-
OPTIONAL MATCH (artifact:Java:Artifact)-[:CONTAINS]->(codeUnit)
10-
WITH *, artifact.name AS artifactName
11-
OPTIONAL MATCH (projectRoot:Directory)<-[:HAS_ROOT]-(proj:TS:Project)-[:CONTAINS]->(codeUnit)
12-
WITH *, last(split(projectRoot.absoluteFileName, '/')) AS projectName
13-
WITH *, coalesce(artifactName, projectName) AS projectName
9+
WITH *, coalesce(codeUnit.projectName, '') AS projectName
1410
RETURN projectName
1511
,codeUnit.name AS shortCodeUnitName
1612
,coalesce(codeUnit.fqn, codeUnit.globalFqn, codeUnit.fileName, codeUnit.signature, codeUnit.name) AS codeUnitName

domains/anomaly-detection/queries/node-embeddings/Node_Embeddings_0a_Query_Calculated.cypher

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
WHERE $dependencies_projection_node IN LABELS(codeUnit)
55
AND codeUnit[$dependencies_projection_write_property] IS NOT NULL
66
// AND codeUnit.notExistingToForceRecalculation IS NOT NULL // uncomment this line to force recalculation
7-
OPTIONAL MATCH (artifact:Java:Artifact)-[:CONTAINS]->(codeUnit)
8-
WITH *, artifact.name AS artifactName
9-
OPTIONAL MATCH (projectRoot:Directory)<-[:HAS_ROOT]-(proj:TS:Project)-[:CONTAINS]->(codeUnit)
10-
WITH *, last(split(projectRoot.absoluteFileName, '/')) AS projectName
117
RETURN DISTINCT
128
coalesce(codeUnit.fqn, codeUnit.globalFqn, codeUnit.fileName, codeUnit.signature, codeUnit.name) AS codeUnitName
139
,codeUnit.name AS shortCodeUnitName
14-
,coalesce(artifactName, projectName) AS projectName
10+
,coalesce(codeUnit.projectName, '') AS projectName
1511
,coalesce(codeUnit.communityLeidenId, 0) AS communityId
1612
,coalesce(codeUnit.centralityPageRank, 0.01) AS centrality
1713
,codeUnit[$dependencies_projection_write_property] AS embedding

domains/anomaly-detection/queries/node-embeddings/Node_Embeddings_1d_Fast_Random_Projection_Tuneable_Stream.cypher

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@ CALL gds.fastRP.stream(
1212
YIELD nodeId, embedding
1313
WITH gds.util.asNode(nodeId) AS codeUnit
1414
,embedding
15-
OPTIONAL MATCH (artifact:Java:Artifact)-[:CONTAINS]->(codeUnit)
16-
WITH *, artifact.name AS artifactName
17-
OPTIONAL MATCH (projectRoot:Directory)<-[:HAS_ROOT]-(proj:TS:Project)-[:CONTAINS]->(codeUnit)
18-
WITH *, last(split(projectRoot.absoluteFileName, '/')) AS projectName
1915
RETURN DISTINCT
2016
coalesce(codeUnit.fqn, codeUnit.globalFqn, codeUnit.fileName, codeUnit.signature, codeUnit.name) AS codeUnitName
2117
,codeUnit.name AS shortCodeUnitName
2218
,elementId(codeUnit) AS nodeElementId
23-
,coalesce(artifactName, projectName) AS projectName
19+
,coalesce(codeUnit.projectName, '') AS projectName
2420
,coalesce(codeUnit.communityLeidenIdTuned, codeUnit.communityLeidenId, 0) AS communityId
2521
,coalesce(codeUnit.centralityPageRank, 0.01) AS centrality
2622
,embedding

domains/anomaly-detection/queries/node-embeddings/Node_Embeddings_2d_Hash_GNN_Tuneable_Stream.cypher

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ CALL gds.beta.hashgnn.stream(
1616
YIELD nodeId, embedding
1717
WITH gds.util.asNode(nodeId) AS codeUnit
1818
,embedding
19-
OPTIONAL MATCH (artifact:Java:Artifact)-[:CONTAINS]->(codeUnit)
20-
WITH *, artifact.name AS artifactName
21-
OPTIONAL MATCH (projectRoot:Directory)<-[:HAS_ROOT]-(proj:TS:Project)-[:CONTAINS]->(codeUnit)
22-
WITH *, last(split(projectRoot.absoluteFileName, '/')) AS projectName
2319
RETURN DISTINCT
2420
coalesce(codeUnit.fqn, codeUnit.globalFqn, codeUnit.fileName, codeUnit.signature, codeUnit.name) AS codeUnitName
2521
,codeUnit.name AS shortCodeUnitName
2622
,elementId(codeUnit) AS nodeElementId
27-
,coalesce(artifactName, projectName) AS projectName
23+
,coalesce(codeUnit.projectName, '') AS projectName
2824
,coalesce(codeUnit.communityLeidenIdTuned, codeUnit.communityLeidenId, 0) AS communityId
2925
,coalesce(codeUnit.centralityPageRank, 0.01) AS centrality
3026
,embedding

domains/anomaly-detection/queries/node-embeddings/Node_Embeddings_3d_Node2Vec_Tuneable_Stream.cypher

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@ CALL gds.node2vec.stream(
1818
YIELD nodeId, embedding
1919
WITH gds.util.asNode(nodeId) AS codeUnit
2020
,embedding
21-
OPTIONAL MATCH (artifact:Java:Artifact)-[:CONTAINS]->(codeUnit)
22-
WITH *, artifact.name AS artifactName
23-
OPTIONAL MATCH (projectRoot:Directory)<-[:HAS_ROOT]-(proj:TS:Project)-[:CONTAINS]->(codeUnit)
24-
WITH *, last(split(projectRoot.absoluteFileName, '/')) AS projectName
2521
RETURN DISTINCT
2622
coalesce(codeUnit.fqn, codeUnit.globalFqn, codeUnit.fileName, codeUnit.signature, codeUnit.name) AS codeUnitName
2723
,codeUnit.name AS shortCodeUnitName
2824
,elementId(codeUnit) AS nodeElementId
29-
,coalesce(artifactName, projectName) AS projectName
25+
,coalesce(codeUnit.projectName, '') AS projectName
3026
,coalesce(codeUnit.communityLeidenIdTuned, codeUnit.communityLeidenId, 0) AS communityId
3127
,coalesce(codeUnit.centralityPageRank, 0.01) AS centrality
3228
,embedding

0 commit comments

Comments
 (0)