Scrubber¤
The main class of the submodule, containing the main functions users will use.
Pipe
¤
A Pydantic dataclass containing a pipeline component.
Calls
The class is callable and returns a function that takes a string and returns a string.
Methods:
| Name | Description |
|---|---|
__call__ |
Call the pipeline component on the text. |
Source code in lexos/scrubber/scrubber.py
__call__(text: str) -> Callable
¤
Call the pipeline component on the text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to scrub. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
A function that takes a string and returns a string. |
Source code in lexos/scrubber/scrubber.py
name: str = Field(..., description='The name of the component.')
class-attribute
instance-attribute
¤
opts: Optional[dict[str, Any]] = Field(default={}, description='Options to pass to the component.')
class-attribute
instance-attribute
¤
factory: Optional[catalogue.Registry] = Field(default_factory=(lambda: scrubber_components), description='The factory to use to get the component.')
class-attribute
instance-attribute
¤
__call__(text: str) -> Callable
¤
Call the pipeline component on the text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to scrub. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
A function that takes a string and returns a string. |
Source code in lexos/scrubber/scrubber.py
Scrubber
¤
A class to scrub text using a pipeline of components.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the Scrubber object. |
add_pipe |
Add a component to the scrubber pipeline. |
pipe |
Scrub a list of texts with the current pipeline. |
remove_pipe |
Remove a component from the scrubber pipeline. |
reset |
Remove all components from the pipeline. |
scrub |
Run a text through the scrubber pipeline. |
Attributes:
| Name | Type | Description |
|---|---|---|
pipes |
list[Pipe]
|
Return a list of the names of the pipeline components. |
Source code in lexos/scrubber/scrubber.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
pipes: list[Pipe]
property
¤
Return a list of the names of the pipeline components.
__init__() -> None
¤
add_pipe(components: ScrubberComponent, *, before: Optional[str | int] = None, after: Optional[str | int] = None, first: Optional[bool] = None, last: Optional[bool] = None) -> None
¤
Add a component to the scrubber pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
ScrubberComponent
|
The component to add to the pipeline. If a string is passed, it is assumed to be the name of the component. If a tuple is passed, the first element is assumed to be the name of the component and the second element is assumed to be a dictionary of options to pass to the component. The method also accepts Pipe objects. |
required |
before
|
str | int
|
Name or index of the component to insert new component directly before. |
None
|
after
|
str | int
|
Name or index of the component to insert new component directly after. |
None
|
first
|
bool
|
If True, insert component first in the pipeline. |
None
|
last
|
bool
|
If True, insert component last in the pipeline. |
None
|
Source code in lexos/scrubber/scrubber.py
pipe(texts: Iterable[str], *, disable: Optional[list[str]] = [], component_cfg: Optional[dict[str, dict[str, Any]]] = {}) -> Iterable[str]
¤
Scrub a list of texts with the current pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
Iterable[str]
|
The text(s) to scrub. |
required |
disable
|
Optional[list[str]]
|
Names of pipeline components to disable. |
[]
|
component_cfg
|
Optional[dict[str, dict[str, Any]]]
|
Optional dictionary of keyword arguments for components, keyed by component names. Defaults to None. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Iterable |
Iterable[str]
|
An iterator of scrubbed texts. |
Source code in lexos/scrubber/scrubber.py
remove_pipe(components: str | Iterable[str]) -> None
¤
Remove a component from the scrubber pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
str | Iterable[str]
|
The name of the component to remove from the pipeline. |
required |
Source code in lexos/scrubber/scrubber.py
reset() -> None
¤
scrub(text: str) -> str
¤
Run a text through the scrubber pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to scrub. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The scrubbed text. |
Source code in lexos/scrubber/scrubber.py
__init__() -> None
¤
pipes: list[Pipe]
property
¤
Return a list of the names of the pipeline components.
_get_pipe_index(before: Optional[str | int] = None, after: Optional[str | int] = None, first: Optional[bool] = None, last: Optional[bool] = None) -> int
¤
Determine where to insert a pipeline component based on the before/after/first/last values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
before
|
str
|
Name or index of the component to insert directly before. |
None
|
after
|
str
|
Name or index of component to insert directly after. |
None
|
first
|
bool
|
If True, insert component first in the pipeline. |
None
|
last
|
bool
|
If True, insert component last in the pipeline. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The index of the new pipeline component. |
Source code in lexos/scrubber/scrubber.py
add_pipe(components: ScrubberComponent, *, before: Optional[str | int] = None, after: Optional[str | int] = None, first: Optional[bool] = None, last: Optional[bool] = None) -> None
¤
Add a component to the scrubber pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
ScrubberComponent
|
The component to add to the pipeline. If a string is passed, it is assumed to be the name of the component. If a tuple is passed, the first element is assumed to be the name of the component and the second element is assumed to be a dictionary of options to pass to the component. The method also accepts Pipe objects. |
required |
before
|
str | int
|
Name or index of the component to insert new component directly before. |
None
|
after
|
str | int
|
Name or index of the component to insert new component directly after. |
None
|
first
|
bool
|
If True, insert component first in the pipeline. |
None
|
last
|
bool
|
If True, insert component last in the pipeline. |
None
|
Source code in lexos/scrubber/scrubber.py
pipe(texts: Iterable[str], *, disable: Optional[list[str]] = [], component_cfg: Optional[dict[str, dict[str, Any]]] = {}) -> Iterable[str]
¤
Scrub a list of texts with the current pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
Iterable[str]
|
The text(s) to scrub. |
required |
disable
|
Optional[list[str]]
|
Names of pipeline components to disable. |
[]
|
component_cfg
|
Optional[dict[str, dict[str, Any]]]
|
Optional dictionary of keyword arguments for components, keyed by component names. Defaults to None. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Iterable |
Iterable[str]
|
An iterator of scrubbed texts. |
Source code in lexos/scrubber/scrubber.py
remove_pipe(components: str | Iterable[str]) -> None
¤
Remove a component from the scrubber pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
str | Iterable[str]
|
The name of the component to remove from the pipeline. |
required |
Source code in lexos/scrubber/scrubber.py
reset() -> None
¤
scrub(text: str) -> str
¤
Run a text through the scrubber pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to scrub. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The scrubbed text. |
Source code in lexos/scrubber/scrubber.py
scrub(text: str, pipeline: PipelineComponents, factory: Optional[catalogue.Registry] = scrubber_components) -> str
¤
Scrub a text with a pipeline of components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to scrub. |
required |
pipeline
|
PipelineComponents
|
An iterable of components. These can be functions, partial functions, Pipe objects, tuple, or strings. If a string is passed, it is assumed to be the name of the component. If a tuple is passed, the first element is assumed to be the name of the component and the second element is assumed to be a dictionary of options to pass. |
required |
factory
|
Optional[Registry]
|
The factory to use to get the components. Defaults to scrubber_components. |
scrubber_components
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The scrubbed text. |