Skip to content

Commit d8c05d9

Browse files
authored
Merge pull request #285 from JohT/feature/add-details-to-algorithm-result-code-unit-names
Add details to algorithm result code unit names
2 parents 7fae849 + 47ba715 commit d8c05d9

9 files changed

+59
-28
lines changed

cypher/Centrality/Centrality_10d_Bridges_Stream.cypher

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ CALL gds.bridges.stream($dependencies_projection + '-cleaned')
44
YIELD from, to
55
WITH gds.util.asNode(from) AS fromMember
66
,gds.util.asNode(to) AS toMember
7-
WITH *
8-
,toMember.rootProjectName + '/' + toMember.name AS toMemberNameWithRoot
9-
,fromMember.rootProjectName + '/' + fromMember.name AS fromMemberNameWithRoot
10-
RETURN coalesce(fromMember.fqn, fromMemberNameWithRoot, fromMember.name, fromMember.fileName) AS fromMemberName
11-
,coalesce(toMember.fqn, toMemberNameWithRoot, toMember.name, toMember.fileName) AS toMemberName
7+
WITH *, coalesce(fromMember.declaringType + ': ', '') +
8+
coalesce(fromMember.rootProjectName + '/', '') +
9+
coalesce(fromMember.signature, fromMember.name) AS fromMemberNameWithDetails
10+
WITH *, coalesce(toMember.declaringType + ': ', '') +
11+
coalesce(toMember.rootProjectName + '/', '') +
12+
coalesce(toMember.signature, toMember.name) AS toMemberNameWithDetails
13+
RETURN coalesce(fromMember.fqn, fromMemberNameWithDetails, fromMember.fileName, fromMember.name) AS fromMemberName
14+
,coalesce(toMember.fqn, toMemberNameWithDetails, toMember.fileName, toMember.name) AS toMemberName
1215
,fromMember.incomingDependencies AS fromIncomingDependencies
1316
,fromMember.outgoingDependencies AS fromOutgoingDependencies
1417
,toMember.incomingDependencies AS toIncomingDependencies
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Centrality 9d Hyperlink-Induced Topic Search (HITS) Stream Mutated. Requires "Add_file_name and_extension.cypher".
1+
// Centrality 9d Hyperlink-Induced Topic Search (HITS) Stream Mutated. Requires "Add_file_name and_extension.cypher", "Set_localRootPath_for_modules", "Set_declaring_type_on_method_nodes".
22

