Add lookup properties for components in Language
@@ -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
