当下面的代码运行时,它得到的类型错误如下:
Traceback (most recent call last):
File "Example.py", line 174, in <module>
for i,sentence in enumerate(clusters[cluster]):
TypeError: 'NoneType' object has no attribute '__getitem__'
如何解决这个问题?
if __name__ == "__main__":
sent=open('/Desktop/word2vec_original/input.txt', 'r').read()
sentences=sent_tokenize(sent)
print
nclusters= 3
clusters = cluster_sentences(sentences, nclusters)
for cluster in range(nclusters):
clusterSentence = []
for i,sentence in enumerate(clusters[cluster]):
posTaggedSentence = pos_tag(word_tokenize(sentences[sentence]))
posTaggedSentenceStr = (' '.join(word + '/' + pos for word, pos in posTaggedSentence))
posTaggedSentence.append(posTaggedSentenceStr.strip())
clusterSentence.append(posTaggedSentenceStr)