-
Notifications
You must be signed in to change notification settings - Fork 0
/
sr_main.py
35 lines (26 loc) · 719 Bytes
/
sr_main.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
from os.path import isfile
import pickle
def loadModel(fileName) :
if isfile(fileName):
print("SR ## File Loaded",fileName)
f = open(fileName, 'rb')
s = pickle.load(f)
f.close()
return s
else:
print("SR ## File Tidak Ada")
return 0
def getKey(item):
return item[1]
def wordRanking(model, arr) :
model = loadModel(model)
tmp = []
for line in arr:
try:
freq = model[line.lower()]
tmp.append([line,round(freq,3)])
except:
tmp.append([line, 0])
tmp = sorted(tmp, key=getKey, reverse=True)
return tmp
# print(wordRanking(model,['owner','holder','buyer','master','teacher']))