Python 3.x 空间习惯分句

Python 3.x 空间习惯分句,python-3.x,spacy,Python 3.x,Spacy,我使用Spacy进行自定义分句,我需要参数化自定义分句表/单词,但我没有找到如何作为arugument传递函数 # Manual or Custom Based def mycustom_boundary(docx): for token in docx[:-1]: if token.text == '...': docx[token.i+1].is_sent_start = True return docx # Adding the r

我使用Spacy进行自定义分句,我需要参数化自定义分句表/单词,但我没有找到如何作为arugument传递函数

# Manual or Custom Based
def mycustom_boundary(docx):
    for token in docx[:-1]:
        if token.text == '...':
            docx[token.i+1].is_sent_start = True
    return docx

# Adding the rule before parsing
nlp.add_pipe(mycustom_boundary,before='parser')

请让我知道如何将基于自定义的拆分器作为列表作为参数发送到函数?

您可以将组件转换为一个可以使用分隔符列表初始化的类?例如:

类MyCustomBoundary(对象):
定义初始化(self,分隔符):
self.delimiters=分隔符
def uu call uu(self,doc):#在对doc调用时应用此选项
对于文档[:-1]中的令牌:
如果self.delimiters中的token.text:
doc[token.i+1]。是否已发送\u start=True
退货单
然后可以将其添加到管道中,如下所示:

mycustom\u boundary=MyCustomBoundary(分隔符=['…','--')
nlp.add_管道(mycustom_边界,在='parser'之前)