Skip to content

Commit efde989

Browse files
committed
Make weight setter language dependent
1 parent dc1a235 commit efde989

10 files changed

+126
-63
lines changed
Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,76 @@
11
// Add weight property for low coupling dependencies to Typescript module DEPENDS_ON relationships
22

3-
MATCH (source:TS:Module)-[moduleDependency:DEPENDS_ON]->(target:ExternalModule)
43
// Get the top level dependency between a Typescript module and the external modules it uses
5-
WITH source
6-
,target
7-
,moduleDependency
8-
,count(DISTINCT target) AS externalModuleCount
9-
,sum(moduleDependency.cardinality) AS externalModuleCardinalities
10-
OPTIONAL MATCH (source)-[rd:DEPENDS_ON]->(declaration:ExternalDeclaration)<-[:EXPORTS]-(target)
4+
MATCH (source:TS:Module)-[moduleDependency:DEPENDS_ON]->(target:ExternalModule)
115
// Get optional external (e.g. type) declarations that the external module (target) provides and the source module uses
6+
OPTIONAL MATCH (source)-[rd:DEPENDS_ON]->(declaration:ExternalDeclaration)<-[:EXPORTS]-(target)
127
WITH source
138
,target
149
,moduleDependency
15-
,externalModuleCount
16-
,externalModuleCardinalities
17-
,count(DISTINCT declaration) AS declarationCount
18-
,sum(rd.cardinality) AS declarationCardinalities
10+
,count(DISTINCT rd) AS declarationCount
11+
,sum(rd.cardinality) AS declarationCardinalities
1912
,collect(DISTINCT declaration.globalFqn)[0..4] AS declarationExamples
20-
OPTIONAL MATCH (source)-[:DECLARES]->(abstraction:TypeAlias|Interface)-[ra:DEPENDS_ON]->(target)
2113
// Get optional low coupling elements (TypeAlias, Interface) that the source module contains and defines (low level) that depend on the external module (target)
14+
OPTIONAL MATCH (source)-[:DECLARES]->(abstraction:TypeAlias|Interface)-[ra:DEPENDS_ON]->(target)
2215
WITH source
2316
,target
2417
,moduleDependency
25-
,externalModuleCount
26-
,externalModuleCardinalities
2718
,declarationCount
2819
,declarationCardinalities
2920
,declarationExamples
30-
,count(DISTINCT abstraction) AS abstractionCount
31-
,sum(ra.cardinality) AS abstractionCardinalities
21+
,count(DISTINCT ra) AS abstractionCount
22+
,sum(ra.cardinality) AS abstractionCardinalities
3223
,collect(DISTINCT abstraction.globalFqn)[0..4] AS abstractionExamples
33-
OPTIONAL MATCH (source)-[:DECLARES]->(implementation:!TypeAlias&!Interface)-[ri:DEPENDS_ON]->(target)
3424
// Get optional higher coupling elements (Class, Function) that the source module contains and defines (low level) that depend on the external module (target)
25+
OPTIONAL MATCH (source)-[:DECLARES]->(implementation:!TypeAlias&!Interface)-[ri:DEPENDS_ON]->(target)
3526
WITH source
3627
,target
3728
,moduleDependency
38-
,externalModuleCount
39-
,externalModuleCardinalities
4029
,declarationCount
4130
,declarationCardinalities
4231
,declarationExamples
4332
,abstractionCount
4433
,abstractionCardinalities
4534
,abstractionExamples
46-
,count(DISTINCT implementation) AS implementationCount
47-
,sum(ri.cardinality) AS implementationCardinalities
35+
,count(DISTINCT ri) AS implementationCount
36+
,sum(ri.cardinality) AS implementationCardinalities
4837
,collect(DISTINCT implementation.globalFqn)[0..4] AS implementationExamples
4938
// Set additional fine grained relationship properties (weights) to distinguish low and high coupling elements.
5039
// The "cardinality" property is similar to "weight" property for Java dependencies and comes from the jQAssistant Typescript Plugin.
51-
// - "weightLowCouplingElements" is the sum of all TypeAlias, Interface and external declaration cardinalities
40+
// - "lowCouplingElementWeight" is the sum of all TypeAlias, Interface and external declaration cardinalities
5241
// and corresponds to the "weightInterfaces" relationship property for Java.
53-
// - "weight25PercentLowCouplingElements" only takes 25% of the weight for elements that are considered as low coupling
42+
// - "lowCouplingElement25PercentWeight" only takes 25% of the weight for elements that are considered as low coupling
5443
// like Type Declarations and Interfaces and adds the unchanged (100%) weight of "high coupling" elements like Functions and Classes.
55-
SET moduleDependency.weightDeclarations = declarationCardinalities
56-
,moduleDependency.weightAbstractions = abstractionCardinalities
57-
,moduleDependency.weightImplementations = implementationCardinalities
58-
,moduleDependency.weightLowCouplingElements = declarationCardinalities + abstractionCardinalities
59-
,moduleDependency.weight25PercentLowCouplingElements = toInteger(implementationCardinalities + round((declarationCardinalities + abstractionCardinalities) * 0.25))
60-
,moduleDependency.weight10PercentLowCouplingElements = toInteger(implementationCardinalities + round((declarationCardinalities + abstractionCardinalities) * 0.10))
44+
SET moduleDependency.declarationCount = declarationCount
45+
,moduleDependency.abstractionCount = abstractionCount
46+
,moduleDependency.implementationCount = implementationCount
47+
,moduleDependency.declarationWeight = declarationCardinalities
48+
,moduleDependency.abstractionWeight = abstractionCardinalities
49+
,moduleDependency.implementationWeight = implementationCardinalities
50+
,moduleDependency.lowCouplingElementWeight = declarationCardinalities + abstractionCardinalities
51+
,moduleDependency.lowCouplingElement25PercentWeight = toInteger(implementationCardinalities + round((declarationCardinalities + abstractionCardinalities) * 0.25))
52+
,moduleDependency.lowCouplingElement10PercentWeight = toInteger(implementationCardinalities + round((declarationCardinalities + abstractionCardinalities) * 0.10))
6153
// Aggregate all gathered information for each (grouped by) source module
6254
WITH source
63-
,source.globalFqn AS sourceGlobalName
64-
,source.localFqn AS sourceLocalName
65-
,sum(externalModuleCount) AS externalModuleCount
66-
,sum(declarationCount) AS declarationCount
67-
,sum(abstractionCount) AS abstractionCount
68-
,sum(implementationCount) AS implementationCount
69-
,sum(externalModuleCardinalities) AS externalModuleCardinalities
70-
,sum(declarationCardinalities) AS declarationCardinalities
71-
,sum(abstractionCardinalities) AS abstractionCardinalities
72-
,sum(implementationCardinalities) AS implementationCardinalities
55+
,source.globalFqn AS sourceGlobalName
56+
,source.localFqn AS sourceLocalName
57+
,count(DISTINCT target.globalFqn) AS externalModuleCount
58+
,sum(moduleDependency.declarationCount) AS declarationCount
59+
,sum(moduleDependency.abstractionCount) AS abstractionCount
60+
,sum(moduleDependency.implementationCount) AS implementationCount
61+
,sum(moduleDependency.cardinality) AS externalModuleCardinalities
62+
,sum(moduleDependency.declarationWeight) AS declarationCardinalities
63+
,sum(moduleDependency.abstractionWeight) AS abstractionCardinalities
64+
,sum(moduleDependency.implementationWeight) AS implementationCardinalities
7365
,collect(DISTINCT target.globalFqn)[0..4] AS externalModuleExamples
7466
,apoc.coll.flatten(collect(declarationExamples))[0..4] AS declarationExamples
7567
,apoc.coll.flatten(collect(abstractionExamples))[0..4] AS abstractionExamples
7668
,apoc.coll.flatten(collect(implementationExamples))[0..4] AS implementationExamples
77-
SET source.outgoingDependencies = declarationCount + abstractionCount + implementationCount
78-
,source.outgoingDependenciesWeight = declarationCardinalities + abstractionCardinalities + implementationCardinalities
79-
,source.outgoingDependentImplementations = implementationCount
80-
,source.outgoingDependentLowCouplingElements = declarationCount + abstractionCount
81-
,source.outgoingDependentModules = externalModuleCount
69+
SET source.outgoingDependencies = declarationCount + abstractionCount + implementationCount
70+
,source.outgoingDependenciesWeight = declarationCardinalities + abstractionCardinalities + implementationCardinalities
71+
,source.outgoingDependentImplementations = implementationCount
72+
,source.outgoingDependentLowCouplingElements = declarationCount + abstractionCount
73+
,source.outgoingDependentModules = externalModuleCount
8274
RETURN sourceGlobalName
8375
,sourceLocalName
8476
,externalModuleCount
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Add weight10PercentInterfaces to Package DEPENDS_ON relationships
22