33
CALL gds.graph.nodeProperties.stream(
44
$dependencies_projection + '-cleaned'
@@ -10,10 +10,13 @@ CALL gds.graph.nodeProperties.stream(
1010
YIELD nodeId, propertyValue
1111
WITH gds.util.asNode(nodeId) AS codeUnit
1212
,collect(propertyValue) AS values
13-
RETURN DISTINCT coalesce(codeUnit.fqn, codeUnit.fileName, codeUnit.signature, codeUnit.name) AS codeUnitName
14-
,codeUnit.name AS shortCodeUnitName
15-
,values[0] AS centralityHyperlinkInducedTopicSearchAuthority
16-
,values[1] AS centralityHyperlinkInducedTopicSearchHub
13+
WITH *, coalesce(codeUnit.declaringType + ': ', '') +
14+
coalesce(codeUnit.rootProjectName + '/', '') +
15+
coalesce(codeUnit.signature, codeUnit.name) AS codeUnitNameWithDetails
16+
RETURN DISTINCT coalesce(codeUnit.fqn, codeUnitNameWithDetails, codeUnit.fileName, codeUnit.name) AS codeUnitName
17+
,codeUnit.name AS shortCodeUnitName
18+
,values[0] AS centralityHyperlinkInducedTopicSearchAuthority
19+
,values[1] AS centralityHyperlinkInducedTopicSearchHub
1720
,codeUnit.incomingDependencies AS incomingDependencies
1821
,codeUnit.outgoingDependencies AS outgoingDependencies
1922
ORDER BY centralityHyperlinkInducedTopicSearchAuthority DESCENDING, codeUnitName ASCENDING
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Read a property from the projection. Variables: dependencies_projection, dependencies_projection_write_property. Requires "Add_file_name and_extension.cypher".
1+
// Read a property from projected nodes unordered. Variables: dependencies_projection, dependencies_projection_write_property. Requires "Add_file_name and_extension.cypher", "Set_localRootPath_for_modules", "Set_declaring_type_on_method_nodes".
22

33
CALL gds.graph.nodeProperties.stream(
44
$dependencies_projection + '-cleaned'
@@ -8,7 +8,10 @@ YIELD nodeId, nodeProperty, propertyValue
88
WITH gds.util.asNode(nodeId) AS codeUnit
99
,nodeProperty AS propertyName
1010
,propertyValue
11-
RETURN DISTINCT coalesce(codeUnit.fqn, codeUnit.fileName, codeUnit.signature, codeUnit.name) AS codeUnitName
11+
WITH *, coalesce(codeUnit.declaringType + ': ', '') +
12+
coalesce(codeUnit.rootProjectName + '/', '') +
13+
coalesce(codeUnit.signature, codeUnit.name) AS codeUnitNameWithDetails
14+
RETURN DISTINCT coalesce(codeUnit.fqn, codeUnitNameWithDetails, codeUnit.fileName, codeUnit.name) AS codeUnitName
1215
,codeUnit.name AS shortCodeUnitName
1316
,propertyName
1417
,propertyValue
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
// Read a property from the projection into the Graph. Variables: dependencies_projection, dependencies_projection_write_property. Requires "Add_file_name and_extension.cypher".
1+
// Read a property from projected nodes extended by some details. Variables: dependencies_projection, dependencies_projection_write_property. Requires "Add_file_name and_extension.cypher", "Set_localRootPath_for_modules", "Set_declaring_type_on_method_nodes".
22

33
CALL gds.graph.nodeProperties.stream(
44
$dependencies_projection + '-cleaned'
55
,[$dependencies_projection_write_property]
66
)
77
YIELD nodeId, nodeProperty, propertyValue
88
WITH gds.util.asNode(nodeId) AS codeUnit
9-
,nodeProperty AS propertyName
9+
,nodeProperty AS propertyName
1010
,propertyValue
11-
OPTIONAL MATCH (artifact:Artifact)-[:CONTAINS]->(codeUnit)
12-
RETURN DISTINCT coalesce(codeUnit.fqn, codeUnit.fileName, codeUnit.name) AS codeUnitName
11+
WITH *, coalesce(codeUnit.declaringType + ': ', '') +
12+
coalesce(codeUnit.rootProjectName + '/', '') +
13+
coalesce(codeUnit.signature, codeUnit.name) AS codeUnitNameWithDetails
14+
OPTIONAL MATCH (project:Artifact|Project)-[:CONTAINS]->(codeUnit)
15+
RETURN DISTINCT coalesce(codeUnit.fqn, codeUnitNameWithDetails, codeUnit.fileName, codeUnit.name) AS codeUnitName
1316
,codeUnit.name AS shortCodeUnitName
1417
,propertyName
1518
,propertyValue
16-
,coalesce(codeUnit.communityLeidenId, 0) AS communityId // optional, might be null
17-
,coalesce(codeUnit.centralityPageRank, 0.01) AS centrality // optional, might be null
18-
,artifact.name AS owningArtifactName
19+
,coalesce(codeUnit.communityLeidenId, 0) AS communityId // optional, might be null
20+
,coalesce(codeUnit.centralityPageRank, 0.00001) AS centrality // optional, might be null
21+
,project.name AS owningProject

cypher/Dependencies_Projection/Dependencies_8_Stream_Mutated_Grouped.cypher

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Read a property from the projection. Variables: dependencies_projection, dependencies_projection_write_property. Requires "Add_file_name and_extension.cypher".
1+
// Read a property from projected nodes. Variables: dependencies_projection, dependencies_projection_write_property. Requires "Add_file_name and_extension.cypher", "Set_localRootPath_for_modules", "Set_declaring_type_on_method_nodes".
22

33
CALL gds.graph.nodeProperties.stream(
44
$dependencies_projection + '-cleaned'
@@ -8,9 +8,12 @@ YIELD nodeId, nodeProperty, propertyValue
88
WITH gds.util.asNode(nodeId) AS codeUnit
99
,nodeProperty AS propertyName
1010
,propertyValue
11+
WITH *, coalesce(codeUnit.declaringType + ': ', '') +
12+
coalesce(codeUnit.rootProjectName + '/', '') +
13+
coalesce(codeUnit.signature, codeUnit.name) AS codeUnitNameWithDetails
1114
WITH propertyName
1215
,propertyValue
13-
,coalesce(codeUnit.fqn, codeUnit.fileName, codeUnit.name) AS codeUnitName
16+
,coalesce(codeUnit.fqn, codeUnitNameWithDetails, codeUnit.fileName, codeUnit.name) AS codeUnitName
1417
,codeUnit.name AS shortCodeUnitName
1518
WITH propertyName
1619
,propertyValue

cypher/Dependencies_Projection/Dependencies_8_Stream_Mutated_Value_Descending.cypher

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Read a property from the projection and order it by its value descending. Variables: dependencies_projection, dependencies_projection_write_property. Requires "Add_file_name and_extension.cypher".
1+
// Read a property from projected nodes ordered by their value descending. Variables: dependencies_projection, dependencies_projection_write_property. Requires "Add_file_name and_extension.cypher", "Set_localRootPath_for_modules", "Set_declaring_type_on_method_nodes".
22

33
CALL gds.graph.nodeProperties.stream(
44
$dependencies_projection + '-cleaned'
@@ -8,7 +8,10 @@ YIELD nodeId, nodeProperty, propertyValue
88
WITH gds.util.asNode(nodeId) AS codeUnit
99
,nodeProperty AS propertyName
1010
,propertyValue
11-
RETURN DISTINCT coalesce(codeUnit.fqn, codeUnit.fileName, codeUnit.signature, codeUnit.name) AS codeUnitName
11+
WITH *, coalesce(codeUnit.declaringType + ': ', '') +
12+
coalesce(codeUnit.rootProjectName + '/', '') +
13+
coalesce(codeUnit.signature, codeUnit.name) AS codeUnitNameWithDetails
14+
RETURN DISTINCT coalesce(codeUnit.fqn, codeUnitNameWithDetails, codeUnit.fileName, codeUnit.name) AS codeUnitName
1215
,codeUnit.name AS shortCodeUnitName
1316
,propertyName
1417
,propertyValue
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Set property "declaringType" on Method nodes.
2+
3+
MATCH (javaType:Type)-[:DECLARES]->(javaMethod:Method)
4+
SET javaMethod.declaringType = javaType.fqn
5+
RETURN count(DISTINCT javaMethod) AS numberOfMethods
6+
,count(DISTINCT javaType) AS numberOfTypes

scripts/prepareAnalysis.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ execute_cypher_summarized "${METRICS_CYPHER_DIR}/Set_Outgoing_Typescript_Module_
112112
execute_cypher_summarized "${METRICS_CYPHER_DIR}/Set_Incoming_Java_Package_Dependencies.cypher"
113113
execute_cypher_summarized "${METRICS_CYPHER_DIR}/Set_Outgoing_Java_Package_Dependencies.cypher"
114114

115+
# Preparation - Add Java Method node property "declaringType"
116+
execute_cypher "${TYPES_CYPHER_DIR}/Set_declaring_type_on_method_nodes.cypher"
117+
115118
# Preparation - Label external types and annotations
116119
# "external" means that there is no byte code available, not a primitive type and not a java type
117120
# "annotation" means that there is a ANNOTATED_BY to that external type

scripts/reports/CentralityCsv.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ runUndirectedCentralityAlgorithms() {
375375
# -- Java Artifact Centrality ------------------------------------
376376

377377
ARTIFACT_PROJECTION="dependencies_projection=artifact-centrality"
378-
ARTIFACT_PROJECTION_UNDIRECTED="dependencies_projection=${ARTIFACT_PROJECTION}-undirected"
378+
ARTIFACT_PROJECTION_UNDIRECTED="dependencies_projection=artifact-centrality-undirected"
379379
ARTIFACT_NODE="dependencies_projection_node=Artifact"
380380
ARTIFACT_WEIGHT="dependencies_projection_weight_property=weight"
381381

@@ -389,7 +389,7 @@ fi
389389
# -- Java Package Centrality -------------------------------------
390390

391391
PACKAGE_PROJECTION="dependencies_projection=package-centrality"
392-
PACKAGE_PROJECTION_UNDIRECTED="dependencies_projection=${PACKAGE_PROJECTION}-undirected"
392+
PACKAGE_PROJECTION_UNDIRECTED="dependencies_projection=package-centrality-undirected"
393393
PACKAGE_NODE="dependencies_projection_node=Package"
394394
PACKAGE_WEIGHT="dependencies_projection_weight_property=weight25PercentInterfaces"
395395

@@ -402,17 +402,21 @@ fi
402402

403403
# -- Java Type Centrality ----------------------------------------
404404

405-
TYPE_PROJECTION="dependencies_projection=type-centrality"
405+
TYPE_PROJECTION="dependencies_projection=type-centrality"
406+
TYPE_PROJECTION_UNDIRECTED="dependencies_projection=type-centrality-undirected"
406407
TYPE_NODE="dependencies_projection_node=Type"
407408
TYPE_WEIGHT="dependencies_projection_weight_property=weight"
408409

409410
if createDirectedJavaTypeDependencyProjection "${TYPE_PROJECTION}" "${TYPE_NODE}" "${TYPE_WEIGHT}"; then
410411
runCentralityAlgorithms "${TYPE_PROJECTION}" "${TYPE_NODE}" "${TYPE_WEIGHT}"
411412
fi
413+
if createUndirectedJavaTypeDependencyProjection "${TYPE_PROJECTION_UNDIRECTED}"; then
414+
runUndirectedCentralityAlgorithms "${TYPE_PROJECTION_UNDIRECTED}" "${TYPE_NODE}"
415+
fi
412416

413417
# -- Java Method Centrality --------------------------------------
414418

415-
METHOD_PROJECTION="dependencies_projection=method-centrality"
419+
METHOD_PROJECTION="dependencies_projection=method-centrality"
416420
METHOD_NODE="dependencies_projection_node=Method"
417421
METHOD_WEIGHT="dependencies_projection_weight_property="
418422

@@ -424,7 +428,7 @@ fi
424428

425429
MODULE_LANGUAGE="dependencies_projection_language=Typescript"
426430
MODULE_PROJECTION="dependencies_projection=typescript-module-centrality"
427-
MODULE_PROJECTION_UNDIRECTED="dependencies_projection=${MODULE_PROJECTION}-undirected"
431+
MODULE_PROJECTION_UNDIRECTED="dependencies_projection=typescript-module-centrality-undirected"
428432
MODULE_NODE="dependencies_projection_node=Module"
429433
MODULE_WEIGHT="dependencies_projection_weight_property=lowCouplingElement25PercentWeight"
430434

0 commit comments

Comments
 (0)