rechu.matcher package

Submodules

rechu.matcher.base module

Database entity matching methods.

class rechu.matcher.base.Matcher[source]

Bases: Generic[IT, CT]

Generic item candidate model matcher.

add_map(candidate: CT) bool[source]

Manually add a candidate model to a mapping of unique keys. Returns whether the entity was actually added, which is not done if the map is not initialized or the keys are not unique enough.

check_map(candidate: CT) CT | None[source]

Retrieve a candidate model obtained from the database which has one or more of the unique keys in common with the provided candidate. If no such candidate is found, then None is returned. Any returned candidate should be considered read-only due to it coming from an earlier session that is already closed.

discard_map(candidate: CT) bool[source]

Remove a candidate model to a mapping of unique keys. Returns whether the entity was actually removed.

fill_map(inventory: Inventory[CT]) None[source]

Update a mapping of unique keys of candidate models from a filled inventory.

filter_duplicate_candidates(candidates: Iterable[tuple[CT, IT]]) Iterator[tuple[CT, IT]][source]

Detect if item models were matched against multiple candidates and filter out such models.

find_candidates(session: Session, items: Collection[IT] | None = None, extra: Collection[CT] | None = None, only_unmatched: bool = False) Iterator[tuple[CT, IT]][source]

Detect candidate models in the database that match items. Optionally, the items may be provided, which might not have been inserted or updated in the database, otherwise all items from the database are attempted for matching. Moreover, extra candidates may be provided, which in their case augment those from the database. If only_unmatched is enabled, then only items that do not have a relation with a candidate model are attempted for matching. The resulting iterator provides tuples of matches between candidates and items which have not had an update to their match relationship yet; multiple candidate models may be indicated for a single item model.

load_map(session: Session) None[source]

Create a mapping of unique keys of candidate models to their database entities.

match(candidate: CT, item: IT) bool[source]

Check if a candidate model matches an item model without looking up through the database.

rechu.matcher.product module

Product metadata matcher.

class rechu.matcher.product.ProductMatcher[source]

Bases: Matcher[ProductItem, Product]

Matcher for receipt product items and product metadata.

IND_MAXIMUM = 'maximum'
IND_MINIMUM = 'minimum'
MAP_GTIN = 'gtin'
MAP_MATCH = 'match'
MAP_SKU = 'sku'
add_map(candidate: Product) bool[source]

Manually add a candidate model to a mapping of unique keys. Returns whether the entity was actually added, which is not done if the map is not initialized or the keys are not unique enough.

check_map(candidate: Product) Product | None[source]

Retrieve a candidate model obtained from the database which has one or more of the unique keys in common with the provided candidate. If no such candidate is found, then None is returned. Any returned candidate should be considered read-only due to it coming from an earlier session that is already closed.

discard_map(candidate: Product) bool[source]

Remove a candidate model to a mapping of unique keys. Returns whether the entity was actually removed.

find_candidates(session: Session, items: Collection[ProductItem] | None = None, extra: Collection[Product] | None = None, only_unmatched: bool = False) Iterator[tuple[Product, ProductItem]][source]

Detect candidate models in the database that match items. Optionally, the items may be provided, which might not have been inserted or updated in the database, otherwise all items from the database are attempted for matching. Moreover, extra candidates may be provided, which in their case augment those from the database. If only_unmatched is enabled, then only items that do not have a relation with a candidate model are attempted for matching. The resulting iterator provides tuples of matches between candidates and items which have not had an update to their match relationship yet; multiple candidate models may be indicated for a single item model.

load_map(session: Session) None[source]

Create a mapping of unique keys of candidate models to their database entities.

match(candidate: Product, item: ProductItem) bool[source]

Check if a candidate model matches an item model without looking up through the database.

Module contents

Entity matching submodule.