3-
MATCH (package:Package)-[r:DEPENDS_ON]->(dependent:Package)
3+
MATCH (package:Java:Package)-[r:DEPENDS_ON]->(dependent:Java:Package)
44
WITH package, r
55
,toInteger(r.weight - round(r.weightInterfaces * 0.90)) AS weight10PercentInterfaces
66
SET r.weight10PercentInterfaces = weight10PercentInterfaces
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Add weight25PercentInterfaces to Package DEPENDS_ON relationships
22

3-
MATCH (package:Package)-[r:DEPENDS_ON]->(dependent:Package)
3+
MATCH (package:Java:Package)-[r:DEPENDS_ON]->(dependent:Java:Package)
44
WITH package, r
55
,toInteger(r.weight - round(r.weightInterfaces * 0.75)) AS weight25PercentInterfaces
66
SET r.weight25PercentInterfaces = weight25PercentInterfaces
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Add weight property for Interface Dependencies to Package DEPENDS_ON Relationship
22

3-
MATCH (sourcePackage:Package)-[packageDependency:DEPENDS_ON]->(dependentPackage:Package)
3+
MATCH (sourcePackage:Java:Package)-[packageDependency:DEPENDS_ON]->(dependentPackage:Java:Package)
44
MATCH (sourcePackage)-[:CONTAINS]->(sourceType:Type)
55
OPTIONAL MATCH (sourceType:Type)-[typeDependency:DEPENDS_ON]->(dependentInterface:Interface)<-[:CONTAINS]-(dependentPackage)
66
WHERE sourcePackage.fqn <> dependentPackage.fqn
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Add weight property to Package DEPENDS_ON Relationship
22

