diff --git a/algo/src/main/java/org/neo4j/gds/algorithms/centrality/CentralityAlgorithmsMutateBusinessFacade.java b/algo/src/main/java/org/neo4j/gds/algorithms/centrality/CentralityAlgorithmsMutateBusinessFacade.java index 5d68444ea2..d2a4bc5e6a 100644 --- a/algo/src/main/java/org/neo4j/gds/algorithms/centrality/CentralityAlgorithmsMutateBusinessFacade.java +++ b/algo/src/main/java/org/neo4j/gds/algorithms/centrality/CentralityAlgorithmsMutateBusinessFacade.java @@ -30,7 +30,6 @@ import org.neo4j.gds.algorithms.runner.AlgorithmRunner; import org.neo4j.gds.config.MutateNodePropertyConfig; import org.neo4j.gds.core.concurrency.DefaultPool; -import org.neo4j.gds.harmonic.HarmonicCentralityMutateConfig; import org.neo4j.gds.influenceMaximization.CELFNodeProperties; import org.neo4j.gds.influenceMaximization.InfluenceMaximizationMutateConfig; import org.neo4j.gds.pagerank.PageRankMutateConfig; @@ -54,24 +53,6 @@ public CentralityAlgorithmsMutateBusinessFacade( this.mutateNodePropertyService = mutateNodePropertyService; } - public NodePropertyMutateResult harmonicCentrality( - String graphName, - HarmonicCentralityMutateConfig configuration, - boolean shouldComputeCentralityDistribution - ) { - // 1. Run the algorithm and time the execution - var intermediateResult = AlgorithmRunner.runWithTiming( - () -> centralityAlgorithmsFacade.harmonicCentrality(graphName, configuration) - ); - - return mutateNodeProperty( - intermediateResult.algorithmResult, - configuration, - shouldComputeCentralityDistribution, - intermediateResult.computeMilliseconds - ); - } - public NodePropertyMutateResult pageRank( String graphName, PageRankMutateConfig configuration, diff --git a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithms.java b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithms.java index ac7b765e9a..8ee75889a5 100644 --- a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithms.java +++ b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithms.java @@ -39,6 +39,9 @@ import org.neo4j.gds.degree.DegreeCentrality; import org.neo4j.gds.degree.DegreeCentralityConfig; import org.neo4j.gds.degree.DegreeCentralityResult; +import org.neo4j.gds.harmonic.HarmonicCentrality; +import org.neo4j.gds.harmonic.HarmonicCentralityBaseConfig; +import org.neo4j.gds.harmonic.HarmonicResult; import org.neo4j.gds.termination.TerminationFlag; public class CentralityAlgorithms { @@ -127,4 +130,18 @@ DegreeCentralityResult degreeCentrality(Graph graph, DegreeCentralityConfig conf return algorithmMachinery.runAlgorithmsAndManageProgressTracker(algorithm, progressTracker, true); } + + HarmonicResult harmonicCentrality(Graph graph, HarmonicCentralityBaseConfig configuration) { + var task = Tasks.leaf(LabelForProgressTracking.HarmonicCentrality.value); + var progressTracker = progressTrackerCreator.createProgressTracker(configuration, task); + + var algorithm = new HarmonicCentrality( + graph, + configuration.concurrency(), + DefaultPool.INSTANCE, + progressTracker + ); + + return algorithmMachinery.runAlgorithmsAndManageProgressTracker(algorithm, progressTracker, true); + } } diff --git a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithmsEstimationModeBusinessFacade.java b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithmsEstimationModeBusinessFacade.java index 14c5120434..2f8538bbb6 100644 --- a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithmsEstimationModeBusinessFacade.java +++ b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithmsEstimationModeBusinessFacade.java @@ -74,4 +74,8 @@ public MemoryEstimateResult degreeCentrality( memoryEstimation ); } + + public MemoryEstimation harmonicCentrality() { + throw new MemoryEstimationNotImplementedException(); + } } diff --git a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithmsMutateModeBusinessFacade.java b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithmsMutateModeBusinessFacade.java index 878d0b7dcc..f69baad24b 100644 --- a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithmsMutateModeBusinessFacade.java +++ b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithmsMutateModeBusinessFacade.java @@ -29,12 +29,15 @@ import org.neo4j.gds.closeness.ClosenessCentralityResult; import org.neo4j.gds.degree.DegreeCentralityMutateConfig; import org.neo4j.gds.degree.DegreeCentralityResult; +import org.neo4j.gds.harmonic.HarmonicCentralityMutateConfig; +import org.neo4j.gds.harmonic.HarmonicResult; import java.util.Optional; import static org.neo4j.gds.applications.algorithms.metadata.LabelForProgressTracking.BetweennessCentrality; import static org.neo4j.gds.applications.algorithms.metadata.LabelForProgressTracking.ClosenessCentrality; import static org.neo4j.gds.applications.algorithms.metadata.LabelForProgressTracking.DegreeCentrality; +import static org.neo4j.gds.applications.algorithms.metadata.LabelForProgressTracking.HarmonicCentrality; public class CentralityAlgorithmsMutateModeBusinessFacade { private final CentralityAlgorithmsEstimationModeBusinessFacade estimation; @@ -116,4 +119,25 @@ public RESULT degreeCentrality( resultBuilder ); } + + public RESULT harmonicCentrality( + GraphName graphName, + HarmonicCentralityMutateConfig configuration, + ResultBuilder resultBuilder + ) { + var mutateStep = new HarmonicCentralityMutateStep( + mutateNodeProperty, + configuration + ); + + return template.processAlgorithm( + graphName, + configuration, + HarmonicCentrality, + estimation::harmonicCentrality, + graph -> algorithms.harmonicCentrality(graph, configuration), + Optional.of(mutateStep), + resultBuilder + ); + } } diff --git a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/HarmonicCentralityMutateStep.java b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/HarmonicCentralityMutateStep.java new file mode 100644 index 0000000000..c75947a261 --- /dev/null +++ b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/HarmonicCentralityMutateStep.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.gds.applications.algorithms.centrality; + +import org.neo4j.gds.api.Graph; +import org.neo4j.gds.api.GraphStore; +import org.neo4j.gds.api.ResultStore; +import org.neo4j.gds.applications.algorithms.machinery.MutateOrWriteStep; +import org.neo4j.gds.applications.algorithms.metadata.NodePropertiesWritten; +import org.neo4j.gds.core.utils.progress.JobId; +import org.neo4j.gds.harmonic.HarmonicCentralityMutateConfig; +import org.neo4j.gds.harmonic.HarmonicResult; + +class HarmonicCentralityMutateStep implements MutateOrWriteStep { + private final MutateNodeProperty mutateNodeProperty; + private final HarmonicCentralityMutateConfig configuration; + + HarmonicCentralityMutateStep( + MutateNodeProperty mutateNodeProperty, + HarmonicCentralityMutateConfig configuration + ) { + this.mutateNodeProperty = mutateNodeProperty; + this.configuration = configuration; + } + + @Override + public NodePropertiesWritten execute( + Graph graph, + GraphStore graphStore, + ResultStore resultStore, + HarmonicResult result, + JobId jobId + ) { + return mutateNodeProperty.mutateNodeProperties( + graph, + graphStore, + configuration, + result.nodePropertyValues() + ); + } +} diff --git a/applications/algorithms/machinery/src/main/java/org/neo4j/gds/applications/algorithms/metadata/Algorithm.java b/applications/algorithms/machinery/src/main/java/org/neo4j/gds/applications/algorithms/metadata/Algorithm.java index 55d649f985..90ec863211 100644 --- a/applications/algorithms/machinery/src/main/java/org/neo4j/gds/applications/algorithms/metadata/Algorithm.java +++ b/applications/algorithms/machinery/src/main/java/org/neo4j/gds/applications/algorithms/metadata/Algorithm.java @@ -40,6 +40,7 @@ public enum Algorithm { Dijkstra, FilteredKNN, FilteredNodeSimilarity, + HarmonicCentrality, KNN, KSpanningTree, LongestPath, diff --git a/applications/algorithms/machinery/src/main/java/org/neo4j/gds/applications/algorithms/metadata/LabelForProgressTracking.java b/applications/algorithms/machinery/src/main/java/org/neo4j/gds/applications/algorithms/metadata/LabelForProgressTracking.java index c4f93627b4..99319ec09a 100644 --- a/applications/algorithms/machinery/src/main/java/org/neo4j/gds/applications/algorithms/metadata/LabelForProgressTracking.java +++ b/applications/algorithms/machinery/src/main/java/org/neo4j/gds/applications/algorithms/metadata/LabelForProgressTracking.java @@ -33,6 +33,7 @@ public enum LabelForProgressTracking { Dijkstra("Dijkstra"), FilteredKNN("Filtered K-Nearest Neighbours"), FilteredNodeSimilarity("Filtered Node Similarity"), + HarmonicCentrality("HarmonicCentrality"), KNN("K-Nearest Neighbours"), KSpanningTree("K Spanning Tree"), LongestPath("LongestPath"), @@ -63,6 +64,7 @@ public static LabelForProgressTracking from(Algorithm algorithm) { case Dijkstra -> Dijkstra; case FilteredKNN -> FilteredKNN; case FilteredNodeSimilarity -> FilteredNodeSimilarity; + case HarmonicCentrality -> HarmonicCentrality; case KNN -> KNN; case KSpanningTree -> KSpanningTree; case LongestPath -> LongestPath; diff --git a/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/ConfigurationParsersForMutateMode.java b/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/ConfigurationParsersForMutateMode.java index 97820c35dc..5a748bd3a1 100644 --- a/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/ConfigurationParsersForMutateMode.java +++ b/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/ConfigurationParsersForMutateMode.java @@ -25,6 +25,7 @@ import org.neo4j.gds.config.AlgoBaseConfig; import org.neo4j.gds.core.CypherMapWrapper; import org.neo4j.gds.degree.DegreeCentralityMutateConfig; +import org.neo4j.gds.harmonic.HarmonicCentralityMutateConfig; import org.neo4j.gds.paths.astar.config.ShortestPathAStarMutateConfig; import org.neo4j.gds.paths.bellmanford.BellmanFordMutateConfig; import org.neo4j.gds.paths.delta.config.AllShortestPathsDeltaMutateConfig; @@ -64,6 +65,7 @@ public Function lookup(Algorithm algorithm) { case Dijkstra -> ShortestPathDijkstraMutateConfig::of; case FilteredKNN -> FilteredKnnMutateConfig::of; case FilteredNodeSimilarity -> FilteredNodeSimilarityMutateConfig::of; + case HarmonicCentrality -> HarmonicCentralityMutateConfig::of; case KNN -> KnnMutateConfig::of; case KSpanningTree -> null; case LongestPath -> null; diff --git a/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/MutateModeAlgorithmLibrary.java b/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/MutateModeAlgorithmLibrary.java index ba9f462c0f..d3519153b1 100644 --- a/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/MutateModeAlgorithmLibrary.java +++ b/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/MutateModeAlgorithmLibrary.java @@ -71,6 +71,7 @@ private static CanonicalProcedureName algorithmToName(Algorithm algorithm) { case Dijkstra -> CanonicalProcedureName.parse("gds.shortestpath.dijkstra"); case FilteredKNN -> CanonicalProcedureName.parse("gds.knn.filtered"); case FilteredNodeSimilarity -> CanonicalProcedureName.parse("gds.nodesimilarity.filtered"); + case HarmonicCentrality -> CanonicalProcedureName.parse("gds.closeness.harmonic.mutate"); case KNN -> CanonicalProcedureName.parse("gds.knn"); case KSpanningTree -> null; case LongestPath -> null; diff --git a/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/StubbyHolder.java b/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/StubbyHolder.java index 2259f2d8f8..2c79a757f5 100644 --- a/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/StubbyHolder.java +++ b/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/StubbyHolder.java @@ -29,6 +29,7 @@ import org.neo4j.gds.ml.pipeline.stubs.DepthFirstSearchStub; import org.neo4j.gds.ml.pipeline.stubs.FilteredKnnStub; import org.neo4j.gds.ml.pipeline.stubs.FilteredNodeSimilarityStub; +import org.neo4j.gds.ml.pipeline.stubs.HarmonicCentralityStub; import org.neo4j.gds.ml.pipeline.stubs.KnnStub; import org.neo4j.gds.ml.pipeline.stubs.NodeSimilarityStub; import org.neo4j.gds.ml.pipeline.stubs.SinglePairShortestPathAStarStub; @@ -63,6 +64,7 @@ Stub get(Algorithm algorithm) { case Dijkstra -> new SinglePairShortestPathDijkstraStub(); case FilteredKNN -> new FilteredKnnStub(); case FilteredNodeSimilarity -> new FilteredNodeSimilarityStub(); + case HarmonicCentrality -> new HarmonicCentralityStub(); case KNN -> new KnnStub(); case KSpanningTree -> null; case LongestPath -> null; diff --git a/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/stubs/HarmonicCentralityStub.java b/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/stubs/HarmonicCentralityStub.java new file mode 100644 index 0000000000..c01c0c98a6 --- /dev/null +++ b/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/stubs/HarmonicCentralityStub.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.gds.ml.pipeline.stubs; + +import org.neo4j.gds.harmonic.HarmonicCentralityMutateConfig; +import org.neo4j.gds.procedures.algorithms.AlgorithmsProcedureFacade; +import org.neo4j.gds.procedures.algorithms.centrality.CentralityMutateResult; +import org.neo4j.gds.procedures.algorithms.stubs.MutateStub; + +public class HarmonicCentralityStub extends AbstractStub { + protected MutateStub stub(AlgorithmsProcedureFacade facade) { + return facade.centrality().harmonicCentralityMutateStub(); + } +} diff --git a/proc/centrality/src/main/java/org/neo4j/gds/harmonic/HarmonicCentralityMutateProc.java b/proc/centrality/src/main/java/org/neo4j/gds/harmonic/HarmonicCentralityMutateProc.java index 1bdf574be4..4b5b8884b7 100644 --- a/proc/centrality/src/main/java/org/neo4j/gds/harmonic/HarmonicCentralityMutateProc.java +++ b/proc/centrality/src/main/java/org/neo4j/gds/harmonic/HarmonicCentralityMutateProc.java @@ -42,6 +42,6 @@ public Stream mutate( @Name(value = "graphName") String graphName, @Name(value = "configuration", defaultValue = "{}") Map configuration ) { - return facade.centrality().harmonicCentralityMutate(graphName, configuration); + return facade.algorithms().centrality().harmonicCentralityMutateStub().execute(graphName, configuration); } } diff --git a/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CentralityProcedureFacade.java b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CentralityProcedureFacade.java index 6a66bf962d..0fc16d7b6d 100644 --- a/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CentralityProcedureFacade.java +++ b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CentralityProcedureFacade.java @@ -37,6 +37,7 @@ import org.neo4j.gds.procedures.algorithms.centrality.stubs.BetweennessCentralityMutateStub; import org.neo4j.gds.procedures.algorithms.centrality.stubs.ClosenessCentralityMutateStub; import org.neo4j.gds.procedures.algorithms.centrality.stubs.DegreeCentralityMutateStub; +import org.neo4j.gds.procedures.algorithms.centrality.stubs.HarmonicCentralityMutateStub; import org.neo4j.gds.procedures.algorithms.runners.EstimationModeRunner; import org.neo4j.gds.procedures.algorithms.runners.StatsModeAlgorithmRunner; import org.neo4j.gds.procedures.algorithms.runners.StreamModeAlgorithmRunner; @@ -54,6 +55,7 @@ public final class CentralityProcedureFacade { private final ClosenessCentralityMutateStub closenessCentralityMutateStub; private final DegreeCentralityMutateStub degreeCentralityMutateStub; + private final HarmonicCentralityMutateStub harmonicCentralityMutateStub; private final ApplicationsFacade applicationsFacade; private final EstimationModeRunner estimationModeRunner; @@ -67,6 +69,7 @@ private CentralityProcedureFacade( BetweennessCentralityMutateStub betweennessCentralityMutateStub, ClosenessCentralityMutateStub closenessCentralityMutateStub, DegreeCentralityMutateStub degreeCentralityMutateStub, + HarmonicCentralityMutateStub harmonicCentralityMutateStub, ApplicationsFacade applicationsFacade, EstimationModeRunner estimationModeRunner, StatsModeAlgorithmRunner statsModeRunner, @@ -78,6 +81,7 @@ private CentralityProcedureFacade( this.betweennessCentralityMutateStub = betweennessCentralityMutateStub; this.closenessCentralityMutateStub = closenessCentralityMutateStub; this.degreeCentralityMutateStub = degreeCentralityMutateStub; + this.harmonicCentralityMutateStub = harmonicCentralityMutateStub; this.applicationsFacade = applicationsFacade; this.estimationModeRunner = estimationModeRunner; this.statsModeRunner = statsModeRunner; @@ -114,6 +118,11 @@ public static CentralityProcedureFacade create( applicationsFacade, procedureReturnColumns ); + var harmonicCentralityMutateStub = new HarmonicCentralityMutateStub( + genericStub, + applicationsFacade, + procedureReturnColumns + ); return new CentralityProcedureFacade( procedureReturnColumns, @@ -121,6 +130,7 @@ public static CentralityProcedureFacade create( betweennessCentralityMutateStub, closenessCentralityMutateStub, degreeCentralityMutateStub, + harmonicCentralityMutateStub, applicationsFacade, estimationModeRunner, statsModeRunner, @@ -326,6 +336,10 @@ public Stream degreeCentralityStatsEstimate( return Stream.of(result); } + public HarmonicCentralityMutateStub harmonicCentralityMutateStub() { + return harmonicCentralityMutateStub; + } + private CentralityAlgorithmsEstimationModeBusinessFacade estimationMode() { return applicationsFacade.centrality().estimate(); } diff --git a/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/stubs/HarmonicCentralityMutateStub.java b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/stubs/HarmonicCentralityMutateStub.java new file mode 100644 index 0000000000..6c8426da08 --- /dev/null +++ b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/stubs/HarmonicCentralityMutateStub.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.gds.procedures.algorithms.centrality.stubs; + +import org.neo4j.gds.api.ProcedureReturnColumns; +import org.neo4j.gds.applications.ApplicationsFacade; +import org.neo4j.gds.applications.algorithms.centrality.CentralityAlgorithmsEstimationModeBusinessFacade; +import org.neo4j.gds.applications.algorithms.machinery.MemoryEstimateResult; +import org.neo4j.gds.harmonic.HarmonicCentralityMutateConfig; +import org.neo4j.gds.mem.MemoryEstimation; +import org.neo4j.gds.procedures.algorithms.centrality.CentralityMutateResult; +import org.neo4j.gds.procedures.algorithms.stubs.GenericStub; +import org.neo4j.gds.procedures.algorithms.stubs.MutateStub; + +import java.util.Map; +import java.util.stream.Stream; + +public class HarmonicCentralityMutateStub implements MutateStub { + private final GenericStub genericStub; + private final ApplicationsFacade applicationsFacade; + private final ProcedureReturnColumns procedureReturnColumns; + + public HarmonicCentralityMutateStub( + GenericStub genericStub, + ApplicationsFacade applicationsFacade, + ProcedureReturnColumns procedureReturnColumns + ) { + this.genericStub = genericStub; + this.applicationsFacade = applicationsFacade; + this.procedureReturnColumns = procedureReturnColumns; + } + + @Override + public HarmonicCentralityMutateConfig parseConfiguration(Map configuration) { + return genericStub.parseConfiguration(HarmonicCentralityMutateConfig::of, configuration); + } + + @Override + public MemoryEstimation getMemoryEstimation(String username, Map configuration) { + return genericStub.getMemoryEstimation( + username, + configuration, + HarmonicCentralityMutateConfig::of, + __ -> estimationMode().harmonicCentrality() + ); + } + + @Override + public Stream estimate(Object graphName, Map configuration) { + return genericStub.estimate( + graphName, + configuration, + HarmonicCentralityMutateConfig::of, + __ -> estimationMode().harmonicCentrality() + ); + } + + @Override + public Stream execute(String graphNameAsString, Map rawConfiguration) { + var shouldComputeCentralityDistribution = procedureReturnColumns.contains("centralityDistribution"); + var resultBuilder = new HarmonicCentralityResultBuilderForMutateMode(shouldComputeCentralityDistribution); + + return genericStub.execute( + graphNameAsString, + rawConfiguration, + HarmonicCentralityMutateConfig::of, + applicationsFacade.centrality().mutate()::harmonicCentrality, + resultBuilder + ); + } + + private CentralityAlgorithmsEstimationModeBusinessFacade estimationMode() { + return applicationsFacade.centrality().estimate(); + } +} diff --git a/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/stubs/HarmonicCentralityResultBuilderForMutateMode.java b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/stubs/HarmonicCentralityResultBuilderForMutateMode.java new file mode 100644 index 0000000000..a1930e6d42 --- /dev/null +++ b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/stubs/HarmonicCentralityResultBuilderForMutateMode.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.gds.procedures.algorithms.centrality.stubs; + +import org.neo4j.gds.api.Graph; +import org.neo4j.gds.api.GraphStore; +import org.neo4j.gds.applications.algorithms.machinery.AlgorithmProcessingTimings; +import org.neo4j.gds.applications.algorithms.machinery.ResultBuilder; +import org.neo4j.gds.applications.algorithms.metadata.NodePropertiesWritten; +import org.neo4j.gds.harmonic.HarmonicCentralityMutateConfig; +import org.neo4j.gds.harmonic.HarmonicResult; +import org.neo4j.gds.procedures.algorithms.centrality.CentralityMutateResult; + +import java.util.Optional; + +class HarmonicCentralityResultBuilderForMutateMode implements ResultBuilder { + private final GenericCentralityResultBuilderForMutateMode genericResultBuilder = new GenericCentralityResultBuilderForMutateMode(); + + private final boolean shouldComputeCentralityDistribution; + + HarmonicCentralityResultBuilderForMutateMode(boolean shouldComputeCentralityDistribution) { + this.shouldComputeCentralityDistribution = shouldComputeCentralityDistribution; + } + + @Override + public CentralityMutateResult build( + Graph graph, + GraphStore graphStore, + HarmonicCentralityMutateConfig configuration, + Optional result, + AlgorithmProcessingTimings timings, + Optional metadata + ) { + return genericResultBuilder.build( + graph, + configuration, + result, + timings, + metadata, + shouldComputeCentralityDistribution + ); + } +} diff --git a/procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/CentralityProcedureFacade.java b/procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/CentralityProcedureFacade.java index 022bd5239d..6a170f3041 100644 --- a/procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/CentralityProcedureFacade.java +++ b/procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/CentralityProcedureFacade.java @@ -28,7 +28,6 @@ import org.neo4j.gds.degree.DegreeCentralityStreamConfig; import org.neo4j.gds.degree.DegreeCentralityWriteConfig; import org.neo4j.gds.harmonic.DeprecatedTieredHarmonicCentralityWriteConfig; -import org.neo4j.gds.harmonic.HarmonicCentralityMutateConfig; import org.neo4j.gds.harmonic.HarmonicCentralityStatsConfig; import org.neo4j.gds.harmonic.HarmonicCentralityStreamConfig; import org.neo4j.gds.harmonic.HarmonicCentralityWriteConfig; @@ -40,7 +39,6 @@ import org.neo4j.gds.pagerank.PageRankStatsConfig; import org.neo4j.gds.pagerank.PageRankStreamConfig; import org.neo4j.gds.pagerank.PageRankWriteConfig; -import org.neo4j.gds.procedures.algorithms.centrality.CentralityMutateResult; import org.neo4j.gds.procedures.algorithms.centrality.CentralityStatsResult; import org.neo4j.gds.procedures.algorithms.centrality.CentralityStreamResult; import org.neo4j.gds.procedures.algorithms.centrality.CentralityWriteResult; @@ -171,22 +169,6 @@ public Stream harmonicCentralityStats( return Stream.of(DefaultCentralityComputationalResultTransformer.toStatsResult(computationResult, config)); } - public Stream harmonicCentralityMutate( - String graphName, - Map configuration - ) { - var config = configurationCreator.createConfiguration(configuration, HarmonicCentralityMutateConfig::of); - - var computationResult = mutateBusinessFacade.harmonicCentrality( - graphName, - config, - procedureReturnColumns.contains("centralityDistribution") - ); - - return Stream.of(DefaultCentralityComputationalResultTransformer.toMutateResult(computationResult)); - } - - public Stream harmonicCentralityWrite( String graphName, Map configuration