【发布时间】:2020-10-10 23:53:23
【问题描述】:
我正在尝试从文本文件中修复错误合并的西班牙语单词,并且我正在使用 Spacy 的 retokenizer.split,但是,我想在 retokenizer.split 中概括 orth 的参数。我有下一个代码
doc= nlp("the wordsare wronly merged and weneed split them") #example
words = ["wordsare"] # Example: words to be split
matcher = PhraseMatcher(nlp.vocab)
patterns = [nlp.make_doc(text) for text in words]
matcher.add("Terminology", None, *patterns)
matches = matcher(doc)
with doc.retokenize() as retokenizer:
for match_id, start, end in matches:
heads = [(doc[start],1), doc[start]]
attrs = {"POS": ["PROPN", "PROPN"], "DEP": ["pobj", "compound"]}
orths= [str(doc[start]),str(doc[end])]
retokenizer.split(doc[start], orths=orths, heads=heads, attrs=attrs)
token_split=[token.text for token in doc]
print(token_split)
但是当我将 orths 放在 orths= [str(doc[start]),str(doc[end])] 而不是 ["words","are"] 时,我得到了这个错误:
ValueError: [E117] 新拆分的标记必须与原始标记的文本匹配。新的 orths:wordsarewrongly。旧文本:wordsare。
我想要一些关于概括的帮助,因为我希望代码不仅仅是修复单词 wordsare 还要修复单词 weneed 和其他文件本来可以的。
【问题讨论】: