Skip to content

Commit

Permalink
using configuration creation service
Browse files Browse the repository at this point in the history
  • Loading branch information
lassewesth committed Nov 16, 2023
1 parent ee33e79 commit f7f9768
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@
import org.neo4j.gds.algorithms.similarity.SimilarityAlgorithmsStatsBusinessFacade;
import org.neo4j.gds.algorithms.similarity.SimilarityAlgorithmsStreamBusinessFacade;
import org.neo4j.gds.algorithms.similarity.SimilarityAlgorithmsWriteBusinessFacade;
import org.neo4j.gds.api.AlgorithmMetaDataSetter;
import org.neo4j.gds.api.ProcedureReturnColumns;
import org.neo4j.gds.api.User;
import org.neo4j.gds.config.AlgoBaseConfig;
import org.neo4j.gds.core.CypherMapWrapper;
import org.neo4j.gds.procedures.configparser.ConfigurationParser;
import org.neo4j.gds.procedures.algorithms.ConfigurationCreator;
import org.neo4j.gds.procedures.similarity.knn.KnnMutateResult;
import org.neo4j.gds.procedures.similarity.knn.KnnStatsResult;
import org.neo4j.gds.procedures.similarity.knn.KnnWriteResult;
Expand All @@ -53,48 +49,40 @@
import org.neo4j.gds.similarity.nodesim.NodeSimilarityWriteConfig;

import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;