3-
MATCH (sourcePackage:Package)-[:CONTAINS]->(sourceType:Type)-[typeDependency:DEPENDS_ON]->(dependentType:Type)<-[:CONTAINS]-(dependentPackage:Package)
3+
MATCH (sourcePackage:Java:Package)-[:CONTAINS]->(sourceType:Type)-[typeDependency:DEPENDS_ON]->(dependentType:Type)<-[:CONTAINS]-(dependentPackage:Java:Package)
44
MATCH (sourcePackage)-[packageDependency:DEPENDS_ON]->(dependentPackage)
55
WHERE sourcePackage.fqn <> dependentPackage.fqn
66
WITH packageDependency
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Add "module" property to ExternalModule nodes for Typescript
2+
3+
MATCH (ext:TS:ExternalModule)
4+
WITH ext
5+
,reverse(split(reverse(ext.globalFqn), '/')[0]) AS moduleName
6+
SET ext.module = moduleName
7+
RETURN moduleName, ext.globalFqn
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Add "name" and "module" properties to ExternalDeclaration nodes for Typescript
2+
3+
MATCH (ext:TS:ExternalDeclaration)
4+
WITH ext
5+
,replace(split(ext.globalFqn, '".')[0],'"', '') AS moduleName
6+
,split(ext.globalFqn, '".')[1] AS symbolName
7+
SET ext.name = symbolName
8+
,ext.module = moduleName
9+
RETURN moduleName, symbolName
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Explore Typescript Projects
2+
3+
MATCH (project:TS:Project)-[:HAS_ROOT]->(dir:Directory)-[:CONTAINS]->(module:Module)
4+
OPTIONAL MATCH (project)<-[:REFERENCED_PROJECTS*]-(top:TS:Project)
5+
RETURN project, dir, module, top
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Set outgoing Typscript Module dependencies
2+
3+
// Get the top level dependency between a Typescript module and the external modules it uses
4+
MATCH (source:TS:Module)-[moduleDependency:DEPENDS_ON]->(target:ExternalModule)
5+
OPTIONAL MATCH (projectdir:Directory)<-[:HAS_ROOT]-(project:TS:Project)-[:CONTAINS]->(:TS:Module{globalFqn: target.globalFqn})
6+
// Aggregate all gathered information for each (grouped by) source module
7+
WITH source
8+
,source.globalFqn AS sourceGlobalName
9+
,source.localFqn AS sourceLocalName
10+
,collect(DISTINCT projectdir.absoluteFileName) AS projectNames
11+
,count(DISTINCT target.globalFqn) AS externalModuleCount
12+
,sum(moduleDependency.declarationCount) AS declarationCount
13+
,sum(moduleDependency.abstractionCount) AS abstractionCount
14+
,sum(moduleDependency.implementationCount) AS implementationCount
15+
,sum(moduleDependency.declarationWeight) AS declarationCardinalities
16+
,sum(moduleDependency.abstractionWeight) AS abstractionCardinalities
17+
,sum(moduleDependency.implementationWeight) AS implementationCardinalities
18+
,collect(DISTINCT target.globalFqn)[0..4] AS externalModuleExamples
19+
SET source.outgoingDependencies = declarationCount + abstractionCount + implementationCount
20+
,source.outgoingDependenciesWeight = declarationCardinalities + abstractionCardinalities + implementationCardinalities
21+
,source.outgoingDependentImplementations = implementationCount
22+
,source.outgoingDependentDeclarations = declarationCount
23+
,source.outgoingDependentAbstractElements = abstractionCount
24+
,source.outgoingDependentLowCouplingElements = declarationCount + abstractionCount
25+
,source.outgoingDependentModules = externalModuleCount
26+
,source.outgoingDependentPackages = size(projectNames)
27+
RETURN sourceGlobalName
28+
,sourceLocalName
29+
,size(projectNames) AS projects
30+
,source.outgoingDependencies
31+
,source.outgoingDependenciesWeight
32+
,source.outgoingDependentImplementations
33+
,source.outgoingDependentDeclarations
34+
,source.outgoingDependentAbstractElements
35+
,source.outgoingDependentLowCouplingElements
36+
,source.outgoingDependentModules
37+
,declarationCardinalities
38+
,abstractionCardinalities
39+
,implementationCardinalities
40+
,externalModuleExamples
41+
,projectNames
42+
ORDER BY sourceGlobalName ASC

