diff --git a/spacy/language.py b/spacy/language.py index 7fd56ed56..5a8c3e90c 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -255,6 +255,15 @@ class Language(object): unfound = before or after 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): """Replace a component in the pipeline. diff --git a/website/api/language.jade b/website/api/language.jade index 500d6c411..668cbadd7 100644 --- a/website/api/language.jade +++ b/website/api/language.jade @@ -327,6 +327,30 @@ p +cell bool +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 +tag method +tag-new(2)