Skip to content

Deterministic

matchlab.models.linkers.deterministic

A linking methodology based on a deterministic set of conditions.

Classes:

  • DeterministicLinker

    A deterministic linker that links based on a set of boolean conditions.

DeterministicLinker

Bases: Linker


              flowchart TD
              matchlab.models.linkers.deterministic.DeterministicLinker[DeterministicLinker]
              matchlab.models.linkers.base.Linker[Linker]

                              matchlab.models.linkers.base.Linker --> matchlab.models.linkers.deterministic.DeterministicLinker
                


              click matchlab.models.linkers.deterministic.DeterministicLinker href "" "matchlab.models.linkers.deterministic.DeterministicLinker"
              click matchlab.models.linkers.base.Linker href "" "matchlab.models.linkers.base.Linker"
            

A deterministic linker that links based on a set of boolean conditions.

Uses DuckDB as the SQL backend, enabling rich SQL operations while maintaining a Polars DataFrame interface. Supports both parallel matching (single round) and sequential matching (multiple rounds where matched records are removed after each round).

Methods:

  • validate_comparison

    Normalise to a list of rounds, and validate each comparison string.

  • prepare

    No preparation needed.

  • link

    Link the left and right dataframes.

Attributes:

version class-attribute

version: int = 1

comparisons class-attribute instance-attribute

comparisons: list[SQLCondition] | list[list[SQLCondition]] = Field(description='\n            Match conditions, in DuckDB SQL. Qualify every column with `l` or `r`.\n\n            A flat list applies every condition in parallel, unioned with OR logic:\n\n                [\n                    "l.company_number = r.company_number",\n                    "l.name = r.name",\n                ]\n\n            A nested list runs sequential rounds instead. Conditions within a round\n            use OR logic. After a round, matched records leave the pool before the\n            next round runs:\n\n                [\n                    [\n                        "l.company_number = r.company_number",\n                        "l.name = r.name",\n                    ],\n                    [\n                        "l.name_normalised = r.name_normalised",\n                        "l.website = r.website",\n                    ],\n                ]\n\n            Supports any DuckDB SQL expression, not just equality.\n        ')

model_config class-attribute instance-attribute

model_config = ConfigDict(extra='forbid', frozen=True)

left_id class-attribute instance-attribute

left_id: Literal['id'] = Field(default='id', description='The unique ID field in the left data')

right_id class-attribute instance-attribute

right_id: Literal['id'] = Field(default='id', description='The unique ID field in the right data')

validate_comparison classmethod

validate_comparison(value: SQLCondition | list[SQLCondition] | list[list[SQLCondition]]) -> list[list[SQLCondition]]

Normalise to a list of rounds, and validate each comparison string.

prepare

prepare(left: DataFrame, right: DataFrame) -> None

No preparation needed.

link(left: DataFrame, right: DataFrame) -> DataFrame

Link the left and right dataframes.

If comparisons is a flat list, applies all comparisons in parallel. If comparisons is a nested list, applies each round sequentially, removing matched records from the pool after each round.