gpt4 book ai didi

python - 从 NLTK 语料库中检索句子字符串

转载 作者:行者123 更新时间:2023-11-28 21:15:28 26 4
gpt4 key购买 nike

这是我的数据集:

emma=gutenberg.sents('austen-emma.txt')

它给了我句子

[[u'she',u'was',u'happy',[u'It',u'was',u'her',u'own',u'good']]

但这就是我想要得到的:

['she was happy','It was her own good']

最佳答案

根据 nltk docs,您似乎获得了正确的输出:

sents(fileids=None)[source]¶ Returns: the given file(s) as a list of sentences or utterances, each encoded as a list of word strings.

所以你只需要将你的单词字符串列表转回一个空格分隔的句子:

sentences = ["".join(list_of_words) for list_of_words in emma]

关于python - 从 NLTK 语料库中检索句子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30170556/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com