Source code for redshred.enrichments.regex

# AUTOGENERATED FILE, DO NOT MANUALLY EDIT

from __future__ import annotations

from typing import Any, List, Literal  # noqa: F401

from pydantic import BaseModel, Field
from pydantic.main import object_setattr

from .base import PerspectiveConfiguration


[docs]class RegexPattern(BaseModel): """ Each Regex Pattern defined here will be queried against the input text(s). This allows you to define multiple patterns that you want to run across a single group of inputs in a single batch. """ label: str = Field( default=..., examples=["Talking about rodents", "has 'fish' in it"], title="Label", description="The human-readable label for this field, reference purposes only", ) flags: str = Field( default="", examples=["iX", "u"], title="Flags", description="Flags can only be in iuLmsX (see python documentation for details on each)", ) pattern: str = Field( default=..., examples=["^dog\\s+", "maps?"], title="Pattern", description="A regex pattern string" )
[docs]class RegexPerspectiveConfig(BaseModel): """ Configuration settings for the RegEx Enrichment """ search_patterns: List["RegexPattern"] = Field( default=..., examples=[{"label": "My Pattern Label", "flags": "i", "pattern": "My Search Pattern [\\w]+"}], title="Search Patterns", description="Each entry should be a readable label, and a 'flags' (if desired) and 'pattern' key", )
[docs] class Config: use_enum_values = True arbitrary_types_allowed = True
[docs]class RegexPerspective(PerspectiveConfiguration): """ Configuration settings for the RegEx Enrichment """ name: Literal["regex"] = Field(default="regex") config: RegexPerspectiveConfig = Field( default_factory=RegexPerspectiveConfig, description="Specific configuration options for the enrichment" ) def __init__(__pydantic_self__, **data: Any) -> None: super().__init__(**data) # we want to make sure that the _name_ attribute is _always_ serialized even when "exclude_unset" is True object_setattr(__pydantic_self__, "__fields_set__", __pydantic_self__.__fields_set__.union({"name"}))