forked from mahnooshshd/extract_method
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_candidates.py
More file actions
113 lines (82 loc) · 3.18 KB
/
Copy pathget_candidates.py
File metadata and controls
113 lines (82 loc) · 3.18 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from extract_base_graph import *
from source_code_parser import count_loc
import math
import csv
ignore_files = []
def get_dataset_data(project_path):
data_path = project_path + '/candidate_Long_Methods.csv'
res = []
with open(data_path, newline='') as csvfile:
spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
for row in spamreader:
# print(row)
if len(row) > 1:
row_data = [row[0].split(';')[0], row[1].split(';')[0]]
if not row[1].split(';')[0] in ignore_files:
res.append(row_data)
# print(len(res), res)
return res
def get_candidate_functions(graph_res, project_path):
inter_closeness = graph_res['internal_closeness']
exter_closeness = graph_res['external_closeness']
last_id = graph_res['last_id']
internal_g = graph_res['internal_graph']
exeternal_g = graph_res['external_graph']
observed = []
total_counter_nim = 0
total_counter_1 = 0
total_counter_2 = 0
total_counter_3 = 0
total_counter_4 = 0
same_methods_counter_nim = 0
same_methods_counter_1 = 0
same_methods_counter_2 = 0
same_methods_counter_3 = 0
same_methods_counter_4 = 0
# dataset = get_dataset_data(project_path)
candidate_funcions = []
for node_id in range(last_id):
try:
method_hir = internal_g.nodes[node_id]['name']
except:
method_hir = exeternal_g.nodes[node_id]['name']
if method_hir in observed:
continue
observed.append(method_hir)
DE = (inter_closeness.get(node_id, 0) + 1) / (exter_closeness.get(node_id, 0) + 1)
method_parents = method_hir.split('->')
num_loc = count_loc(method_parents[-2], method_parents[-1], project_path)
if num_loc is not None:
res = DE + math.exp((num_loc-40)/10)
if res > 0.5:
if '$' in method_parents[-2]:
class_name = method_parents[-2].split('$')[0]
else:
class_name = method_parents[-2]
total_counter_nim += 1
candidate_funcions.append(method_parents)
if res > 1:
if '$' in method_parents[-2]:
class_name = method_parents[-2].split('$')[0]
else:
class_name = method_parents[-2]
total_counter_1 += 1
if res > 2:
if '$' in method_parents[-2]:
class_name = method_parents[-2].split('$')[0]
else:
class_name = method_parents[-2]
total_counter_2 += 1
if res > 3:
if '$' in method_parents[-2]:
class_name = method_parents[-2].split('$')[0]
else:
class_name = method_parents[-2]
total_counter_3 += 1
if res > 4:
if '$' in method_parents[-2]:
class_name = method_parents[-2].split('$')[0]
else:
class_name = method_parents[-2]
total_counter_4 += 1
return candidate_funcions