我如何添加到<s>每个句子的开头和每个句子</s>的结尾


pap = open('papdelete.txt', 'r')
content = pap.read()
content = content.lower()
nlp = spacy.load("en_core_web_sm")
SplitSentences = nlp(content)
First = nlp('<s>')
Last = nlp('</s>')
SplitSentences = [First.sents+ content +Last.sents for content in SplitSentences.sents]

上面的代码给了我一个

TypeError: unsupported operand type(s) for +: 'generator' and 'spacy.tokens.span.Span'.

pap.txt的内容:

"Why, my dear, you must know, Mrs. Long says that Netherfield is taken by a young man of large fortune from the north of England; that he came down on Monday in a chaise and four to see the place, and was so much delighted with it, that he agreed with Mr. Morris immediately; that he is to take possession before Michaelmas, and some of his servants are to be in the house by the end of next week."
"What is his name?"
"Bingley."
"Is he married or single?"
"Oh! Single, my dear, to be sure! A single man of large fortune; four or five thousand a year. What a fine thing for our girls!"

您尝试过f-string(或.format(吗?示例:

f"{First}{content}{Last}"

而不是最后一行中的CCD_ 1。

最新更新