python中 invalid syntax一直改不好,请问哪里错了?有关textrank实现特定文本摘要,nltk库中的sent_tokenize( )函数实现文本内容分割

img


用到python的nltk库中的sent_tokenize( )函数实现文本内容分割,最后一行怎么改都是invalid syntax

不知道df的数据结构是什么样的,将sentences.append(str(sent_tokenize(s)))中的str去掉,同时变量名最好不要重复。如下示例代码运行结果正常:

from nltk.tokenize import sent_tokenize,word_tokenize
text = ["He is so lucky. he won a lottery.","It's a good news! Have a nice day!"]
sents=[]
for s in text:
    sents.append(sent_tokenize(s))
words=[word_tokenize(x) for y in sents for x in y]
print(words)
sentences=[x for y in sents for x in y]
print(sentences)