Skip to content

Impl

pipelines.enrichment.entity.impl

Summary

Concrete entity-family implementations (dagpipe stage nodes + root).


Stage bodies are ports of domain/enrichment/entity/resolver.py, keeping the exact fork/confidence semantics. The root ImplEntityPipeline.enrich runs the hexa-wired stage graph through a dagpipe Engine (assembled in shared/loader.py) and delegates terminal processing to ImplEntityFinalizePort (port of EntityStatesProcessorAdaptor).

Classes

ImplCandidateFlagsPort

Bases: CandidateFlagsPort

Candidate-flags stage: keyword matches append candidate-based flags.

Attributes
candidate_based_flag_mapping property
candidate_based_flag_mapping

Keyword → flag mapping used for candidate flagging.

Returns:

Name Type Description
dict

The candidate-based flag mapping.

config property
config

Per-node config injected via set_config.

Returns:

Type Description

dict | None: The per-node config, or None before injection.

Functions
resolve
resolve(state: State) -> Iterable[State]

Append candidate flags whose keywords appear in the candidate value.

Parameters:

Name Type Description Default
state State

Incoming state carrying a candidate value and flags.

required

Yields:

Name Type Description
State Iterable[State]

A fork with updated candidate.flags when flags changed, else the unmodified state.

set_config
set_config(config)

Inject the per-node config.

Parameters:

Name Type Description Default
config dict

Per-node config from the dagpipe spec.

required
set_registry
set_registry(registry)

Inject the merged pattern registry.

Parameters:

Name Type Description Default
registry PatternRegistry

The merged pattern registry.

required

ImplEntityAliasPort

Bases: EntityAliasPort

Entity-alias stage: resolve the entity from the candidate via aliases.

Attributes
config property
config

Per-node config injected via set_config.

Returns:

Type Description

dict | None: The per-node config, or None before injection.

default_logo_mapping property
default_logo_mapping

Entity type → default logo mapping.

Returns:

Name Type Description
dict

The default logo mapping.

entity_alias_regex property
entity_alias_regex

Alias regex → name pairs used for entity resolution.

Returns:

Type Description

List[Tuple[re.Pattern, str]]: Compiled (regex, name) pairs.

entity_type_mapping property
entity_type_mapping

Entity id → type mapping used for entity resolution.

Returns:

Name Type Description
dict

The entity type mapping.

Functions
resolve
resolve(state: State) -> Iterable[State]

Resolve the entity from the candidate value via alias regexes.

Parameters:

Name Type Description Default
state State

Incoming state carrying a candidate value.

required

Yields:

Name Type Description
State Iterable[State]

A fork with the aliased entity payload, or the unmodified state when the name is already set or no alias matches.

set_config
set_config(config)

Inject the per-node config.

Parameters:

Name Type Description Default
config dict

Per-node config from the dagpipe spec.

required
set_registry
set_registry(registry)

Inject the merged pattern registry.

Parameters:

Name Type Description Default
registry PatternRegistry

The merged pattern registry.

required

ImplEntityFinalizePort

Bases: EntityFinalizePort

Finalize terminal states into the entity result dict.

Functions
process
process(states: List) -> dict

Build the entity result dict from the best terminal state.

Parameters:

Name Type Description Default
states List

Terminal states from the dagpipe graph.

required

Returns:

Name Type Description
dict dict

The entity result dict (name, id, type, logo, raw_candidate, candidate flags and tags).

ImplEntityPipeline

Bases: EntityPipeline

Concrete entity pipeline root wiring the stage ports.

Attributes:

Name Type Description
normalize ImplNormalizePort

Normalize stage port.

extract_candidates ImplExtractCandidatesPort

Extract-candidates port.

candidate_flags ImplCandidateFlagsPort

Candidate-flags port.

amount_flags ImplAmountFlagsPort

Amount-flags port.

set_entity ImplSetEntityPort

Set-entity port.

entity_alias ImplEntityAliasPort

Entity-alias port.

fallback ImplFallbackPort

Fallback port.

finalize ImplEntityFinalizePort

Terminal finalize port.

Functions
enrich
enrich(payload: dict) -> dict

Run the entity graph on a raw payload and finalize the result.

Parameters:

Name Type Description Default
payload dict

Raw transaction payload.

required

Returns:

Name Type Description
dict dict

The entity result dict from the finalize port.

ImplExtractCandidatesPort

Bases: ExtractCandidatesPort

