Skip to content

Commit cf60968

Browse files
committed
Add report for Bridges centrality algorithm
1 parent 1f0d41e commit cf60968

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Centrality 10a Bridges Estimate
2+
3+
CALL gds.bridges.stream.estimate($dependencies_projection + '-cleaned', {})
4+
YIELD nodeCount, relationshipCount, bytesMin, bytesMax, heapPercentageMin, heapPercentageMax, treeView
5+
RETURN nodeCount, relationshipCount, bytesMin, bytesMax, heapPercentageMin, heapPercentageMax, treeView
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Centrality 10d Bridges Stream
2+
3+
CALL gds.bridges.stream($dependencies_projection + '-cleaned')
4+
YIELD from, to
5+
WITH gds.util.asNode(from) AS fromMember
6+
,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
12+
,fromMember.incomingDependencies AS fromIncomingDependencies
13+
,fromMember.outgoingDependencies AS fromOutgoingDependencies
14+
,toMember.incomingDependencies AS toIncomingDependencies
15+
,toMember.outgoingDependencies AS toOutgoingDependencies
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Centrality 10e Bridges Stream - Write Relationship Property "isBridge"
2+
3+
CALL gds.bridges.stream($dependencies_projection + '-cleaned')
4+
YIELD from, to
5+
WITH gds.util.asNode(from) AS fromMember
6+
,gds.util.asNode(to) AS toMember
7+
MATCH (fromMember)-[dependency:DEPENDS_ON]-(toMember)
8+
SET dependency.isBridge = true
9+
RETURN count(*) AS numberOfBridges

scripts/reports/CentralityCsv.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,30 @@ centralityWithHyperlinkInducedTopicSearchHITS() {
306306
execute_cypher "${CENTRALITY_CYPHER_DIR}/Centrality_1d_Label_Add.cypher" "${@}" "${writePropertyName}Hub"
307307
}
308308

