python - 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
它不应该对语料库数据做任何事情,只是将其中的单词收集到两个列表中。在周期内,打印语料库数据表明它是完整的,没有任何变化。但是,循环后立即打印显示语料库突然为空,所有文章都是空数组,句子不再存在。
这里发生了什么,为什么?
解决方案
推荐阅读
- web-site-project - 我做了一个网站,还没有分享,我如何吸引访问者?
- c# - 从列表中查找小于特定值的值列表
- identityserver4 - /Account/Login 在尝试登录 ABP Angular 应用程序时挂起
- postgresql - 播放框架 2.8 和 postgreSQL 12.5
- r - R:查找包含精确字符串匹配的文件,后跟_(忽略大小写)
- python - 为什么 numpy 在我实际尝试转换 int 时告诉我无法转换 float NaN?
- saxon - Saxon 6.5.5 jar 文件将在 android 4.2.2 中用于 XML 解析器
- angular - 来自 api 的数据未显示在 chart.js 中(角度)
- sql - Azure SQL 表大小与行数不一致
- javascript - Javascript不会在加载时启动脚本