scripts/prepareAnalysis.sh

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ source "${SCRIPTS_DIR}/executeQueryFunctions.sh"
3131
source "${SCRIPTS_DIR}/parseCsvFunctions.sh"
3232

3333
# Local Constants
34-
PACKAGE_WEIGHTS_CYPHER_DIR="$CYPHER_DIR/Package_Relationship_Weights"
35-
PACKAGE_METRICS_CYPHER_DIR="$CYPHER_DIR/Metrics"
34+
DEPENDS_ON_CYPHER_DIR="$CYPHER_DIR/DependsOn_Relationship_Weights"
35+
METRICS_CYPHER_DIR="$CYPHER_DIR/Metrics"
3636
EXTERNAL_DEPENDENCIES_CYPHER_DIR="$CYPHER_DIR/External_Dependencies"
3737
ARTIFACT_DEPENDENCIES_CYPHER_DIR="$CYPHER_DIR/Artifact_Dependencies"
3838
TYPES_CYPHER_DIR="$CYPHER_DIR/Types"
@@ -52,15 +52,23 @@ execute_cypher "${CYPHER_DIR}/Create_index_for_full_qualified_type_name.cypher"
5252
# execute_cypher "${CYPHER_DIR}/Create_a_DEPENDS_ON_relationship_for_every_DEPENDS_ON_PACKAGE.cypher"
5353
# execute_cypher "${CYPHER_DIR}/Create_a_DEPENDS_ON_relationship_for_every_DEPENDS_ON_ARTIFACT.cypher"
5454

55-
# Preparation - Add weights to package DEPENDS_ON relationships
56-
execute_cypher_expect_results "${PACKAGE_WEIGHTS_CYPHER_DIR}/Add_weight_property_for_Interface_Dependencies_to_Package_DEPENDS_ON_Relationship.cypher"
57-
execute_cypher_expect_results "${PACKAGE_WEIGHTS_CYPHER_DIR}/Add_weight_property_to_Package_DEPENDS_ON_Relationship.cypher"
58-
execute_cypher_expect_results "${PACKAGE_WEIGHTS_CYPHER_DIR}/Add_weight25PercentInterfaces_to_Package_DEPENDS_ON_relationships.cypher"
59-
execute_cypher_expect_results "${PACKAGE_WEIGHTS_CYPHER_DIR}/Add_weight10PercentInterfaces_to_Package_DEPENDS_ON_relationships.cypher"
55+
# Preparation - Add weights to Java Package DEPENDS_ON relationships
56+
execute_cypher "${DEPENDS_ON_CYPHER_DIR}/Add_weight_property_for_Java_Interface_Dependencies_to_Package_DEPENDS_ON_Relationship.cypher"
57+
execute_cypher "${DEPENDS_ON_CYPHER_DIR}/Add_weight_property_to_Java_Package_DEPENDS_ON_Relationship.cypher"
58+
execute_cypher "${DEPENDS_ON_CYPHER_DIR}/Add_weight25PercentInterfaces_to_Java_Package_DEPENDS_ON_relationships.cypher"
59+
execute_cypher "${DEPENDS_ON_CYPHER_DIR}/Add_weight10PercentInterfaces_to_Java_Package_DEPENDS_ON_relationships.cypher"
6060

