Skip to content

Commit 2fcb71b

Browse files
Add Label Propagation to business facade
1 parent afeaaca commit 2fcb71b

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

algorithms-compute-business-facade/src/main/java/org/neo4j/gds/community/CommunityComputeBusinessFacade.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.neo4j.gds.core.loading.validation.NoAlgorithmValidation;
3737
import org.neo4j.gds.core.loading.validation.NodePropertyAnyExistsGraphStoreValidation;
3838
import org.neo4j.gds.core.loading.validation.NodePropertyTypeGraphStoreValidation;
39+
import org.neo4j.gds.core.loading.validation.SeedPropertyGraphStoreValidation;
3940
import org.neo4j.gds.core.loading.validation.UndirectedOnlyGraphStoreValidation;
4041
import org.neo4j.gds.hdbscan.HDBScanParameters;
4142
import org.neo4j.gds.hdbscan.Labels;
@@ -45,6 +46,8 @@
4546
import org.neo4j.gds.kcore.KCoreDecompositionResult;
4647
import org.neo4j.gds.kmeans.KmeansParameters;
4748
import org.neo4j.gds.kmeans.KmeansResult;
49+
import org.neo4j.gds.labelpropagation.LabelPropagationParameters;
50+
import org.neo4j.gds.labelpropagation.LabelPropagationResult;
4851
import org.neo4j.gds.result.TimedAlgorithmResult;
4952
import org.neo4j.gds.results.ResultTransformerBuilder;
5053

@@ -284,4 +287,35 @@ public <TR> CompletableFuture<TR> kMeans(
284287
).thenApply(resultTransformerBuilder.build(graphResources));
285288
}
286289

290+
public <TR> CompletableFuture<TR> labelPropagation(
291+
GraphName graphName,
292+
GraphParameters graphParameters,
293+
Optional<String> relationshipProperty,
294+
LabelPropagationParameters parameters,
295+
JobId jobId,
296+
boolean logProgress,
297+
ResultTransformerBuilder<TimedAlgorithmResult<LabelPropagationResult>, TR> resultTransformerBuilder
298+
) {
299+
// Fetch the Graph the algorithm will operate on
300+
var graphResources = graphStoreCatalogService.fetchGraphResources(
301+
graphName,
302+
graphParameters,
303+
relationshipProperty,
304+
SeedPropertyGraphStoreValidation.create(parameters.seedProperty()),
305+
Optional.empty(),
306+
user,
307+
databaseId
308+
);
309+
var graph = graphResources.graph();
310+
311+
return computeFacade.labelPropagation(
312+
graph,
313+
parameters,
314+
jobId,
315+
logProgress
316+
317+
).thenApply(resultTransformerBuilder.build(graphResources));
318+
}
319+
320+
287321
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.core.loading.validation;
21+
22+
import org.neo4j.gds.NodeLabel;
23+
import org.neo4j.gds.RelationshipType;
24+
import org.neo4j.gds.api.GraphStore;
25+
26+
import java.util.Collection;
27+
28+
public class SeedPropertyGraphStoreValidation extends GraphStoreValidation {
29+
30+
private GraphStoreValidation validation;
31+
32+
public SeedPropertyGraphStoreValidation(GraphStoreValidation validation) {this.validation = validation;}
33+
34+
public static SeedPropertyGraphStoreValidation create(String seedProperty){
35+
if (seedProperty == null){
36+
return new SeedPropertyGraphStoreValidation(new NoAlgorithmValidation());
37+
}else {
38+
return new SeedPropertyGraphStoreValidation(new NodePropertyAllExistsGraphStoreValidation("seedProperty"));
39+
}
40+
}
41+
@Override
42+
protected void validateAlgorithmRequirements(
43+
GraphStore graphStore,
44+
Collection<NodeLabel> selectedLabels,
45+
Collection<RelationshipType> selectedRelationshipTypes
46+
) {
47+
validation.validateAlgorithmRequirements(graphStore,selectedLabels,selectedRelationshipTypes);
48+
}
49+
}

0 commit comments

Comments
 (0)