Add lookup properties for components in Language

This commit is contained in:
Matthew Honnibal 2017-06-04 15:52:09 -05:00
parent e28f90b672
commit 939e8ed567
1 changed files with 29 additions and 0 deletions

View File

@ -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