61-
# Preparation - Add Package node properties "incomingDependencies" and "outgoingDependencies"
62-
execute_cypher_expect_results "${PACKAGE_METRICS_CYPHER_DIR}/Set_Incoming_Package_Dependencies.cypher"
63-
execute_cypher_expect_results "${PACKAGE_METRICS_CYPHER_DIR}/Set_Outgoing_Package_Dependencies.cypher"
61+
# Preparation - Add weights to Typescript Module DEPENDS_ON relationships
62+
execute_cypher "${DEPENDS_ON_CYPHER_DIR}/Add_fine_grained_weights_for_Typescript_module_dependencies.cypher"
63+
64+
# Preparation - Add Typescript Module node properties "incomingDependencies" and "outgoingDependencies"
65+
# TODO Implement incoming (and outgoing) dependencies
66+
#execute_cypher "${METRICS_CYPHER_DIR}/Set_Incoming_Typescript_Module_Dependencies.cypher"
67+
execute_cypher "${METRICS_CYPHER_DIR}/Set_Outgoing_Typescript_Module_Dependencies.cypher"
68+
69+
# Preparation - Add Java Package node properties "incomingDependencies" and "outgoingDependencies"
70+
execute_cypher "${METRICS_CYPHER_DIR}/Set_Incoming_Java_Package_Dependencies.cypher"
71+
execute_cypher "${METRICS_CYPHER_DIR}/Set_Outgoing_Java_Package_Dependencies.cypher"
6472

6573
# Preparation - Label external types and annotations
6674
# "external" means that there is no byte code available, not a primitive type and not a java type
@@ -74,11 +82,11 @@ execute_cypher "${EXTERNAL_DEPENDENCIES_CYPHER_DIR}/Remove_external_type_and_ann
7482
execute_cypher "${EXTERNAL_DEPENDENCIES_CYPHER_DIR}/Label_external_types_and_annotations.cypher"
7583

7684
# Preparation - Add Artifact node properties "incomingDependencies" and "outgoingDependencies"
77-
execute_cypher_expect_results "${ARTIFACT_DEPENDENCIES_CYPHER_DIR}/Incoming_Artifact_Dependencies.cypher"
78-
execute_cypher_expect_results "${ARTIFACT_DEPENDENCIES_CYPHER_DIR}/Outgoing_Artifact_Dependencies.cypher"
85+
execute_cypher "${ARTIFACT_DEPENDENCIES_CYPHER_DIR}/Incoming_Artifact_Dependencies.cypher"
86+
execute_cypher "${ARTIFACT_DEPENDENCIES_CYPHER_DIR}/Outgoing_Artifact_Dependencies.cypher"
7987

80-
# Preparation - Add Type node properties "incomingDependencies" and "outgoingDependencies"
81-
execute_cypher_expect_results "${PACKAGE_METRICS_CYPHER_DIR}/Set_Incoming_Type_Dependencies.cypher"
82-
execute_cypher_expect_results "${PACKAGE_METRICS_CYPHER_DIR}/Set_Outgoing_Type_Dependencies.cypher"
88+
# Preparation - Add Java Type node properties "incomingDependencies" and "outgoingDependencies"
89+
execute_cypher "${METRICS_CYPHER_DIR}/Set_Incoming_Java_Type_Dependencies.cypher"
90+
execute_cypher "${METRICS_CYPHER_DIR}/Set_Outgoing_Java_Type_Dependencies.cypher"
8391

8492
echo "prepareAnalysis: Preparation successful"

0 commit comments

Comments
 (0)