Skip to content

Commit b2de954

Browse files
committed
Refine type classification and projection filter
1 parent f3197ff commit b2de954

13 files changed

+203
-26
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Create filtered Type node projection without zero-degree nodes, external types, java types or duplicates. Variables: dependencies_projection. Requires 'Label_base_java_types', 'Label_buildin_java_types' and 'Label_resolved_duplicate_types' of 'Types' directory.
2+
3+
MATCH (internalType:Type&!PrimitiveType&!Void&!JavaType&!ResolvedDuplicateType&!ExternalType)
4+
OPTIONAL MATCH (internalType)-[typeDependency:DEPENDS_ON]->(dependentType:Type&!PrimitiveType&!Void&!JavaType&!ResolvedDuplicateType&!ExternalType)
5+
WITH internalType
6+
,typeDependency
7+
,dependentType
8+
,exists((internalType)<-[:DEPENDS_ON]-(:Type)) AS hasIncomingDependenciesInternal
9+
WHERE (hasIncomingDependenciesInternal OR dependentType IS NOT NULL)
10+
WITH gds.graph.project($dependencies_projection + '-cleaned', internalType, dependentType, {
11+
sourceNodeProperties: internalType {.incomingDependencies, .outgoingDependencies}
12+
,targetNodeProperties: dependentType {.incomingDependencies, .outgoingDependencies}
13+
,relationshipProperties: typeDependency {.weight}
14+
,relationshipType: 'DEPENDS_ON'
15+
}
16+
) AS projection
17+
RETURN projection.graphName AS graphName
18+
,projection.nodeCount AS nodeCount
19+
,projection.relationshipCount AS relationshipCount
20+
,projection.projectMillis AS projectMillis
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Create filtered Type node projection without zero-degree nodes, external types, java types or duplicates. Variables: dependencies_projection. Requires 'Label_base_java_types', 'Label_buildin_java_types' and 'Label_resolved_duplicate_types' of 'Types' directory.
2+
3+
MATCH (internalType:Type&!PrimitiveType&!Void&!JavaType&!ResolvedDuplicateType&!ExternalType)
4+
OPTIONAL MATCH (internalType)-[typeDependency:DEPENDS_ON]->(dependentType:Type&!PrimitiveType&!Void&!JavaType&!ResolvedDuplicateType&!ExternalType)
5+
WITH internalType
6+
,typeDependency
7+
,dependentType
8+
,exists((internalType)<-[:DEPENDS_ON]-(:Type)) AS hasIncomingDependenciesInternal
9+
WHERE (hasIncomingDependenciesInternal OR dependentType IS NOT NULL)
10+
WITH gds.graph.project($dependencies_projection + '-cleaned', internalType, dependentType, {
11+
sourceNodeProperties: internalType {.incomingDependencies, .outgoingDependencies}
12+
,targetNodeProperties: dependentType {.incomingDependencies, .outgoingDependencies}
13+
,relationshipProperties: typeDependency {.weight}
14+
,relationshipType: 'DEPENDS_ON'
15+
},
16+
{
17+
undirectedRelationshipTypes: ['*']
18+
}
19+
) AS projection
20+
RETURN projection.graphName AS graphName
21+
,projection.nodeCount AS nodeCount
22+
,projection.relationshipCount AS relationshipCount
23+
,projection.projectMillis AS projectMillis
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
// Label external types and annotations
1+
// Label external types and external annotations. Requires 'Label_base_java_types', 'Label_buildin_java_types' and 'Label_resolved_duplicate_types' of 'Types' directory.
22

3-
MATCH (externalType:Type)
4-
WHERE externalType.byteCodeVersion IS NULL // byte code not available -> external dependency
5-
WITH externalType
6-
,(NOT externalType.fqn CONTAINS '.') AS isPrimitiveType
7-
,(externalType.fqn STARTS WITH 'java.') AS isJavaType
8-
,exists((externalType)-[:RESOLVES_TO]->(:Type)) AS isAlsoInternalType
9-
,exists((externalType)<-[:OF_TYPE]-()<-[:ANNOTATED_BY]-()) AS isAnnotation
10-
WHERE isPrimitiveType = false
11-
AND isJavaType = false
12-
AND isAlsoInternalType = false
13-
WITH externalType
14-
,CASE WHEN isAnnotation THEN [1] ELSE [] END AS annotated
15-
FOREACH (x in annotated | SET externalType:ExternalAnnotation)
16-
SET externalType:ExternalType
17-
RETURN labels(externalType), count(externalType) as numberOfExternalTypes
3+
MATCH (type:Type&!PrimitiveType&!Void&!JavaType&!ResolvedDuplicateType)
4+
WITH type
5+
,type.byteCodeVersion IS NULL AS isExternalType
6+
,exists((type)<-[:OF_TYPE]-()<-[:ANNOTATED_BY]-()) AS isAnnotation
7+
WITH type
8+
,isExternalType
9+
,CASE WHEN isAnnotation THEN [1] ELSE [] END AS annotation
10+
WHERE isExternalType
11+
FOREACH (x in annotation | SET type:ExternalAnnotation)
12+
SET type:ExternalType
13+
RETURN labels(type), count(type) as numberOfExternalTypes

