首页 > 解决方案 > Python NLTK 意外的循环语料库数据丢失

问题描述

这里不是最喜欢python的,但必须将它用于NLTK。这就是为什么我怀疑我错过了一些简单的东西。

我有一个由文章组成的语料库,文章由句子组成。我还有以下功能:

unlabelled = [] #first word of a sentence
labelled = [] #all words of a sentence except the first
for article in corpora:
    for sent in article:
        print(list(sent)) #returns everything as it should be
        for i, w in enumerate(sent):
            if (i == 0): 
            unlabelled.append((w.lower(), w))
        else:
            labelled.append((w.lower(), w))
        print(list(sent)) #returns everything as it should be

for article in corpora:
    print(list(article)) #returns all empty

它不应该对语料库数据做任何事情,只是将其中的单词收集到两个列表中。在周期内,打印语料库数据表明它是完整的,没有任何变化。但是,循环后立即打印显示语料库突然为空,所有文章都是空数组,句子不再存在。

这里发生了什么,为什么?

标签: pythonfor-loopnltk

解决方案


推荐阅读