Skip to content

Models

domain.enrichment.models

Summary

Pydantic models for enrichment patterns: a discriminated union of pattern payloads (Pattern) and a versioned PatternRegistry lookup table compiled by the pipeline loaders.


Notes

Guarantees:

  • Pattern discriminates on the type field, so a payload whose marker does not match its shape fails pydantic validation.

Lifecycle:

  • Registries are assembled once per load from the packaged resources/patterns/*.yaml files and treated as read-only after construction.

Classes

ArrayPattern

Bases: BasePattern

Ordered list pattern, e.g. negative candidate lists.

Attributes:

Name Type Description
type Literal[ARRAY]

Constant marker for this shape.

array List

The ordered list payload.

BasePattern

Bases: BaseModel

Base class for all pattern payloads.

Attributes:

Name Type Description
type PatternType

Discriminator identifying the concrete pattern shape.

KeywordsPattern

Bases: BasePattern

Keyword list pattern.

Attributes:

Name Type Description
type Literal[KEYWORDS]

Constant marker for this shape.

items List[str]

Keywords that match, in any order.

MappingPattern

Bases: BasePattern

Key/value mapping pattern.

Attributes:

Name Type Description
type Literal[MAPPING]

Constant marker for this shape.

mapping Dict[str, Union[str, MappingValue, List]]

Mapping keys to bare strings, structured values, or lists.

MappingValue

Bases: BaseModel

A single mapping entry value carrying an id and display name.

Attributes:

Name Type Description
id str

Stable identifier for the mapped value.

name str

Human-readable display name.

PatternRegistry

Bases: BaseModel

Versioned registry of named enrichment patterns.

Accessors dispatch on the runtime pattern type and raise TypeError when the stored pattern has a different shape than requested.

Attributes:

Name Type Description
version int

Registry schema version.

patterns Dict[str, Pattern]

Named patterns keyed by their registry name.

Functions
array
array(name: str) -> List

Return the array payload of a named ArrayPattern.

Parameters:

Name Type Description Default
name str

Registry name of the pattern.

required

Returns:

Name Type Description
List List

The pattern's array payload.

Raises:

Type Description
TypeError

If the stored pattern is not an ArrayPattern.

get
get(name: str) -> Pattern

Return the pattern registered under name.

Parameters:

Name Type Description Default
name str

Registry name of the pattern.

required

Returns:

Name Type Description
Pattern Pattern

The stored pattern payload.

Raises:

Type Description
KeyError

If no pattern is registered under name.

keywords
keywords(name: str) -> List[str]

Return the keyword items of a named KeywordsPattern.

Parameters:

Name Type Description Default
name str

Registry name of the pattern.

required

Returns:

Type Description
List[str]

List[str]: The pattern's item keywords.

Raises:

Type Description
TypeError

If the stored pattern is not a KeywordsPattern.

mapping
mapping(name: str) -> Dict[str, str]

Return the mapping of a named MappingPattern.

Parameters:

Name Type Description Default
name str

Registry name of the pattern.

required

Returns:

Type Description
Dict[str, str]

Dict[str, str]: The pattern's key/value mapping.

Raises:

Type Description
TypeError

If the stored pattern is not a MappingPattern.

regex
regex(name: str) -> re.Pattern

Return the compiled regex of a named RegexPattern.

Parameters:

Name Type Description Default
name str

Registry name of the pattern.

required

Returns:

Type Description
Pattern

re.Pattern: The pattern's compiled regex.

Raises:

Type Description
TypeError

If the stored pattern is not a RegexPattern.

regex_list
regex_list(name: str) -> List[re.Pattern]

Return compiled regexes of a named RegexListPattern.

Parameters:

Name Type Description Default
name str

Registry name of the pattern.

required

Returns:

Type Description
List[Pattern]

List[re.Pattern]: The pattern's compiled regexes.

Raises:

Type Description
TypeError

If the stored pattern is not a RegexListPattern.

regex_map
regex_map(name: str) -> List[Tuple[re.Pattern, str]]

Return compiled regex/value pairs of a RegexMapPattern.

Parameters:

Name Type Description Default
name str

Registry name of the pattern.

required

Returns:

Type Description
List[Tuple[Pattern, str]]

List[Tuple[re.Pattern, str]]: Compiled regex and value pairs.

Raises:

Type Description
TypeError

If the stored pattern is not a RegexMapPattern.

rules
rules(name: str) -> List[Dict]

Return the rule list of a named RulesPattern.

Parameters:

Name Type Description Default
name str

Registry name of the pattern.

required

Returns:

Type Description
List[Dict]

List[Dict]: The pattern's rule dicts.

Raises:

Type Description
TypeError

If the stored pattern is not a RulesPattern.

template
template(name: str) -> str

Return the template string of a named TemplatePattern.

Parameters:

Name Type Description Default
name str

Registry name of the pattern.

required

Returns:

Name Type Description
str str

The pattern's template string.

Raises:

Type Description
TypeError

If the stored pattern is not a TemplatePattern.

PatternType

Bases: str, Enum

Discriminator values selecting a concrete pattern shape.

Attributes:

Name Type Description
KEYWORDS PatternType

Keyword list pattern (KeywordsPattern).

MAPPING PatternType

Key/value mapping pattern (MappingPattern).

ARRAY PatternType

Plain array pattern (ArrayPattern).

RULES PatternType

Rule list pattern (RulesPattern).

REGEX PatternType

Single regex pattern (RegexPattern).

REGEX_LIST PatternType

List of regexes (RegexListPattern).

REGEX_MAP PatternType

Regex-to-value mapping (RegexMapPattern).

TEMPLATE PatternType

String template pattern (TemplatePattern).

RegexListPattern

Bases: BasePattern

List of regular expressions pattern.

Attributes:

Name Type Description
type Literal[REGEX_LIST]

Constant marker for this shape.

patterns List[str]

Regex sources compiled by compile_all.

Functions
compile_all
compile_all(flags: int = re.IGNORECASE) -> List[re.Pattern]

Compile every regex source in this pattern.

Parameters:

Name Type Description Default
flags int

Regex flags passed to re.compile; defaults to re.IGNORECASE.

IGNORECASE

Returns:

Type Description
List[Pattern]

List[re.Pattern]: One compiled regex per source.

Raises:

Type Description
error

If any source is not valid regex.

RegexMapPattern

Bases: BasePattern

Regex-to-value mapping pattern.

Attributes:

Name Type Description
type Literal[REGEX_MAP]

Constant marker for this shape.

mapping Dict[str, str]

Regex sources mapped to match values.

Functions
compile_all
1
2
3
compile_all(
    flags: int = re.IGNORECASE,
) -> List[Tuple[re.Pattern, str]]

Compile every regex in the mapping paired with its value.

Parameters:

Name Type Description Default
flags int

Regex flags passed to re.compile; defaults to re.IGNORECASE.

IGNORECASE

Returns:

Type Description
List[Tuple[Pattern, str]]

List[Tuple[re.Pattern, str]]: Compiled regex and value pairs.

Raises:

Type Description
error

If any source is not valid regex.

RegexPattern

Bases: BasePattern

Single regular expression pattern.

Attributes:

Name Type Description
type Literal[REGEX]

Constant marker for this shape.

pattern str

Regex source used to compile a matcher.

Functions
compile
compile(flags: int = re.IGNORECASE) -> re.Pattern

Compile this pattern's regex source.

Parameters:

Name Type Description Default
flags int

Regex flags passed to re.compile; defaults to re.IGNORECASE.

IGNORECASE

Returns:

Type Description
Pattern

re.Pattern: The compiled regex.

Raises:

Type Description
error

If pattern is not valid regex.

RulesPattern

Bases: BasePattern

List of rule dictionaries pattern.

Attributes:

Name Type Description
type Literal[RULES]

Constant marker for this shape.

rules List[Dict]

Rule dicts consumed by flag/tag rule evaluators.

TemplatePattern

Bases: BasePattern

String template pattern.

Attributes:

Name Type Description
type Literal[TEMPLATE]

Constant marker for this shape.

format str

Template string returned by the registry accessor.