cypher/Overview/Words_for_Wordcloud.cypher

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
MATCH (package:Package)
44
WITH collect(package.name) AS packageNames
5-
MATCH (type:Type)
6-
WHERE type.byteCodeVersion IS NOT NULL // no external types
7-
AND NOT type.fqn STARTS WITH 'java.' // no java types
8-
AND type.name <> 'package-info' // not package-info files
5+
MATCH (type:Type&!PrimitiveType&!Void&!JavaType&!ResolvedDuplicateType&!ExternalType)
6+
WHERE type.name <> 'package-info' // not package-info files
97
WITH packageNames, split(type.name, '$') AS splittedInnerClasses
108
UNWIND splittedInnerClasses AS splittedInnerClass
119
WITH packageNames
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Label primitive Java types and void
2+
3+
MATCH (type:Type)
4+
WITH type
5+
,type.fqn in ['byte', 'short', 'int', 'long', 'float', 'double', 'boolean', 'char'] AS isPrimitiveType
6+
,type.fqn = 'void' AS isVoid
7+
WITH type
8+
,isPrimitiveType
9+
,isVoid
10+
,CASE WHEN isPrimitiveType THEN [1] ELSE [] END AS primitive
11+
,CASE WHEN isVoid THEN [1] ELSE [] END AS void
12+
WHERE isPrimitiveType OR isVoid
13+
FOREACH (x in primitive | SET type:PrimitiveType)
14+
FOREACH (x in void | SET type:Void)
15+
RETURN labels(type), count(type) as numberOfBaseTypes
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Label build-in Java types
2+
3+
MATCH (t:Type)
4+
WITH t
5+
,CASE WHEN (t.fqn STARTS WITH 'java.') THEN true
6+
WHEN (t.fqn STARTS WITH 'com.sun.') THEN true
7+
WHEN (t.fqn STARTS WITH 'javax.accessibility') THEN true
8+
WHEN (t.fqn STARTS WITH 'javax.annotation.processing') THEN true
9+
WHEN (t.fqn STARTS WITH 'javax.crypto') THEN true
10+
WHEN (t.fqn STARTS WITH 'javax.lang.model') THEN true
11+
WHEN (t.fqn STARTS WITH 'javax.management') THEN true
12+
WHEN (t.fqn STARTS WITH 'javax.naming') THEN true
13+
WHEN (t.fqn STARTS WITH 'javax.net') THEN true
14+
WHEN (t.fqn STARTS WITH 'javax.print') THEN true
15+
WHEN (t.fqn STARTS WITH 'javax.rmi.ssl') THEN true
16+
WHEN (t.fqn STARTS WITH 'javax.script') THEN true
17+
WHEN (t.fqn STARTS WITH 'javax.security.') THEN true
18+
WHEN (t.fqn STARTS WITH 'javax.smartcardio') THEN true
19+
WHEN (t.fqn STARTS WITH 'javax.sound.') THEN true
20+
WHEN (t.fqn STARTS WITH 'javax.sql') THEN true
21+
WHEN (t.fqn STARTS WITH 'javax.swing') THEN true
22+
WHEN (t.fqn STARTS WITH 'javax.tools') THEN true
23+
WHEN (t.fqn STARTS WITH 'javax.transaction.xa') THEN true
24+
WHEN (t.fqn STARTS WITH 'javax.xml') THEN true
25+
WHEN (t.fqn STARTS WITH 'jdk.') THEN true
26+
WHEN (t.fqn STARTS WITH 'netscape.javascript') THEN true
27+
WHEN (t.fqn STARTS WITH 'org.ietf.jgss') THEN true
28+
WHEN (t.fqn STARTS WITH 'org.w3c.dom') THEN true
29+
WHEN (t.fqn STARTS WITH 'org.xml.sax') THEN true
30+
ELSE false
31+
END AS isJavaType
32+
WHERE isJavaType
33+
SET t:JavaType
34+
RETURN labels(t), count(t) as numberOfJavaTypes
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Label resolved duplicate types.
2+
3+
MATCH (type:Type)
4+
WITH type, exists((type)-[:RESOLVES_TO]->(:Type)) AS isResolvedDuplicate
5+
WHERE isResolvedDuplicate
6+
SET type:ResolvedDuplicateType
7+
RETURN labels(type), count(type) as numberOfResolvedDuplicateTypes
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Remove external type and annotation labels
2+
3+
MATCH (extendedLabeledType:JavaType|PrimitiveType|Void|ResolvedDuplicateType)
4+
REMOVE extendedLabeledType:JavaType:PrimitiveType:Void:ResolvedDuplicateType

