我有一项任务是使用NLTK分析N个文本。每个文本都超过10万字,所以计算机很难处理这么多数据,这就是为什么我决定在子列表中标记后拆分每个文本,如下所示:
chunks = [tokens_words[x:x+1000] for x in range (0,len(tokens_words), 1000)]
可能,它工作得很好。你知道吗
然后我需要计算,例如,每个文本中的名词数量。我是这样做的:
for chunk in chunks:
for key in tagged.keys():
for noun_tag in noun_tags:
if tagged[key] == noun_tag:
noun += 1
totalNoun.append(noun)
然后我使用sum()
并计算百分比。我也试过totalNoun += noun
,但在这两种情况下,我都能得到3500%或2498%的smth。你知道吗
我做错了什么?你知道吗
假设你有两块,一块有13个名词,一块有30个名词。您的代码将执行以下操作:
据我所知,您没有在每个块之后将
noun
设置为0。即:在
for chunk in chunks
循环中使用noun = 0
应该可以做到这一点。你知道吗相关问题 更多 >
编程相关推荐