mirror of https://github.com/explosion/spaCy.git
Update Language.replace_pipe for disabled components (#8729)
* Fix the index where the replacement in inserted to account for disabled components * Allow `Language.replace_pipe` to replace disabled components
This commit is contained in:
parent
d717593eb7
commit
e532c69475
|
@ -872,14 +872,14 @@ class Language:
|
||||||
|
|
||||||
DOCS: https://spacy.io/api/language#replace_pipe
|
DOCS: https://spacy.io/api/language#replace_pipe
|
||||||
"""
|
"""
|
||||||
if name not in self.pipe_names:
|
if name not in self.component_names:
|
||||||
raise ValueError(Errors.E001.format(name=name, opts=self.pipe_names))
|
raise ValueError(Errors.E001.format(name=name, opts=self.pipe_names))
|
||||||
if hasattr(factory_name, "__call__"):
|
if hasattr(factory_name, "__call__"):
|
||||||
err = Errors.E968.format(component=repr(factory_name), name=name)
|
err = Errors.E968.format(component=repr(factory_name), name=name)
|
||||||
raise ValueError(err)
|
raise ValueError(err)
|
||||||
# We need to delegate to Language.add_pipe here instead of just writing
|
# We need to delegate to Language.add_pipe here instead of just writing
|
||||||
# to Language.pipeline to make sure the configs are handled correctly
|
# to Language.pipeline to make sure the configs are handled correctly
|
||||||
pipe_index = self.pipe_names.index(name)
|
pipe_index = self.component_names.index(name)
|
||||||
self.remove_pipe(name)
|
self.remove_pipe(name)
|
||||||
if not len(self._components) or pipe_index == len(self._components):
|
if not len(self._components) or pipe_index == len(self._components):
|
||||||
# we have no components to insert before/after, or we're replacing the last component
|
# we have no components to insert before/after, or we're replacing the last component
|
||||||
|
|
Loading…
Reference in New Issue