MCPcopy Create free account
hub / github.com/Dod-o/Statistical-Learning-Method_Code / frequency_counter

Function frequency_counter

LSA/LSA.py:58–74  ·  view source on GitHub ↗

INPUT: text - (list) 文本列表 words - (list) 单词列表 OUTPUT: X - (array) 单词-文本矩阵

(text, words)

Source from the content-addressed store, hash-verified

56
57#定义构建单词-文本矩阵的函数,这里矩阵的每一项表示单词在文本中的出现频次,也可以用TF-IDF来表示
58def frequency_counter(text, words):
59 '''
60 INPUT:
61 text - (list) 文本列表
62 words - (list) 单词列表
63
64 OUTPUT:
65 X - (array) 单词-文本矩阵
66
67 '''
68 X = np.zeros((len(words), len(text))) #定义m*n的矩阵,其中m为单词列表中的单词个数,n为文本个数
69 for i in range(len(text)):
70 t = text[i] #读取文本列表中的第i条文本
71 for w in t:
72 ind = words.index(w) #取出第i条文本中的第t个单词在单词列表中的索引
73 X[ind][i] += 1 #对应位置的单词出现频次加一
74 return X
75
76
77#定义潜在语义分析函数

Callers 1

LSA.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected