Skip to content
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

Connect to_hierarchical_clusters into the process with new Results and insert_results #34

Merged
merged 23 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
34 changes: 4 additions & 30 deletions src/matchbox/client/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
from matchbox.client.models.dedupers.base import Deduper
from matchbox.client.models.linkers.base import Linker
from matchbox.client.results import (
ClusterResults,
ModelMetadata,
ModelType,
ProbabilityResults,
Results,
)
from matchbox.common.exceptions import MatchboxResolutionError
from matchbox.common.transform import to_clusters
from matchbox.server import MatchboxDBAdapter, inject_backend
from matchbox.server.base import MatchboxModelAdapter

Expand Down Expand Up @@ -74,18 +71,6 @@ def insert_model(self) -> None:
)
self._connect()

@property
@ensure_connection
def probabilities(self) -> ProbabilityResults:
"""Retrieve probabilities associated with the model from the database."""
return self._model.probabilities

@property
@ensure_connection
def clusters(self) -> ClusterResults:
"""Retrieve clusters associated with the model from the database."""
return self._model.clusters

@property
@ensure_connection
def results(self) -> Results:
Expand Down Expand Up @@ -128,8 +113,8 @@ def ancestors_cache(self, ancestors_cache: dict[str, float]) -> None:
"""Set the ancestors cache of the model."""
self._model.ancestors_cache = ancestors_cache

def calculate_probabilities(self) -> ProbabilityResults:
"""Calculate probabilities for the model."""
def run(self) -> Results:
"""Execute the model pipeline and return results."""
if self.metadata.type == ModelType.LINKER:
if self.right_data is None:
raise MatchboxResolutionError("Right dataset required for linking")
Expand All @@ -140,23 +125,12 @@ def calculate_probabilities(self) -> ProbabilityResults:
else:
results = self.model_instance.dedupe(data=self.left_data)

return ProbabilityResults(
dataframe=results,
return Results(
probabilities=results,
model=self,
metadata=self.metadata,
)

def calculate_clusters(self, probabilities: ProbabilityResults) -> ClusterResults:
"""Calculate clusters for the model based on probabilities."""
return to_clusters(results=probabilities)

def run(self) -> Results:
"""Execute the model pipeline and return results."""
probabilities = self.calculate_probabilities()
clusters = self.calculate_clusters(probabilities)

return Results(model=self, probabilities=probabilities, clusters=clusters)


@inject_backend
def make_model(
Expand Down
Loading
Loading