309+
# Apply the centrality algorithm "Bridges".
310+
# Requires an undirected graph projection and ignores weights. Thus, no weight property is needed.
311+
#
312+
# Required Parameters:
313+
# - dependencies_projection=...
314+
# Name prefix for the in-memory projection name for dependencies. Example: "type-centrality"
315+
# - dependencies_projection_node=...
316+
# Label of the nodes that will be used for the projection. Example: "Type"
317+
centralityWithBridges() {
318+
local CENTRALITY_CYPHER_DIR="$CYPHER_DIR/Centrality"
319+
local PROJECTION_CYPHER_DIR="$CYPHER_DIR/Dependencies_Projection"
320+
321+
# Statistics
322+
execute_cypher "${CENTRALITY_CYPHER_DIR}/Centrality_10a_Bridges_Estimate.cypher" "${@}" "${writePropertyName}"
323+
324+
# Stream to CSV
325+
local nodeLabel
326+
nodeLabel=$( extractQueryParameter "dependencies_projection_node" "${@}" )
327+
execute_cypher "${CENTRALITY_CYPHER_DIR}/Centrality_10d_Bridges_Stream.cypher" "${@}" > "${FULL_REPORT_DIRECTORY}/${nodeLabel}_Centrality_Bridges.csv"
328+
329+
# Set "isBridge=true" on all relationships identified as Bridge
330+
execute_cypher "${CENTRALITY_CYPHER_DIR}/Centrality_10e_Bridges_Write.cypher" "${@}"
331+
}
332+
309333
listAllResults() {
310334
local CENTRALITY_CYPHER_DIR="$CYPHER_DIR/Centrality"
311335

@@ -334,25 +358,47 @@ runCentralityAlgorithms() {
334358
listAllResults "${@}"
335359
}
336360

361+
# Run all centrality algorithms that require an undirected graph projection.
362+
#
363+
# Required Parameters:
364+
# - dependencies_projection=...
365+
# Name prefix for the in-memory projection name for dependencies. Example: "package"
366+
# - dependencies_projection_node=...
367+
# Label of the nodes that will be used for the projection. Example: "centralityPageRank"
368+
# - dependencies_projection_weight_property=...
369+
# Name of the node property that contains the dependency weight. Example: "weight"
370+
runUndirectedCentralityAlgorithms() {
371+
time centralityWithBridges "${@}"
372+
}
373+
374+
337375
# -- Java Artifact Centrality ------------------------------------
338376

339377
ARTIFACT_PROJECTION="dependencies_projection=artifact-centrality"
378+
ARTIFACT_PROJECTION_UNDIRECTED="dependencies_projection=${ARTIFACT_PROJECTION}-undirected"
340379
ARTIFACT_NODE="dependencies_projection_node=Artifact"
341380
ARTIFACT_WEIGHT="dependencies_projection_weight_property=weight"
342381

343382
if createDirectedDependencyProjection "${ARTIFACT_PROJECTION}" "${ARTIFACT_NODE}" "${ARTIFACT_WEIGHT}"; then
344383
runCentralityAlgorithms "${ARTIFACT_PROJECTION}" "${ARTIFACT_NODE}" "${ARTIFACT_WEIGHT}"
345384
fi
385+
if createUndirectedDependencyProjection "${ARTIFACT_PROJECTION_UNDIRECTED}" "${ARTIFACT_NODE}" "${ARTIFACT_WEIGHT}"; then
386+
runUndirectedCentralityAlgorithms "${ARTIFACT_PROJECTION_UNDIRECTED}" "${ARTIFACT_NODE}"
387+
fi
346388

347389
# -- Java Package Centrality -------------------------------------
348390

349391
PACKAGE_PROJECTION="dependencies_projection=package-centrality"
392+
PACKAGE_PROJECTION_UNDIRECTED="dependencies_projection=${PACKAGE_PROJECTION}-undirected"
350393
PACKAGE_NODE="dependencies_projection_node=Package"
351394
PACKAGE_WEIGHT="dependencies_projection_weight_property=weight25PercentInterfaces"
352395

353396
if createDirectedDependencyProjection "${PACKAGE_PROJECTION}" "${PACKAGE_NODE}" "${PACKAGE_WEIGHT}"; then
354397
runCentralityAlgorithms "${PACKAGE_PROJECTION}" "${PACKAGE_NODE}" "${PACKAGE_WEIGHT}"
355398
fi
399+
if createUndirectedDependencyProjection "${PACKAGE_PROJECTION_UNDIRECTED}" "${PACKAGE_NODE}" "${PACKAGE_WEIGHT}"; then
400+
runUndirectedCentralityAlgorithms "${PACKAGE_PROJECTION_UNDIRECTED}" "${PACKAGE_NODE}"
401+
fi
356402

357403
# -- Java Type Centrality ----------------------------------------
358404

@@ -378,12 +424,16 @@ fi
378424

379425
MODULE_LANGUAGE="dependencies_projection_language=Typescript"
380426
MODULE_PROJECTION="dependencies_projection=typescript-module-centrality"
427+
MODULE_PROJECTION_UNDIRECTED="dependencies_projection=${MODULE_PROJECTION}-undirected"
381428
MODULE_NODE="dependencies_projection_node=Module"
382429
MODULE_WEIGHT="dependencies_projection_weight_property=lowCouplingElement25PercentWeight"
383430

384431
if createDirectedDependencyProjection "${MODULE_LANGUAGE}" "${MODULE_PROJECTION}" "${MODULE_NODE}" "${MODULE_WEIGHT}"; then
385432
runCentralityAlgorithms "${MODULE_PROJECTION}" "${MODULE_NODE}" "${MODULE_WEIGHT}"
386433
fi
434+
if createUndirectedDependencyProjection "${MODULE_LANGUAGE}" "${MODULE_PROJECTION_UNDIRECTED}" "${MODULE_NODE}" "${MODULE_WEIGHT}"; then
435+
runUndirectedCentralityAlgorithms "${MODULE_PROJECTION_UNDIRECTED}" "${MODULE_NODE}"
436+
fi
387437

388438
# ---------------------------------------------------------------
389439

0 commit comments

Comments
 (0)