Skip to content

Commit ffdfded

Browse files
committed
Add cypher queries to explore code graph schemas
1 parent a3373ac commit ffdfded

7 files changed

+89
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Get DEPENDS_ON relationships schema
2+
3+
MATCH (s)-[r:DEPENDS_ON]->(t)
4+
RETURN labels(s) AS sourceLabels
5+
,labels(t) AS targetLabels
6+
,keys(r) AS relationshipKeys
7+
,count(*) AS numberOfNodes
8+
ORDER BY sourceLabels, targetLabels, relationshipKeys
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// External declarations split by their module and their contained symbols
2+
3+
MATCH (s:ExternalDeclaration)
4+
WITH *
5+
,replace(split(s.globalFqn, '".')[0],'"', '') AS externalDeclarationModule
6+
,split(s.globalFqn, '".')[1] AS externalDeclarationSymbol
7+
RETURN externalDeclarationModule
8+
,count(DISTINCT externalDeclarationSymbol) AS externalDeclarationSymbols
9+
,collect(externalDeclarationSymbol)[0..4] AS someExternalDeclarationSymbols
10+
,count(*) as numberOfExternalDeclarations
11+
ORDER BY numberOfExternalDeclarations DESC, externalDeclarationModule ASC
12+
LIMIT 50
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Explore outgoing dependencies of modules
2+
3+
MATCH (source:Module)-[rm:DEPENDS_ON]->(module:ExternalModule)
4+
OPTIONAL MATCH (module)-[:EXPORTS]->(declaration:ExternalDeclaration)<-[re:DEPENDS_ON]-(source)
5+
OPTIONAL MATCH (source)-[:DECLARES]->(implementation:Function|Variable)-[ri:DEPENDS_ON]->(module)
6+
OPTIONAL MATCH (source)-[:DECLARES]->(abstract:Interface|TypeAlias)-[ra:DEPENDS_ON]->(module)
7+
RETURN source.globalFqn AS module
8+
,count(DISTINCT abstract) AS numberOfAbstract
9+
,count(DISTINCT declaration) AS numberOfExternalDeclarations
10+
,count(DISTINCT implementation) AS numberOfImplementations
11+
,sum(rm.cardinality) AS sumModuleDependencyWeights
12+
,sum(re.cardinality) AS sumExternalDeclarationWeights
13+
,sum(ri.cardinality) AS sumImplementationWeights
14+
,sum(ra.cardinality) AS sumAbstractWeights
15+
//TODO sumWeights should sum up to sumModuleDependencyWeights
16+
,sum(re.cardinality) + sum(ri.cardinality) + sum(ra.cardinality) as sumWeights
17+
ORDER BY source.globalFqn ASC
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Explore nodes grouped by their module (first part of globalFqn)
2+
3+
MATCH (n:TS)
4+
WHERE n.globalFqn IS NOT NULL
5+
UNWIND labels(n) AS nodeLabel
6+
WITH replace(split(n.globalFqn, '".')[0],'"', '') AS module
7+
,collect(split(n.globalFqn, '".')[1]) AS symbols
8+
,nodeLabel
9+
,count(DISTINCT n) as numberOfNodes
10+
WHERE nodeLabel <> 'TS'
11+
RETURN module
12+
,collect(DISTINCT nodeLabel) AS nodeLabels
13+
,sum(numberOfNodes) AS numberOfNodes
14+
,collect(symbols[0..4]) AS symbolExamples
15+
ORDER BY module ASC
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Explore nodes grouped by their module (first part of globalFqn) and their type of contained symbols
2+
3+
MATCH (n:TS)
4+
WHERE n.globalFqn IS NOT NULL
5+
UNWIND labels(n) AS nodeLabel
6+
WITH replace(split(n.globalFqn, '".')[0],'"', '') AS module
7+
,collect(split(n.globalFqn, '".')[1]) AS symbols
8+
,nodeLabel
9+
,count(DISTINCT n) as numberOfNodes
10+
WHERE nodeLabel <> 'TS'
11+
RETURN module
12+
,collect(DISTINCT nodeLabel) as nodeLabels
13+
,numberOfNodes
14+
,symbols[0..4] AS symbolExamples
15+
ORDER BY module ASC
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Explore node properties, the labels of their nodes and their count
2+
3+
MATCH (n)
4+
UNWIND keys(n) AS nodePropertyName
5+
UNWIND labels(n) AS nodeLabel
6+
RETURN nodePropertyName
7+
,collect(DISTINCT nodeLabel) AS nodeLabels
8+
,count(DISTINCT n) AS numberOfNodes
9+
,count(DISTINCT n[nodePropertyName]) AS numberOfDistinctValues
10+
,collect(DISTINCT n[nodePropertyName])[0..4] AS exampleValues
11+
ORDER BY nodePropertyName
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Get all relationships of one specific node to explore the schema
2+
3+
MATCH (s:TS:Module)-[r]->(t)
4+
RETURN labels(s) AS sourceLabels
5+
,keys(s) AS sourceKeys
6+
,labels(t) AS targetLabels
7+
,keys(t) AS targetKeys
8+
,type(r) AS relationshipType
9+
,keys(r) AS relationshipKeys
10+
,count(*) AS numberOfNodes
11+
ORDER BY sourceLabels, targetLabels, relationshipKeys

0 commit comments

Comments
 (0)