scripts/prepareAnalysis.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ PACKAGE_WEIGHTS_CYPHER_DIR="$CYPHER_DIR/Package_Relationship_Weights"
3232
PACKAGE_METRICS_CYPHER_DIR="$CYPHER_DIR/Metrics"
3333
EXTERNAL_DEPENDENCIES_CYPHER_DIR="$CYPHER_DIR/External_Dependencies"
3434
ARTIFACT_DEPENDENCIES_CYPHER_DIR="$CYPHER_DIR/Artifact_Dependencies"
35+
TYPES_CYPHER_DIR="$CYPHER_DIR/Types"
3536

3637
# Preparation - Create indizes
3738
execute_cypher "${CYPHER_DIR}/Create_index_for_full_qualified_type_name.cypher"
@@ -53,6 +54,11 @@ execute_cypher_expect_results "${PACKAGE_METRICS_CYPHER_DIR}/Set_Outgoing_Packag
5354
# Preparation - Label external types and annotations
5455
# "external" means that there is no byte code available, not a primitive type and not a java type
5556
# "annoatation" means that there is a ANNOTATED_BY to that external type
57+
execute_cypher "${TYPES_CYPHER_DIR}/Remove_extended_type_labels.cypher"
58+
execute_cypher "${TYPES_CYPHER_DIR}/Label_base_java_types.cypher"
59+
execute_cypher "${TYPES_CYPHER_DIR}/Label_buildin_java_types.cypher"
60+
execute_cypher "${TYPES_CYPHER_DIR}/Label_resolved_duplicate_types.cypher"
61+
5662
execute_cypher "${EXTERNAL_DEPENDENCIES_CYPHER_DIR}/Remove_external_type_and_annotation_labels.cypher"
5763
execute_cypher "${EXTERNAL_DEPENDENCIES_CYPHER_DIR}/Label_external_types_and_annotations.cypher"
5864

@@ -62,4 +68,6 @@ execute_cypher_expect_results "${ARTIFACT_DEPENDENCIES_CYPHER_DIR}/Outgoing_Arti
6268

6369
# Preparation - Add Type node properties "incomingDependencies" and "outgoingDependencies"
6470
execute_cypher_expect_results "${PACKAGE_METRICS_CYPHER_DIR}/Set_Incoming_Type_Dependencies.cypher"
65-
execute_cypher_expect_results "${PACKAGE_METRICS_CYPHER_DIR}/Set_Outgoing_Type_Dependencies.cypher"
71+
execute_cypher_expect_results "${PACKAGE_METRICS_CYPHER_DIR}/Set_Outgoing_Type_Dependencies.cypher"
72+
73+
echo "prepareAnalysis: Preparation successful"

scripts/reports/CentralityCsv.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ createDependencyProjection() {
5656
execute_cypher "${PROJECTION_CYPHER_DIR}/Dependencies_5_Create_Subgraph.cypher" "${@}"
5757
}
5858

59+
# Centrality preparation for Type nodes
60+
# Selects the Type nodes and relationships for the algorithm and creates an in-memory projection.
61+
# Nodes without incoming and outgoing dependencies will be filtered out with a subgraph.
62+
#
63+
# Required Parameters:
64+
# - dependencies_projection=...
65+
# Name prefix for the in-memory projection name for dependencies. Example: "package"
66+
createTypeProjection() {
67+
local PROJECTION_CYPHER_DIR="$CYPHER_DIR/Dependencies_Projection"
68+
69+
execute_cypher "${PROJECTION_CYPHER_DIR}/Dependencies_2_Delete_Subgraph.cypher" "${@}"
70+
execute_cypher "${PROJECTION_CYPHER_DIR}/Dependencies_3c_Create_Type_Projection.cypher" "${@}"
71+
}
72+
5973
# Centrality preparation for method calls
6074
# Selects the method nodes and relationships for the algorithm and creates an in-memory projection.
6175
# Nodes without incoming and outgoing dependencies will be filtered out with a subgraph.
@@ -399,7 +413,7 @@ TYPE_WEIGHT="dependencies_projection_weight_property=weight"
399413

400414
# Type Centrality
401415
echo "centralityCsv: $(date +'%Y-%m-%dT%H:%M:%S%z') Processing type dependencies..."
402-
createDependencyProjection "${TYPE_PROJECTION}" "${TYPE_NODE}" "${TYPE_WEIGHT}"
416+
createTypeProjection "${TYPE_PROJECTION}" "${TYPE_NODE}" "${TYPE_WEIGHT}"
403417
runCentralityAlgorithms "${TYPE_PROJECTION}" "${TYPE_NODE}" "${TYPE_WEIGHT}"
404418

405419
# ---------------------------------------------------------------

0 commit comments

Comments
 (0)