Skip to content

Commit da4f2f8

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

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Centrality 10a Bridges Estimate
2+
3+
CALL gds.bridges.stream.estimate(
4+
$dependencies_projection + '-cleaned', {
5+
})
6+
YIELD nodeCount, relationshipCount, bytesMin, bytesMax, heapPercentageMin, heapPercentageMax, treeView
7+
RETURN nodeCount, relationshipCount, bytesMin, bytesMax, heapPercentageMin, heapPercentageMax, treeView
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Centrality 10d Bridges Stream
2+
3+
CALL gds.bridges.stream(
4+
$dependencies_projection + '-cleaned', {
5+
})
6+
YIELD from, to
7+
WITH gds.util.asNode(from) AS fromMember
8+
,gds.util.asNode(to) AS toMember
9+
WITH *
10+
,toMember.rootProjectName + '/' + toMember.name AS toMemberNameWithRoot
11+
,fromMember.rootProjectName + '/' + fromMember.name AS fromMemberNameWithRoot
12+
RETURN coalesce(fromMember.fqn, fromMemberNameWithRoot, fromMember.name, fromMember.fileName) AS fromMemberName
13+
,coalesce(toMember.fqn, toMemberNameWithRoot, toMember.name, toMember.fileName) AS toMemberName
14+
,fromMember.incomingDependencies AS fromIncomingDependencies
15+
,fromMember.outgoingDependencies AS fromOutgoingDependencies
16+
,toMember.incomingDependencies AS toIncomingDependencies
17+
,toMember.outgoingDependencies AS toOutgoingDependencies

scripts/reports/CentralityCsv.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,29 @@ 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+
# TODO Update Graph (mark bridge relationships)
330+
}
331+
309332
listAllResults() {
310333
local CENTRALITY_CYPHER_DIR="$CYPHER_DIR/Centrality"
311334

@@ -334,25 +357,47 @@ runCentralityAlgorithms() {
334357
listAllResults "${@}"
335358
}
336359

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

339376
ARTIFACT_PROJECTION="dependencies_projection=artifact-centrality"
377+
ARTIFACT_PROJECTION_UNDIRECTED="dependencies_projection=${ARTIFACT_PROJECTION}-undirected"
340378
ARTIFACT_NODE="dependencies_projection_node=Artifact"
341379
ARTIFACT_WEIGHT="dependencies_projection_weight_property=weight"
342380

343381
if createDirectedDependencyProjection "${ARTIFACT_PROJECTION}" "${ARTIFACT_NODE}" "${ARTIFACT_WEIGHT}"; then
344382
runCentralityAlgorithms "${ARTIFACT_PROJECTION}" "${ARTIFACT_NODE}" "${ARTIFACT_WEIGHT}"
345383
fi
384+
if createUndirectedDependencyProjection "${ARTIFACT_PROJECTION_UNDIRECTED}" "${ARTIFACT_NODE}" "${ARTIFACT_WEIGHT}"; then
385+
runUndirectedCentralityAlgorithms "${ARTIFACT_PROJECTION_UNDIRECTED}" "${ARTIFACT_NODE}"
386+
fi
346387

347388
# -- Java Package Centrality -------------------------------------
348389

349390
PACKAGE_PROJECTION="dependencies_projection=package-centrality"
391+
PACKAGE_PROJECTION_UNDIRECTED="dependencies_projection=${PACKAGE_PROJECTION}-undirected"
350392
PACKAGE_NODE="dependencies_projection_node=Package"
351393
PACKAGE_WEIGHT="dependencies_projection_weight_property=weight25PercentInterfaces"
352394

353395
if createDirectedDependencyProjection "${PACKAGE_PROJECTION}" "${PACKAGE_NODE}" "${PACKAGE_WEIGHT}"; then
354396
runCentralityAlgorithms "${PACKAGE_PROJECTION}" "${PACKAGE_NODE}" "${PACKAGE_WEIGHT}"
355397
fi
398+
if createUndirectedDependencyProjection "${PACKAGE_PROJECTION_UNDIRECTED}" "${PACKAGE_NODE}" "${PACKAGE_WEIGHT}"; then
399+
runUndirectedCentralityAlgorithms "${PACKAGE_PROJECTION_UNDIRECTED}" "${PACKAGE_NODE}"
400+
fi
356401

357402
# -- Java Type Centrality ----------------------------------------
358403

@@ -378,12 +423,16 @@ fi
378423

379424
MODULE_LANGUAGE="dependencies_projection_language=Typescript"
380425
MODULE_PROJECTION="dependencies_projection=typescript-module-centrality"
426+
MODULE_PROJECTION_UNDIRECTED="dependencies_projection=${MODULE_PROJECTION}-undirected"
381427
MODULE_NODE="dependencies_projection_node=Module"
382428
MODULE_WEIGHT="dependencies_projection_weight_property=lowCouplingElement25PercentWeight"
383429

384430
if createDirectedDependencyProjection "${MODULE_LANGUAGE}" "${MODULE_PROJECTION}" "${MODULE_NODE}" "${MODULE_WEIGHT}"; then
385431
runCentralityAlgorithms "${MODULE_PROJECTION}" "${MODULE_NODE}" "${MODULE_WEIGHT}"
386432
fi
433+
if createUndirectedDependencyProjection "${MODULE_LANGUAGE}" "${MODULE_PROJECTION_UNDIRECTED}" "${MODULE_NODE}" "${MODULE_WEIGHT}"; then
434+
runUndirectedCentralityAlgorithms "${MODULE_PROJECTION_UNDIRECTED}" "${MODULE_NODE}"
435+
fi
387436

388437
# ---------------------------------------------------------------
389438

0 commit comments

Comments
 (0)