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:
Patterndiscriminates on thetypefield, 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/*.yamlfiles 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
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 |
get
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 |
keywords
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 |
mapping
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 |
regex
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 |
regex_list
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
|
regex_map
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 |
rules
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 |
template
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 |
PatternType
Bases: str, Enum
Discriminator values selecting a concrete pattern shape.
Attributes:
| Name | Type | Description |
|---|---|---|
KEYWORDS |
PatternType
|
Keyword list pattern ( |
MAPPING |
PatternType
|
Key/value mapping pattern ( |
ARRAY |
PatternType
|
Plain array pattern ( |
RULES |
PatternType
|
Rule list pattern ( |
REGEX |
PatternType
|
Single regex pattern ( |
REGEX_LIST |
PatternType
|
List of regexes ( |
REGEX_MAP |
PatternType
|
Regex-to-value mapping ( |
TEMPLATE |
PatternType
|
String template pattern ( |
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 |
Functions
compile_all
Compile every regex source in this pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flags |
int
|
Regex flags passed to |
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
Compile every regex in the mapping paired with its value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flags |
int
|
Regex flags passed to |
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 this pattern's regex source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flags |
int
|
Regex flags passed to |
IGNORECASE
|
Returns:
| Type | Description |
|---|---|
Pattern
|
re.Pattern: The compiled regex. |
Raises:
| Type | Description |
|---|---|
error
|
If |
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. |