public class SimilarityProcedureFacade {

private final ConfigurationParser configurationParser;
private final User user;
private final ConfigurationCreator configurationCreator;
private final ProcedureReturnColumns procedureReturnColumns;
private final SimilarityAlgorithmsEstimateBusinessFacade estimateBusinessFacade;
private final SimilarityAlgorithmsMutateBusinessFacade mutateBusinessFacade;
private final SimilarityAlgorithmsStatsBusinessFacade statsBusinessFacade;
private final SimilarityAlgorithmsStreamBusinessFacade streamBusinessFacade;
private final SimilarityAlgorithmsWriteBusinessFacade writeBusinessFacade;
private final SimilarityAlgorithmsEstimateBusinessFacade estimateBusinessFacade;
private final AlgorithmMetaDataSetter algorithmMetaDataSetter;

public SimilarityProcedureFacade(
ConfigurationParser configurationParser,
User user,
ConfigurationCreator configurationCreator,
ProcedureReturnColumns procedureReturnColumns,
SimilarityAlgorithmsEstimateBusinessFacade estimateBusinessFacade,
SimilarityAlgorithmsMutateBusinessFacade mutateBusinessFacade,
SimilarityAlgorithmsStatsBusinessFacade statsBusinessFacade,
SimilarityAlgorithmsStreamBusinessFacade streamBusinessFacade,
SimilarityAlgorithmsWriteBusinessFacade writeBusinessFacade,
SimilarityAlgorithmsEstimateBusinessFacade estimateBusinessFacade,
AlgorithmMetaDataSetter algorithmMetaDataSetter
SimilarityAlgorithmsWriteBusinessFacade writeBusinessFacade
) {
this.configurationParser = configurationParser;
this.user = user;
this.configurationCreator = configurationCreator;
this.procedureReturnColumns = procedureReturnColumns;
this.estimateBusinessFacade = estimateBusinessFacade;
this.mutateBusinessFacade = mutateBusinessFacade;
this.statsBusinessFacade = statsBusinessFacade;
this.streamBusinessFacade = streamBusinessFacade;
this.writeBusinessFacade = writeBusinessFacade;
this.estimateBusinessFacade = estimateBusinessFacade;
this.algorithmMetaDataSetter = algorithmMetaDataSetter;
}

public Stream<SimilarityResult> nodeSimilarityStream(
String graphName,
Map<String, Object> configuration
) {
var streamConfig = createStreamConfig(configuration, NodeSimilarityStreamConfig::of);
var streamConfig = configurationCreator.createConfigurationForStream(configuration, NodeSimilarityStreamConfig::of);

var computationResult = streamBusinessFacade.nodeSimilarity(
graphName,
Expand All @@ -108,7 +96,7 @@ public Stream<SimilarityStatsResult> nodeSimilarityStats(
String graphName,
Map<String, Object> configuration
) {
var statsConfig = createConfig(configuration, NodeSimilarityStatsConfig::of);
var statsConfig = configurationCreator.createConfiguration(configuration, NodeSimilarityStatsConfig::of);

var computationResult = statsBusinessFacade.nodeSimilarity(
graphName,
Expand All @@ -123,7 +111,7 @@ public Stream<SimilarityWriteResult> nodeSimilarityWrite(
String graphName,
Map<String, Object> configuration
) {
var statsConfig = createConfig(configuration, NodeSimilarityWriteConfig::of);
var statsConfig = configurationCreator.createConfiguration(configuration, NodeSimilarityWriteConfig::of);

var computationResult = writeBusinessFacade.nodeSimilarity(
graphName,
Expand All @@ -138,7 +126,7 @@ public Stream<SimilarityMutateResult> nodeSimilarityMutate(
String graphName,
Map<String, Object> configuration
) {
var mutateConfig = createConfig(configuration, NodeSimilarityMutateConfig::of);
var mutateConfig = configurationCreator.createConfiguration(configuration, NodeSimilarityMutateConfig::of);

var computationResult = mutateBusinessFacade.nodeSimilarity(
graphName,
Expand All @@ -154,31 +142,31 @@ public Stream<MemoryEstimateResult> nodeSimilarityEstimateStream(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, NodeSimilarityStreamConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, NodeSimilarityStreamConfig::of);
return Stream.of(estimateBusinessFacade.nodeSimilarity(graphNameOrConfiguration, config));
}

public Stream<MemoryEstimateResult> nodeSimilarityEstimateStats(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, NodeSimilarityStatsConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, NodeSimilarityStatsConfig::of);
return Stream.of(estimateBusinessFacade.nodeSimilarity(graphNameOrConfiguration, config));
}

public Stream<MemoryEstimateResult> nodeSimilarityEstimateMutate(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, NodeSimilarityMutateConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, NodeSimilarityMutateConfig::of);
return Stream.of(estimateBusinessFacade.nodeSimilarity(graphNameOrConfiguration, config));
}

public Stream<MemoryEstimateResult> nodeSimilarityEstimateWrite(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, NodeSimilarityWriteConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, NodeSimilarityWriteConfig::of);
return Stream.of(estimateBusinessFacade.nodeSimilarity(graphNameOrConfiguration, config));
}

Expand All @@ -187,7 +175,7 @@ public Stream<SimilarityResult> filteredNodeSimilarityStream(
String graphName,
Map<String, Object> configuration
) {
var streamConfig = createStreamConfig(configuration, FilteredNodeSimilarityStreamConfig::of);
var streamConfig = configurationCreator.createConfigurationForStream(configuration, FilteredNodeSimilarityStreamConfig::of);

var computationResult = streamBusinessFacade.filteredNodeSimilarity(
graphName,
Expand All @@ -201,7 +189,7 @@ public Stream<SimilarityStatsResult> filteredNodeSimilarityStats(
String graphName,
Map<String, Object> configuration
) {
var statsConfig = createConfig(configuration, FilteredNodeSimilarityStatsConfig::of);
var statsConfig = configurationCreator.createConfiguration(configuration, FilteredNodeSimilarityStatsConfig::of);

var computationResult = statsBusinessFacade.filteredNodeSimilarity(
graphName,
Expand All @@ -216,7 +204,7 @@ public Stream<SimilarityMutateResult> filteredNodeSimilarityMutate(
String graphName,
Map<String, Object> configuration
) {
var mutateConfig = createConfig(configuration, FilteredNodeSimilarityMutateConfig::of);
var mutateConfig = configurationCreator.createConfiguration(configuration, FilteredNodeSimilarityMutateConfig::of);

var computationResult = mutateBusinessFacade.filteredNodeSimilarity(
graphName,
Expand All @@ -231,7 +219,7 @@ public Stream<SimilarityWriteResult> filteredNodeSimilarityWrite(
String graphName,
Map<String, Object> configuration
) {
var writeConfig = createConfig(configuration, FilteredNodeSimilarityWriteConfig::of);
var writeConfig = configurationCreator.createConfiguration(configuration, FilteredNodeSimilarityWriteConfig::of);

var computationResult = writeBusinessFacade.filteredNodeSimilarity(
graphName,
Expand All @@ -247,39 +235,39 @@ public Stream<MemoryEstimateResult> filteredNodeSimilarityEstimateStream(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, FilteredNodeSimilarityStreamConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, FilteredNodeSimilarityStreamConfig::of);
return Stream.of(estimateBusinessFacade.filteredNodeSimilarity(graphNameOrConfiguration, config));
}

public Stream<MemoryEstimateResult> filteredNodeSimilarityEstimateStats(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, FilteredNodeSimilarityStatsConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, FilteredNodeSimilarityStatsConfig::of);
return Stream.of(estimateBusinessFacade.filteredNodeSimilarity(graphNameOrConfiguration, config));
}

public Stream<MemoryEstimateResult> filteredNodeSimilarityEstimateMutate(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, FilteredNodeSimilarityMutateConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, FilteredNodeSimilarityMutateConfig::of);
return Stream.of(estimateBusinessFacade.nodeSimilarity(graphNameOrConfiguration, config));
}

public Stream<MemoryEstimateResult> filteredNodeSimilarityEstimateWrite(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, FilteredNodeSimilarityWriteConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, FilteredNodeSimilarityWriteConfig::of);
return Stream.of(estimateBusinessFacade.nodeSimilarity(graphNameOrConfiguration, config));
}

public Stream<SimilarityResult> knnStream(
String graphName,
Map<String, Object> configuration
) {
var streamConfig = createStreamConfig(configuration, KnnStreamConfig::of);
var streamConfig = configurationCreator.createConfigurationForStream(configuration, KnnStreamConfig::of);

var computationResult = streamBusinessFacade.knn(
graphName,
Expand All @@ -293,7 +281,7 @@ public Stream<KnnStatsResult> knnStats(
String graphName,
Map<String, Object> configuration
) {
var statsConfig = createConfig(configuration, KnnStatsConfig::of);
var statsConfig = configurationCreator.createConfiguration(configuration, KnnStatsConfig::of);

var computationResult = statsBusinessFacade.knn(
graphName,
Expand All @@ -308,7 +296,7 @@ public Stream<KnnWriteResult> knnWrite(
String graphName,
Map<String, Object> configuration
) {
var writeConfig = createConfig(configuration, KnnWriteConfig::of);
var writeConfig = configurationCreator.createConfiguration(configuration, KnnWriteConfig::of);

var computationResult = writeBusinessFacade.knn(
graphName,
Expand All @@ -323,7 +311,7 @@ public Stream<KnnMutateResult> knnMutate(
String graphName,
Map<String, Object> configuration
) {
var mutateConfig = createConfig(configuration, KnnMutateConfig::of);
var mutateConfig = configurationCreator.createConfiguration(configuration, KnnMutateConfig::of);

var computationResult = mutateBusinessFacade.knn(
graphName,
Expand All @@ -339,39 +327,39 @@ public Stream<MemoryEstimateResult> knnStreamEstimate(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, KnnStreamConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, KnnStreamConfig::of);
return Stream.of(estimateBusinessFacade.knn(graphNameOrConfiguration, config));
}

public Stream<MemoryEstimateResult> knnStatsEstimate(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, KnnStatsConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, KnnStatsConfig::of);
return Stream.of(estimateBusinessFacade.knn(graphNameOrConfiguration, config));
}

public Stream<MemoryEstimateResult> knnWriteEstimate(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, KnnWriteConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, KnnWriteConfig::of);
return Stream.of(estimateBusinessFacade.knn(graphNameOrConfiguration, config));
}

public Stream<MemoryEstimateResult> knnMutateEstimate(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, KnnMutateConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, KnnMutateConfig::of);
return Stream.of(estimateBusinessFacade.knn(graphNameOrConfiguration, config));
}

public Stream<SimilarityResult> filteredKnnStream(
String graphName,
Map<String, Object> configuration
) {
var streamConfig = createStreamConfig(configuration, FilteredKnnStreamConfig::of);
var streamConfig = configurationCreator.createConfigurationForStream(configuration, FilteredKnnStreamConfig::of);

var computationResult = streamBusinessFacade.filteredKnn(
graphName,
Expand All @@ -385,7 +373,7 @@ public Stream<KnnStatsResult> filteredKnnStats(
String graphName,
Map<String, Object> configuration
) {
var statsConfig = createConfig(configuration, FilteredKnnStatsConfig::of);
var statsConfig = configurationCreator.createConfiguration(configuration, FilteredKnnStatsConfig::of);

var computationResult = statsBusinessFacade.filteredKnn(
graphName,
Expand All @@ -400,7 +388,7 @@ public Stream<KnnMutateResult> filteredKnnMutate(
String graphName,
Map<String, Object> configuration
) {
var mutateConfig = createConfig(configuration, FilteredKnnMutateConfig::of);
var mutateConfig = configurationCreator.createConfiguration(configuration, FilteredKnnMutateConfig::of);

var computationResult = mutateBusinessFacade.filteredKnn(
graphName,
Expand All @@ -415,7 +403,7 @@ public Stream<KnnWriteResult> filteredKnnWrite(
String graphName,
Map<String, Object> configuration
) {
var writeConfig = createConfig(configuration, FilteredKnnWriteConfig::of);
var writeConfig = configurationCreator.createConfiguration(configuration, FilteredKnnWriteConfig::of);

var computationResult = writeBusinessFacade.filteredKnn(
graphName,
Expand All @@ -431,54 +419,31 @@ public Stream<MemoryEstimateResult> filteredKnnStreamEstimate(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, FilteredKnnStreamConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, FilteredKnnStreamConfig::of);
return Stream.of(estimateBusinessFacade.filteredKnn(graphNameOrConfiguration, config));
}

public Stream<MemoryEstimateResult> filteredKnnStatsEstimate(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, FilteredKnnStatsConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, FilteredKnnStatsConfig::of);
return Stream.of(estimateBusinessFacade.filteredKnn(graphNameOrConfiguration, config));
}

public Stream<MemoryEstimateResult> filteredKnnMutateEstimate(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, FilteredKnnMutateConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, FilteredKnnMutateConfig::of);
return Stream.of(estimateBusinessFacade.filteredKnn(graphNameOrConfiguration, config));
}

public Stream<MemoryEstimateResult> filteredKnnWriteEstimate(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, FilteredKnnWriteConfig::of);
var config = configurationCreator.createConfiguration(algoConfiguration, FilteredKnnWriteConfig::of);
return Stream.of(estimateBusinessFacade.filteredKnn(graphNameOrConfiguration, config));
}


// FIXME: the following two methods are duplicate, find a good place for them.
private <C extends AlgoBaseConfig> C createStreamConfig(
Map<String, Object> configuration,
Function<CypherMapWrapper, C> configCreator
) {
return createConfig(
configuration,
configCreator.andThen(algorithmConfiguration -> {
algorithmMetaDataSetter.set(algorithmConfiguration);
return algorithmConfiguration;
})
);
}

private <C extends AlgoBaseConfig> C createConfig(
Map<String, Object> configuration,
Function<CypherMapWrapper, C> configCreator
) {
return configurationParser.produceConfig(configuration, configCreator, user.getUsername());
}
//FIXME: here ends the fixme-block
}
Loading

0 comments on commit f7f9768

Please sign in to comment.