Add Language.has_pipe method

This commit is contained in:
ines 2017-10-17 11:20:07 +02:00
parent 485c4f6df5
commit 8ca344712d
2 changed files with 33 additions and 0 deletions

View File

@ -255,6 +255,15 @@ class Language(object):
unfound = before or after unfound = before or after
raise ValueError(msg.format(unfound, self.pipe_names)) raise ValueError(msg.format(unfound, self.pipe_names))
def has_pipe(self, name):
"""Check if a component name is present in the pipeline. Equivalent to
`name in nlp.pipe_names`.
name (unicode): Name of the component.
RETURNS (bool): Whether a component of that name exists in the pipeline.
"""
return name in self.pipe_names
def replace_pipe(self, name, component): def replace_pipe(self, name, component):
"""Replace a component in the pipeline. """Replace a component in the pipeline.

View File

@ -327,6 +327,30 @@ p
+cell bool +cell bool
+cell Insert component last / not last in the pipeline. +cell Insert component last / not last in the pipeline.
+h(2, "has_pipe") Language.has_pipe
+tag method
+tag-new(2)
p
| Check whether a component is present in the pipeline. Equivalent to
| #[code name in nlp.pipe_names].
+aside-code("Example").
nlp.add_pipe(lambda doc: doc, name='component')
assert 'component' in nlp.pipe_names
assert nlp.has_pipe('component')
+table(["Name", "Type", "Description"])
+row
+cell #[code name]
+cell unicode
+cell Name of the pipeline component to check.
+row("foot")
+cell returns
+cell bool
+cell Whether a component of that name exists in the pipeline.
+h(2, "get_pipe") Language.get_pipe +h(2, "get_pipe") Language.get_pipe
+tag method +tag method
+tag-new(2) +tag-new(2)