Extract-candidates stage: signals → candidate value forks with penalties.

Attributes
candidate_regex property
candidate_regex

Candidate extraction regexes from the pattern registry.

Returns:

Type Description

List[re.Pattern]: Compiled candidate extraction regexes.

config property
config

Per-node config injected via set_config.

Returns:

Type Description

dict | None: The per-node config, or None before injection.

negative_candidates property
negative_candidates

Tokens excluded from candidate extraction.

Returns:

Name Type Description
List

The registered negative candidate tokens.

Functions
resolve
resolve(state: State) -> Iterable[State]

Yield candidate-value forks from signals, penalizing fallbacks.

Parameters:

Name Type Description Default
state State

Incoming state carrying signals.

required

Yields:

Name Type Description
State Iterable[State]

Forks carrying candidate.value for each accepted candidate (parts/items fallbacks penalized), or a single penalized fork when nothing matches.

set_config
set_config(config)

Inject the per-node config.

Parameters:

Name Type Description Default
config dict

Per-node config from the dagpipe spec.

required
set_registry
set_registry(registry)

Inject the merged pattern registry.

Parameters:

Name Type Description Default
registry PatternRegistry

The merged pattern registry.

required

ImplFallbackPort

Bases: FallbackPort

Terminal fallback stage: candidate merchant/person, else Unknown.

Attributes
config property
config

Per-node config injected via set_config.

Returns:

Type Description

dict | None: The per-node config, or None before injection.

Functions
resolve
resolve(state: State) -> Iterable[State]

Assign the terminal fallback entity when none was resolved.

Parameters:

Name Type Description Default
state State

Incoming terminal state.

required

Yields:

Name Type Description
State Iterable[State]

A fork carrying the fallback entity (candidate, Unknown, or the already-resolved entity).

set_config
set_config(config)

Inject the per-node config.

Parameters:

Name Type Description Default
config dict

Per-node config from the dagpipe spec.

required
set_registry
set_registry(registry)

Inject the merged pattern registry.

Parameters:

Name Type Description Default
registry PatternRegistry

The merged pattern registry.

required

ImplNormalizePort

Bases: NormalizePort

Normalize stage: strip number sequences, then build raw/items/parts signals.

Attributes
config property
config

Per-node config injected via set_config.

Returns:

Type Description

dict | None: The per-node config, or None before injection.

Functions
resolve
resolve(state: State) -> Iterable[State]

Clean raw.description and yield a single signals fork.

Parameters:

Name Type Description Default
state State

Incoming state carrying raw.description and the raw.amount/raw.balance values.

required

Yields:

Name Type Description
State Iterable[State]

A single fork populating signals.raw, signals.items and signals.parts.

set_config
set_config(config)

Inject the per-node config.

Parameters:

Name Type Description Default
config dict

Per-node config from the dagpipe spec.

required
set_registry
set_registry(registry)

Inject the merged pattern registry.

Parameters:

Name Type Description Default
registry PatternRegistry

The merged pattern registry.

required

ImplSetEntityPort

Bases: SetEntityPort

Set-entity stage: resolve the entity from candidate flags via rules.

Attributes
config property
config

Per-node config injected via set_config.

Returns:

Type Description

dict | None: The per-node config, or None before injection.

default_logo_mapping property
default_logo_mapping

Entity type → default logo mapping.

Returns:

Name Type Description
dict

The default logo mapping.

entity_type_mapping property
entity_type_mapping

Entity id → type mapping used for entity resolution.

Returns:

Name Type Description
dict

The entity type mapping.

flags_based_entity_rules property
flags_based_entity_rules

Flag-matching rules that emit the resolved entity.

Returns:

Type Description

List[Dict]: The ordered entity rules.

Functions
resolve
resolve(state: State) -> Iterable[State]

Resolve the entity from candidate flags using the first matching rule.

Parameters:

Name Type Description Default
state State

Incoming state carrying candidate flags.

required

Yields:

Name Type Description
State Iterable[State]

A fork with the resolved entity payload, the unmodified state when an entity name is already set, or a penalized fork when unresolvable.

set_config
set_config(config)

Inject the per-node config.

Parameters:

Name Type Description Default
config dict

Per-node config from the dagpipe spec.

required
set_registry
set_registry(registry)

Inject the merged pattern registry.

Parameters:

Name Type Description Default
registry PatternRegistry

The merged pattern registry.

required

Functions