Skip to content

Commit

Permalink
Filtered Node Similarity Write Facade
Browse files Browse the repository at this point in the history
  • Loading branch information
IoannisPanagiotas committed Oct 30, 2023
1 parent 0325c14 commit 1a51641
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.neo4j.gds.config.WriteConfig;
import org.neo4j.gds.core.utils.ProgressTimer;
import org.neo4j.gds.similarity.SimilarityGraphResult;
import org.neo4j.gds.similarity.filterednodesim.FilteredNodeSimilarityWriteConfig;
import org.neo4j.gds.similarity.knn.KnnWriteConfig;
import org.neo4j.gds.similarity.nodesim.NodeSimilarityWriteConfig;

Expand Down Expand Up @@ -88,6 +89,43 @@ public RelationshipWriteResult nodeSimilarity(

}

public RelationshipWriteResult<SimilaritySpecificFieldsWithDistribution> filteredNodeSimilarity(
String graphName,
FilteredNodeSimilarityWriteConfig configuration,
User user,
DatabaseId databaseId,
boolean computeSimilarityDistribution
) {
// 1. Run the algorithm and time the execution
var intermediateResult = AlgorithmRunner.runWithTiming(
() -> similarityAlgorithmsFacade.filteredNodeSimilarity(graphName, configuration, user, databaseId)
);
var algorithmResult = intermediateResult.algorithmResult;

return write(
algorithmResult,
configuration,
result -> result.graphResult(),
((result, similarityDistribution) -> {
var similarityGraphResult = result.graphResult();
return new SimilaritySpecificFieldsWithDistribution(
similarityGraphResult.comparedNodes(),
similarityGraphResult.similarityGraph().relationshipCount(),
similarityDistribution
);
}),
intermediateResult.computeMilliseconds,
() -> SimilaritySpecificFieldsWithDistribution.EMPTY,
computeSimilarityDistribution,
"FilteredNodeSimilarityWrite",
configuration.writeProperty(),
configuration.writeRelationshipType(),
configuration.arrowConnectionInfo()

);
}


public RelationshipWriteResult knn(
String graphName,
KnnWriteConfig configuration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
package org.neo4j.gds.similarity.filterednodesim;

import org.neo4j.gds.BaseProc;
import org.neo4j.gds.core.write.RelationshipExporterBuilder;
import org.neo4j.gds.executor.ExecutionContext;
import org.neo4j.gds.executor.MemoryEstimationExecutor;
import org.neo4j.gds.executor.ProcedureExecutor;
import org.neo4j.gds.procedures.GraphDataScience;
import org.neo4j.gds.procedures.similarity.SimilarityWriteResult;
import org.neo4j.gds.results.MemoryEstimateResult;
import org.neo4j.procedure.Context;
Expand All @@ -42,18 +39,15 @@
public class FilteredNodeSimilarityWriteProc extends BaseProc {

@Context
public RelationshipExporterBuilder relationshipExporterBuilder;
public GraphDataScience facade;

@Procedure(value = "gds.nodeSimilarity.filtered.write", mode = WRITE)
@Description(DESCRIPTION)
public Stream<SimilarityWriteResult> write(
@Name(value = "graphName") String graphName,
@Name(value = "configuration", defaultValue = "{}") Map<String, Object> configuration
){
return new ProcedureExecutor<>(
new FilteredNodeSimilarityWriteSpec(),
executionContext()
).compute(graphName, configuration);
return facade.similarity().filteredNodeSimilarityWrite(graphName, configuration);
}

@Procedure(value = "gds.nodeSimilarity.filtered.write.estimate", mode = READ)
Expand All @@ -62,11 +56,7 @@ public Stream<MemoryEstimateResult> estimate(
@Name(value = "graphNameOrConfiguration") Object graphNameOrConfiguration,
@Name(value = "algoConfiguration") Map<String, Object> algoConfiguration
) {
return new MemoryEstimationExecutor<>(
new FilteredNodeSimilarityWriteSpec(),
executionContext(),
transactionContext()
).computeEstimate(graphNameOrConfiguration, algoConfiguration);
return facade.similarity().filteredNodeSimilarityEstimateWrite(graphNameOrConfiguration, algoConfiguration);
}

@Deprecated(forRemoval = true)
Expand Down Expand Up @@ -98,9 +88,5 @@ public Stream<MemoryEstimateResult> estimateAlpha(

return estimate(graphNameOrConfiguration, algoConfiguration);
}

@Override
public ExecutionContext executionContext() {
return super.executionContext().withRelationshipExporterBuilder(relationshipExporterBuilder);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.neo4j.gds.similarity.filterednodesim.FilteredNodeSimilarityMutateConfig;
import org.neo4j.gds.similarity.filterednodesim.FilteredNodeSimilarityStatsConfig;
import org.neo4j.gds.similarity.filterednodesim.FilteredNodeSimilarityStreamConfig;
import org.neo4j.gds.similarity.filterednodesim.FilteredNodeSimilarityWriteConfig;
import org.neo4j.gds.similarity.knn.KnnMutateConfig;
import org.neo4j.gds.similarity.knn.KnnStatsConfig;
import org.neo4j.gds.similarity.knn.KnnStreamConfig;
Expand Down Expand Up @@ -241,6 +242,23 @@ public Stream<SimilarityMutateResult> filteredNodeSimilarityMutate(
return Stream.of(NodeSimilarityComputationResultTransformer.toMutateResult(computationResult));
}

public Stream<SimilarityWriteResult> filteredNodeSimilarityWrite(
String graphName,
Map<String, Object> configuration
) {
var writeConfig = createConfig(configuration, FilteredNodeSimilarityWriteConfig::of);

var computationResult = writeBusinessFacade.filteredNodeSimilarity(
graphName,
writeConfig,
user,
databaseId,
procedureReturnColumns.contains("similarityDistribution")
);

return Stream.of(NodeSimilarityComputationResultTransformer.toWriteResult(computationResult));
}


public Stream<MemoryEstimateResult> filteredNodeSimilarityEstimateStream(
Object graphNameOrConfiguration,
Expand All @@ -266,6 +284,14 @@ public Stream<MemoryEstimateResult> filteredNodeSimilarityEstimateMutate(
return Stream.of(estimateBusinessFacade.nodeSimilarity(graphNameOrConfiguration, config));
}

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

public Stream<SimilarityResult> knnStream(
String graphName,
Map<String, Object> configuration
Expand Down

0 comments on commit 1a51641

Please sign in to comment.