空格自定句拆分 [英] Spacy custom sentence spliting
本文介绍了空格自定句拆分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Spacy进行自定义句子拆分,我需要将Custom_delimeter/word参数化为句子拼写,但我不知道如何作为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')
请让我知道如何将基于自定义的拆分器作为参数发送为要运行的列表?
推荐答案
您可以将组件转换为可以使用分隔符列表进行初始化的类?例如:
class MyCustomBoundary(object):
def __init__(self, delimiters):
self.delimiters = delimiters
def __call__(self, doc): # this is applied when you call it on a Doc
for token in doc[:-1]:
if token.text in self.delimiters:
doc[token.i+1].is_sent_start = True
return doc
然后您可以将其添加到您的管道中,如下所示:
mycustom_boundary = MyCustomBoundary(delimiters=['...', '---'])
nlp.add_pipe(mycustom_boundary, before='parser')
这篇关于空格自定句拆分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文