-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguess_prob.py
More file actions
183 lines (131 loc) · 4.44 KB
/
guess_prob.py
File metadata and controls
183 lines (131 loc) · 4.44 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import re
import csv
import os
import string
valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
prob_dict = {}
sample_dict = {}
stat_dict={}
def cleanse_str(test):
test = test.strip()
test = test.replace("v1","v_one");
test = test.replace("v2","v_two");
test = test.replace('-','');
test = test.replace('_','');
test = test.replace('(','');
test = test.replace(')','');
test = ''.join(test.split())
test = test.lower()
return test
def create_sample():
os.system("mkdir -p samples")
with open("../prob_list.csv") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
number = row[0]
name = row[1]
sample_dict[number] = "samples/"+number;
cmd = "mkdir -p "+sample_dict[number]
#print cmd
os.system(cmd)
name = cleanse_str(name)
stat_dict[number] = 0
prob_dict[name] = number
# prob_dict[number] = number
def guess_by_name(curname):
key = curname
if key in prob_dict:
return prob_dict[key]
match = re.search(r"([a-z]+)$", curname)
if match:
key = match.group(1).strip()
if key in prob_dict:
return prob_dict[key]
match = re.search(r"^([a-z]+)", curname)
if match:
key = match.group(1).strip()
if key in prob_dict:
return prob_dict[key]
return ""
def guess_by_number(curname):
key = curname
if key in prob_dict:
return prob_dict[key]
match = re.search(r"(\d+)$", curname)
if match:
key = str(int(match.group(1).strip()))
if key in prob_dict:
return prob_dict[key]
match = re.search(r"^(\d+).*", curname)
if match:
key = str(int(match.group(1).strip()))
if key in prob_dict:
return prob_dict[key]
return ""
def ignore_by_name(curname):
match = re.search(r"test", curname)
if match:
return True
return False
create_sample()
ext_dic = {".cpp":1, ".c":2, ".hpp":3, ".h":4, ".java":11, ".js":12, ".py":21, ".go":31}
num_tested = 0
num_mapped = 0;
f = open("../file_list.txt", "r")
for line in f:
test = line.strip()
curext = os.path.splitext(test)[1]
if curext not in ext_dic:
continue
test = cleanse_str(test)
#filename
curbase = os.path.basename(test);
curbase = os.path.splitext(curbase)[0]
curbase = curbase.replace('.','')
curbase = ''.join(c for c in curbase if c in valid_chars)
#remove filename and check dir
curdir = os.path.basename(os.path.dirname(test))
curdir = curdir.replace('.','')
#remove filename and check dir
prvdir = os.path.basename(os.path.dirname(os.path.dirname(test)))
prvdir = prvdir.replace('.','')
print("======{}:{}:{}:{}".format(curbase, curdir, prvdir, test))
if(ignore_by_name(curdir) or ignore_by_name(curbase)):
continue
cur_dict = {}
prob_num = guess_by_name(curbase)
if prob_num is not "":
cur_dict[prob_num] = cur_dict.get(prob_num, 0) + 1
prob_num = guess_by_number(curbase)
if prob_num is not "":
cur_dict[prob_num] = cur_dict.get(prob_num, 0) + 1
if len(cur_dict) == 0:
prob_num = guess_by_name(curdir)
if prob_num is not "":
cur_dict[prob_num] = cur_dict.get(prob_num, 0) + 1
prob_num = guess_by_name(prvdir)
if prob_num is not "":
cur_dict[prob_num] = cur_dict.get(prob_num, 0) + 1
prob_num = guess_by_number(curdir)
if prob_num is not "":
cur_dict[prob_num] = cur_dict.get(prob_num, 0) + 1
prob_num = guess_by_number(prvdir)
if prob_num is not "":
cur_dict[prob_num] = cur_dict.get(prob_num, 0) + 1
num_tested = num_tested+1
if len(cur_dict) == 0:
print ("{} {}".format("??", line))
elif len(cur_dict) == 1:
num_mapped = num_mapped+1
for key in cur_dict:
print ("{} {}".format(key, line))
cmd = "ln -sf \"../../"+line.strip()+"\" "+sample_dict[key]+"/"+str(stat_dict[key])+curext
print(cmd)
os.system(cmd)
stat_dict[key] = stat_dict[key] + 1
else:
for key in cur_dict:
print ("!!{} {}".format(key, line))
print (num_mapped,"/",num_tested)
for key in sorted(stat_dict):
print ("{} {}".format(key, stat_dict[key]))