我有一个句子列表:
text = ['cant railway station','citadel hotel',' police stn'].
我需要形成双字母对,并将它们存储在变量中。问题是当我这样做时,我得到一对句子而不是单词。这是我所做的:
text2 = [[word for word in line.split()] for line in text]
bigrams = nltk.bigrams(text2)
print(bigrams)
产生
[(['cant', 'railway', 'station'], ['citadel', 'hotel']), (['citadel', 'hotel'], ['police', 'stn'])
火车站和城堡酒店不能合二为一。我想要的是
[([cant],[railway]),([railway],[station]),([citadel,hotel]), and so on...
第一个句子的最后一个单词不应与第二个句子的第一个单词合并。我应该怎么做才能使其正常工作?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句