Skip to content

Create explicit WCC endpoints #859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions graphdatascience/graph_data_science.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from neo4j import Driver
from pandas import DataFrame

from graphdatascience.procedure_surface.api.wcc_endpoints import WccEndpoints
from graphdatascience.procedure_surface.cypher.wcc_proc_runner import WccCypherEndpoints

from .call_builder import IndirectCallBuilder
from .endpoints import AlphaEndpoints, BetaEndpoints, DirectEndpoints
from .error.uncallable_namespace import UncallableNamespace
Expand Down Expand Up @@ -106,10 +109,16 @@ def __init__(
self._query_runner.set_show_progress(show_progress)
super().__init__(self._query_runner, namespace="gds", server_version=self._server_version)

self._wcc_endpoints = WccCypherEndpoints(self._query_runner)

@property
def graph(self) -> GraphProcRunner:
return GraphProcRunner(self._query_runner, f"{self._namespace}.graph", self._server_version)

@property
def wcc(self) -> WccEndpoints:
return self._wcc_endpoints

@property
def util(self) -> UtilProcRunner:
return UtilProcRunner(self._query_runner, f"{self._namespace}.util", self._server_version)
Expand Down
Empty file.
Empty file.
242 changes: 242 additions & 0 deletions graphdatascience/procedure_surface/api/wcc_endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
from abc import ABC, abstractmethod
from typing import Any, List, Optional

from pandas import DataFrame, Series

from ...graph.graph_object import Graph


class WccEndpoints(ABC):
"""
Abstract base class defining the API for the Weakly Connected Components (WCC) algorithm.
"""

@abstractmethod
def mutate(
self,
G: Graph,
mutate_property: str,
threshold: Optional[float] = None,
relationship_types: Optional[List[str]] = None,
node_labels: Optional[List[str]] = None,
sudo: Optional[bool] = None,
log_progress: Optional[bool] = None,
username: Optional[str] = None,
concurrency: Optional[Any] = None,
job_id: Optional[Any] = None,
seed_property: Optional[str] = None,
consecutive_ids: Optional[bool] = None,
relationship_weight_property: Optional[str] = None,
) -> Series[Any]:
"""
Executes the WCC algorithm and writes the results to the in-memory graph as node properties.

Parameters
----------
G : Graph
The graph to run the algorithm on
mutate_property : str
The property name to store the component ID for each node
threshold : Optional[float], default=None
The minimum required weight to consider a relationship during traversal
relationship_types : Optional[List[str]], default=None
The relationship types to project
node_labels : Optional[List[str]], default=None
The node labels to project
sudo : Optional[bool], default=None
Run analysis with admin permission
log_progress : Optional[bool], default=None
Whether to log progress
username : Optional[str], default=None
The username to attribute the procedure run to
concurrency : Optional[Any], default=None
The number of concurrent threads
job_id : Optional[Any], default=None
An identifier for the job
seed_property : Optional[str], default=None
Defines node properties that are used as initial component identifiers
consecutive_ids : Optional[bool], default=None
Flag to decide whether component identifiers are mapped into a consecutive id space
relationship_weight_property : Optional[str], default=None
The property name that contains weight

Returns
-------
Series
Algorithm metrics and statistics
"""
pass

@abstractmethod
def stats(
self,
G: Graph,
threshold: Optional[float] = None,
relationship_types: Optional[List[str]] = None,
node_labels: Optional[List[str]] = None,
sudo: Optional[bool] = None,
log_progress: Optional[bool] = None,
username: Optional[str] = None,
concurrency: Optional[Any] = None,
job_id: Optional[Any] = None,
seed_property: Optional[str] = None,
consecutive_ids: Optional[bool] = None,
relationship_weight_property: Optional[str] = None,
) -> Series[Any]:
"""
Executes the WCC algorithm and returns statistics.

Parameters
----------
G : Graph
The graph to run the algorithm on
threshold : Optional[float], default=None
The minimum required weight to consider a relationship during traversal
relationship_types : Optional[List[str]], default=None
The relationship types to project
node_labels : Optional[List[str]], default=None
The node labels to project
sudo : Optional[bool], default=None
Run analysis with admin permission
log_progress : Optional[bool], default=None
Whether to log progress
username : Optional[str], default=None
The username to attribute the procedure run to
concurrency : Optional[Any], default=None
The number of concurrent threads
job_id : Optional[Any], default=None
An identifier for the job
seed_property : Optional[str], default=None
Defines node properties that are used as initial component identifiers
consecutive_ids : Optional[bool], default=None
Flag to decide whether component identifiers are mapped into a consecutive id space
relationship_weight_property : Optional[str], default=None
The property name that contains weight

Returns
-------
Series
Algorithm metrics and statistics
"""
pass

@abstractmethod
def stream(
self,
G: Graph,
min_component_size: Optional[int] = None,
threshold: Optional[float] = None,
relationship_types: Optional[List[str]] = None,
node_labels: Optional[List[str]] = None,
sudo: Optional[bool] = None,
log_progress: Optional[bool] = None,
username: Optional[str] = None,
concurrency: Optional[Any] = None,
job_id: Optional[Any] = None,
seed_property: Optional[str] = None,
consecutive_ids: Optional[bool] = None,
relationship_weight_property: Optional[str] = None,
) -> DataFrame:
"""
Executes the WCC algorithm and returns a stream of results.

Parameters
----------
G : Graph
The graph to run the algorithm on
min_component_size : Optional[int], default=None
Don't stream components with fewer nodes than this
threshold : Optional[float], default=None
The minimum required weight to consider a relationship during traversal
relationship_types : Optional[List[str]], default=None
The relationship types to project
node_labels : Optional[List[str]], default=None
The node labels to project
sudo : Optional[bool], default=None
Run analysis with admin permission
log_progress : Optional[bool], default=None
Whether to log progress
username : Optional[str], default=None
The username to attribute the procedure run to
concurrency : Optional[Any], default=None
The number of concurrent threads
job_id : Optional[Any], default=None
An identifier for the job
seed_property : Optional[str], default=None
Defines node properties that are used as initial component identifiers
consecutive_ids : Optional[bool], default=None
Flag to decide whether component identifiers are mapped into a consecutive id space
relationship_weight_property : Optional[str], default=None
The property name that contains weight

Returns
-------
DataFrame
DataFrame with the algorithm results
"""
pass

@abstractmethod
def write(
self,
G: Graph,
write_property: str,
min_component_size: Optional[int] = None,
threshold: Optional[float] = None,
relationship_types: Optional[List[str]] = None,
node_labels: Optional[List[str]] = None,
sudo: Optional[bool] = None,
log_progress: Optional[bool] = None,
username: Optional[str] = None,
concurrency: Optional[Any] = None,
job_id: Optional[Any] = None,
seed_property: Optional[str] = None,
consecutive_ids: Optional[bool] = None,
relationship_weight_property: Optional[str] = None,
write_concurrency: Optional[Any] = None,
write_to_result_store: Optional[bool] = None,
) -> Series[Any]:
"""
Executes the WCC algorithm and writes the results to the Neo4j database.

Parameters
----------
G : Graph
The graph to run the algorithm on
write_property : str
The property name to write component IDs to
min_component_size : Optional[int], default=None
Don't write components with fewer nodes than this
threshold : Optional[float], default=None
The minimum required weight to consider a relationship during traversal
relationship_types : Optional[List[str]], default=None
The relationship types to project
node_labels : Optional[List[str]], default=None
The node labels to project
sudo : Optional[bool], default=None
Run analysis with admin permission
log_progress : Optional[bool], default=None
Whether to log progress
username : Optional[str], default=None
The username to attribute the procedure run to
concurrency : Optional[Any], default=None
The number of concurrent threads
job_id : Optional[Any], default=None
An identifier for the job
seed_property : Optional[str], default=None
Defines node properties that are used as initial component identifiers
consecutive_ids : Optional[bool], default=None
Flag to decide whether component identifiers are mapped into a consecutive id space
relationship_weight_property : Optional[str], default=None
The property name that contains weight
write_concurrency : Optional[Any], default=None
The number of concurrent threads during the write phase
write_to_result_store : Optional[bool], default=None
Whether to write the results to the result store

Returns
-------
Series
Algorithm metrics and statistics
"""
pass
Empty file.
Loading