From 939e8ed567c41af87cb264fe768d7dc5f45bf8f2 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 4 Jun 2017 15:52:09 -0500 Subject: [PATCH] Add lookup properties for components in Language --- spacy/language.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/spacy/language.py b/spacy/language.py index e559e7c58..f4966b106 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -184,6 +184,35 @@ class Language(object): flat_list.append(pipe) self.pipeline = flat_list + # Conveniences to access pipeline components + @property + def tensorizer(self): + return self.get_component('tensorizer') + + @property + def tagger(self): + return self.get_component('tagger') + + @property + def parser(self): + return self.get_component('parser') + + @property + def entity(self): + return self.get_component('ner') + + @property + def matcher(self): + return self.get_component('matcher') + + def get_component(self, name): + if self.pipeline in (True, None): + return None + for proc in self.pipeline: + if hasattr(proc, 'name') and proc.name.endswith(name): + return proc + return None + def __call__(self, text, disable=[]): """'Apply the pipeline to some text. The text can span multiple sentences, and can contain arbtrary whitespace. Alignment into the original string