-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyse_GUI.py
More file actions
40 lines (29 loc) · 1007 Bytes
/
analyse_GUI.py
File metadata and controls
40 lines (29 loc) · 1007 Bytes
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 19 13:32:28 2017
@author: koolok
"""
from multiprocessing import Pool
#from distanceC import distance_multi_GUI
from editdistancemulti import edidistance_multi_compress_GUI
def analyse_multi(word,base,label,k=1) :
if len(base) == 0 :
return -1
if len(base) == 1 :
return label[0]
pool = Pool()
all_distance = pool.starmap_async(edidistance_multi_compress_GUI, zip(base,[word]*len(base),label)).get()
pool.close()
# all_distance = dict(zip(label, all_distance))
#
# all_distance = sorted(label, key=all_distance.__getitem__)
all_distance = sorted(all_distance, key=lambda tup: tup[1])
votes = [0]*10
Nearest = []
for i in range(k):
votes[all_distance[i][0]] +=1
Nearest.append(all_distance[i][2])
if max(votes) == 1 :
return word, all_distance[0][0], Nearest
return word, votes.index(max(votes)), Nearest