-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuggester.py
More file actions
64 lines (45 loc) · 2 KB
/
Copy pathSuggester.py
File metadata and controls
64 lines (45 loc) · 2 KB
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
55
56
57
58
59
60
61
62
63
64
from collections import Counter
def count_suggestion_occurrence(suggestion_link_dict):
suggestion_list = []
for link_kind, links in suggestion_link_dict.items():
if link_kind != "Kind":
suggestion_list.extend(links)
counted_suggestions = Counter(suggestion_list)
return counted_suggestions
def order_suggestions_by_occurence(suggestions):
ordered_suggestions = {}
for item in suggestions:
if not (suggestions[item] in ordered_suggestions):
ordered_suggestions[suggestions[item]] = [item]
else:
ordered_suggestions[suggestions[item]].append(item)
return ordered_suggestions
def bin_suggestions(suggestions):
for method, suggestion in suggestions.items():
links = []
same_class = []
method_class = method.split('_')[0]
for rank, items in suggestion.items():
if rank != "Kind":
for item in items:
item_class = item.split('_')[0]
if item == method:
suggestion[rank].remove(item)
elif item in suggestions:
if suggestions[item]["Kind"] == "Removed":
links.append(item)
suggestion[rank].remove(item)
elif item_class == method_class:
same_class.append(item)
suggestion[rank].remove(item)
suggestion.update({"Links": links})
suggestion.update({"Likely": same_class})
return suggestions
def get_suggestion(final_link_results):
suggestions = {}
for method in final_link_results["Methods"]:
suggestions[method] = {"Kind": final_link_results["Methods"][method]["Kind"]}
suggestion_occurence = count_suggestion_occurrence(final_link_results["Methods"][method])
suggestions[method].update(order_suggestions_by_occurence(suggestion_occurence))
bin_suggestions(suggestions)
return suggestions