Disable one or more pipeline components. If used as a context manager, the pipeline will be restored to the initial state at the end of the block. Otherwise, a DisabledPipes object is returned, that has a `.restore()` method you can use to undo your changes. disable
(
self,
*,
disable: Optional[Union[str, Iterable[str]]] = None,
enable: Optional[Union[str, Iterable[str]]] = None,
)
| 1074 | return self.select_pipes(disable=names) |
| 1075 | |
| 1076 | def select_pipes( |
| 1077 | self, |
| 1078 | *, |
| 1079 | disable: Optional[Union[str, Iterable[str]]] = None, |
| 1080 | enable: Optional[Union[str, Iterable[str]]] = None, |
| 1081 | ) -> "DisabledPipes": |
| 1082 | """Disable one or more pipeline components. If used as a context |
| 1083 | manager, the pipeline will be restored to the initial state at the end |
| 1084 | of the block. Otherwise, a DisabledPipes object is returned, that has |
| 1085 | a `.restore()` method you can use to undo your changes. |
| 1086 | |
| 1087 | disable (str or iterable): The name(s) of the pipes to disable |
| 1088 | enable (str or iterable): The name(s) of the pipes to enable - all others will be disabled |
| 1089 | |
| 1090 | DOCS: https://spacy.io/api/language#select_pipes |
| 1091 | """ |
| 1092 | if enable is None and disable is None: |
| 1093 | raise ValueError(Errors.E991) |
| 1094 | if isinstance(disable, str): |
| 1095 | disable = [disable] |
| 1096 | if enable is not None: |
| 1097 | if isinstance(enable, str): |
| 1098 | enable = [enable] |
| 1099 | to_disable = [pipe for pipe in self.pipe_names if pipe not in enable] |
| 1100 | # raise an error if the enable and disable keywords are not consistent |
| 1101 | if disable is not None and disable != to_disable: |
| 1102 | raise ValueError( |
| 1103 | Errors.E992.format( |
| 1104 | enable=enable, disable=disable, names=self.pipe_names |
| 1105 | ) |
| 1106 | ) |
| 1107 | disable = to_disable |
| 1108 | assert disable is not None |
| 1109 | # DisabledPipes will restore the pipes in 'disable' when it's done, so we need to exclude |
| 1110 | # those pipes that were already disabled. |
| 1111 | disable = [d for d in disable if d not in self._disabled] |
| 1112 | return DisabledPipes(self, disable) |
| 1113 | |
| 1114 | def make_doc(self, text: str) -> Doc: |
| 1115 | """Turn a text into a Doc object. |