Python-计算共现矩阵,窗口大小= 10

时间:2019-12-16 15:12:38

标签: python nlp text-mining

我找到了用于在固定窗口大小的python中计算共现矩阵的代码,但是我不能使用它们,并且其中一些不能很好地工作。 我在下面的代码中找到了窗口大小= 2的代码,但是我无法将其更改为大小= 5

import numpy as np
CORPUS=["abc def ijk pqr", "pqr klm opq", "lmn pqr xyz abc def pqr abc"]


top2000 = [ "abc","pqr","def"]#list(set((' '.join(ctxs)).split(' ')))
a = np.zeros((3,3), np.int32)
for  sentence in CORPUS:
    for index,word in enumerate(sentence.split(' ')):
       if word in top2000 : 
           print(word)
           context=GetContext(sentence,index)
           print(context)
           for word2 in context:
             if word2 in top2000:
                 a[top2000.index(word)][top2000.index(word2)]+=1
print(a)

我想要这样的函数:共现(a,b,w) 答:文件包含我的话 b:我的文件 w:窗口大小

0 个答案:

没有答案