-
Notifications
You must be signed in to change notification settings - Fork 0
/
Processing.py
executable file
·54 lines (41 loc) · 1.38 KB
/
Processing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import jieba
import numpy as np
class ClfCore:
def __init__(self):
self.matrix=np.ones((4,8),np.int)
self.loadData()
def loadData(self):
filename = 'Data/Data.txt'
data = open(filename, 'r',encoding='utf-8')
lines = data.readlines()
self.KeyWords=[]
for line in lines:
line = line.replace('\n','')
lineItems=line.split(',')
self.KeyWords.append(lineItems)
def getClassIndex(self,textKeywords):
for index in range(8):
line = self.KeyWords[index]
for keyword in textKeywords:
if(keyword in line):
return index
return 0
def getKewwords(self,text):
content_seg = jieba.cut(text)
kewwords=' '.join(content_seg)
return kewwords.split()
def predict(self,text):
keywords = self.getKewwords(text)
classIndex=self.getClassIndex(keywords)
proList=self.matrix[:,classIndex]
return classIndex,proList
def updateMatrix(self,imgIndex,classIndex):
self.matrix[imgIndex,classIndex]+=1
# self.printMatrix()
def printMatrix(self):
print(self.matrix)
# clf=ClfCore()
# # ks=clf.getKewwords('高兴赞佩喜悦跃跃欲试')
# clf.updateMatrix(0,5)
# clf.printMatrix()
# print(ks)