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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import random
|
3 |
+
import os
|
4 |
+
import datasets
|
5 |
+
|
6 |
+
opt_out_github_login_the_stack_12 = '''tomas
|
7 |
+
bermannoah
|
8 |
+
rtzoeller
|
9 |
+
sdatkinson
|
10 |
+
jtth
|
11 |
+
benui-dev
|
12 |
+
DrTimothyAldenDavis
|
13 |
+
pranftw
|
14 |
+
marcsances
|
15 |
+
sitmo
|
16 |
+
jucor
|
17 |
+
digantamisra98
|
18 |
+
przemb
|
19 |
+
jisakiel
|
20 |
+
kellycochran
|
21 |
+
AkashM398
|
22 |
+
MeSayan
|
23 |
+
SWinxy
|
24 |
+
zitterbewegung
|
25 |
+
fredster33
|
26 |
+
demangejeremy
|
27 |
+
PPPI
|
28 |
+
henilp105
|
29 |
+
tobymcclean
|
30 |
+
cynddl
|
31 |
+
spate141
|
32 |
+
plaaosert
|
33 |
+
woylie
|
34 |
+
alexkoster
|
35 |
+
satyrnidae
|
36 |
+
rclark
|
37 |
+
zakkolar
|
38 |
+
jimscard
|
39 |
+
marjoleinF
|
40 |
+
ghchinoy
|
41 |
+
jmfadeley
|
42 |
+
fuhrmanator
|
43 |
+
stephen-three
|
44 |
+
retro-ai
|
45 |
+
abolouri
|
46 |
+
matthewheath
|
47 |
+
jollypolly123
|
48 |
+
RJRauch
|
49 |
+
ivansche
|
50 |
+
'''.splitlines()
|
51 |
+
|
52 |
+
paths = '''diffs_10485761_11010048.jsonl
|
53 |
+
diffs_1048577_1572864.jsonl
|
54 |
+
diffs_11010049_11534336.jsonl
|
55 |
+
diffs_11534337_12058624.jsonl
|
56 |
+
diffs_12058625_12582912.jsonl
|
57 |
+
diffs_12582913_13107200.jsonl
|
58 |
+
diffs_13107201_13631488.jsonl
|
59 |
+
diffs_13631489_14155776.jsonl
|
60 |
+
diffs_14155777_14680064.jsonl
|
61 |
+
diffs_14680065_15204352.jsonl
|
62 |
+
diffs_15204353_15728640.jsonl
|
63 |
+
diffs_15728641_16252928.jsonl
|
64 |
+
diffs_1572865_2097152.jsonl
|
65 |
+
diffs_16252929_16777216.jsonl
|
66 |
+
diffs_1_524288.jsonl
|
67 |
+
diffs_2097153_2621440.jsonl
|
68 |
+
diffs_25165825_25690112.jsonl
|
69 |
+
diffs_25690113_26214400.jsonl
|
70 |
+
diffs_26214401_26738688.jsonl
|
71 |
+
diffs_2621441_3145728.jsonl
|
72 |
+
diffs_26738689_27262976.jsonl
|
73 |
+
diffs_27262977_27787264.jsonl
|
74 |
+
diffs_27787265_28311552.jsonl
|
75 |
+
diffs_28311553_28835840.jsonl
|
76 |
+
diffs_28835841_29360128.jsonl
|
77 |
+
diffs_29360129_29884416.jsonl
|
78 |
+
diffs_29884417_30408704.jsonl
|
79 |
+
diffs_30408705_30932992.jsonl
|
80 |
+
diffs_30932993_31457280.jsonl
|
81 |
+
diffs_31457281_31981568.jsonl
|
82 |
+
diffs_3145729_3670016.jsonl
|
83 |
+
diffs_31981569_32505856.jsonl
|
84 |
+
diffs_32505857_33030144.jsonl
|
85 |
+
diffs_33030145_33554432.jsonl
|
86 |
+
diffs_33554433_34078720.jsonl
|
87 |
+
diffs_34078721_34603008.jsonl
|
88 |
+
diffs_34603009_35127296.jsonl
|
89 |
+
diffs_35127297_35651584.jsonl
|
90 |
+
diffs_35651585_36175872.jsonl
|
91 |
+
diffs_36175873_36700160.jsonl
|
92 |
+
diffs_36700161_37224448.jsonl
|
93 |
+
diffs_3670017_4194304.jsonl
|
94 |
+
diffs_37224449_37748736.jsonl
|
95 |
+
diffs_37748737_38273024.jsonl
|
96 |
+
diffs_38273025_38797312.jsonl
|
97 |
+
diffs_38797313_39321600.jsonl
|
98 |
+
diffs_39321601_39845888.jsonl
|
99 |
+
diffs_39845889_40370176.jsonl
|
100 |
+
diffs_40370177_40894464.jsonl
|
101 |
+
diffs_40894465_41418752.jsonl
|
102 |
+
diffs_41418753_41943040.jsonl
|
103 |
+
diffs_41943041_42467328.jsonl
|
104 |
+
diffs_4194305_4718592.jsonl
|
105 |
+
diffs_42467329_42991616.jsonl
|
106 |
+
diffs_42991617_43515904.jsonl
|
107 |
+
diffs_43515905_44040192.jsonl
|
108 |
+
diffs_44040193_44564480.jsonl
|
109 |
+
diffs_44564481_45088768.jsonl
|
110 |
+
diffs_45088769_45613056.jsonl
|
111 |
+
diffs_45613057_46137344.jsonl
|
112 |
+
diffs_46137345_46661632.jsonl
|
113 |
+
diffs_46661633_47185920.jsonl
|
114 |
+
diffs_47185921_47710208.jsonl
|
115 |
+
diffs_4718593_5242880.jsonl
|
116 |
+
diffs_47710209_48234496.jsonl
|
117 |
+
diffs_48234497_48758784.jsonl
|
118 |
+
diffs_48758785_49283072.jsonl
|
119 |
+
diffs_49283073_49807360.jsonl
|
120 |
+
diffs_49807361_50331648.jsonl
|
121 |
+
diffs_50331649_50855936.jsonl
|
122 |
+
diffs_50855937_51380224.jsonl
|
123 |
+
diffs_51380225_51904512.jsonl
|
124 |
+
diffs_51904513_52428800.jsonl
|
125 |
+
diffs_52428801_52953088.jsonl
|
126 |
+
diffs_5242881_5767168.jsonl
|
127 |
+
diffs_524289_1048576.jsonl
|
128 |
+
diffs_52953089_53477376.jsonl
|
129 |
+
diffs_53477377_54001664.jsonl
|
130 |
+
diffs_54001665_54525952.jsonl
|
131 |
+
diffs_54525953_55050240.jsonl
|
132 |
+
diffs_55050241_55574528.jsonl
|
133 |
+
diffs_55574529_56098816.jsonl
|
134 |
+
diffs_56098817_56623104.jsonl
|
135 |
+
diffs_56623105_57147392.jsonl
|
136 |
+
diffs_57147393_57671680.jsonl
|
137 |
+
diffs_57671681_58195968.jsonl
|
138 |
+
diffs_5767169_6291456.jsonl
|
139 |
+
diffs_58195969_58720256.jsonl
|
140 |
+
diffs_49807361_50331648.jsonl
|
141 |
+
diffs_50331649_50855936.jsonl
|
142 |
+
diffs_50855937_51380224.jsonl
|
143 |
+
diffs_51380225_51904512.jsonl
|
144 |
+
diffs_51904513_52428800.jsonl
|
145 |
+
diffs_52428801_52953088.jsonl
|
146 |
+
diffs_5242881_5767168.jsonl
|
147 |
+
diffs_524289_1048576.jsonl
|
148 |
+
diffs_52953089_53477376.jsonl
|
149 |
+
diffs_53477377_54001664.jsonl
|
150 |
+
diffs_54001665_54525952.jsonl
|
151 |
+
diffs_54525953_55050240.jsonl
|
152 |
+
diffs_55050241_55574528.jsonl
|
153 |
+
diffs_55574529_56098816.jsonl
|
154 |
+
diffs_56098817_56623104.jsonl
|
155 |
+
diffs_56623105_57147392.jsonl
|
156 |
+
diffs_57147393_57671680.jsonl
|
157 |
+
diffs_57671681_58195968.jsonl
|
158 |
+
diffs_5767169_6291456.jsonl
|
159 |
+
diffs_58195969_58720256.jsonl
|
160 |
+
diffs_58720257_59244544.jsonl
|
161 |
+
diffs_59244545_59768832.jsonl
|
162 |
+
diffs_59768833_60293120.jsonl
|
163 |
+
diffs_60293121_60817408.jsonl
|
164 |
+
diffs_60817409_61341696.jsonl
|
165 |
+
diffs_61341697_61865984.jsonl
|
166 |
+
diffs_61865985_62390272.jsonl
|
167 |
+
diffs_62390273_62914560.jsonl
|
168 |
+
diffs_62914561_63438848.jsonl
|
169 |
+
diffs_6291457_6815744.jsonl
|
170 |
+
diffs_63438849_63963136.jsonl
|
171 |
+
diffs_63963137_64487424.jsonl
|
172 |
+
diffs_64487425_65011712.jsonl
|
173 |
+
diffs_65011713_65536000.jsonl
|
174 |
+
diffs_65536001_66060288.jsonl
|
175 |
+
diffs_66060289_66584576.jsonl
|
176 |
+
diffs_66584577_67108864.jsonl
|
177 |
+
diffs_6815745_7340032.jsonl
|
178 |
+
diffs_7340033_7864320.jsonl
|
179 |
+
diffs_7864321_8388608.jsonl
|
180 |
+
diffs_8388609_8912896.jsonl
|
181 |
+
diffs_8912897_9437184.jsonl
|
182 |
+
diffs_9437185_9961472.jsonl'''.splitlines()
|
183 |
+
|
184 |
+
|
185 |
+
if False:#__name__ == "__main__":
|
186 |
+
data = {}
|
187 |
+
# licenses:
|
188 |
+
# {"repos":"samoht/ocaml-conduit,samoht/ocaml-conduit,avsm/ocaml-conduit,mirage/ocaml-conduit,djs55/ocaml-conduit,rgrinberg/ocaml-conduit,rgrinberg/ocaml-conduit,djs55/ocaml-conduit","license":"isc"}
|
189 |
+
with open('licenses_merged.jsonl', 'r') as f:
|
190 |
+
for line in f:
|
191 |
+
line = line.strip()
|
192 |
+
if not line:
|
193 |
+
continue
|
194 |
+
d = json.loads(line)
|
195 |
+
for repo in d['repos'].split(","):
|
196 |
+
data[repo] = d['license']
|
197 |
+
|
198 |
+
NUM_PROC = 8
|
199 |
+
|
200 |
+
# path = "diffs_9961473_10485760.jsonl"
|
201 |
+
for path in paths:
|
202 |
+
ds = datasets.load_dataset("json", data_files=path)
|
203 |
+
|
204 |
+
print(ds)
|
205 |
+
print(random.sample(data.items(), 10))
|
206 |
+
|
207 |
+
def map_col(example):
|
208 |
+
for repo in example["repos"].split(","):
|
209 |
+
if repo in data:
|
210 |
+
example["license"] = data[repo]
|
211 |
+
return example
|
212 |
+
example["license"] = 'unknown'
|
213 |
+
return example
|
214 |
+
|
215 |
+
def opt_out(example):
|
216 |
+
repos = example["repos"].split(",")
|
217 |
+
if (len(repos) == 1) and (repos[0].split("/")[0] in opt_out_github_login_the_stack_12):
|
218 |
+
return False
|
219 |
+
return True
|
220 |
+
|
221 |
+
ds['train'].map(map_col).filter(opt_out).to_json(path.replace(".jsonl", "_new.jsonl"), num_proc=NUM_PROC)
|
222 |
+
|
223 |
+
"""
|
224 |
+
AND ( (lang_table.language_name LIKE 'Python')
|
225 |
+
OR (lang_table.language_name LIKE 'Java')
|
226 |
+
OR (lang_table.language_name LIKE 'JavaScript')
|
227 |
+
OR (lang_table.language_name LIKE 'HTML')
|
228 |
+
OR (lang_table.language_name LIKE 'Common Lisp')
|
229 |
+
OR (lang_table.language_name LIKE 'Shell')
|
230 |
+
OR (lang_table.language_name LIKE 'R')
|
231 |
+
OR (lang_table.language_name LIKE 'Perl%')
|
232 |
+
OR (lang_table.language_name LIKE 'SQL')
|
233 |
+
OR (lang_table.language_name LIKE 'C')
|
234 |
+
OR (lang_table.language_name LIKE 'C#')
|
235 |
+
OR (lang_table.language_name LIKE 'C++')
|
236 |
+
OR (lang_table.language_name LIKE 'TypeScript')
|
237 |
+
OR (lang_table.language_name LIKE 'Go')
|
238 |
+
OR (lang_table.language_name LIKE 'Rust')
|
239 |
+
OR (lang_table.language_name LIKE 'Swift')
|
240 |
+
OR (lang_table.language_name LIKE 'PHP')
|
241 |
+
OR (lang_table.language_name LIKE 'Dart')
|
242 |
+
OR (lang_table.language_name LIKE 'Kotlin')
|
243 |
+
OR (lang_table.language_name LIKE 'Matlab')
|
244 |
+
OR (lang_table.language_name LIKE 'MATLAB')
|
245 |
+
OR (lang_table.language_name LIKE 'Ruby') )
|
246 |
+
"""
|
247 |
+
|
248 |
+
if __name__ == "__main__":
|
249 |
+
|
250 |
+
with open("programming_languages.json", "r") as f:
|
251 |
+
prog_langs = json.load(f)
|
252 |
+
|
253 |
+
ext_to_lang = {}
|
254 |
+
for lang, exts in prog_langs.items():
|
255 |
+
for ext in exts:
|
256 |
+
ext_to_lang[ext] = lang
|
257 |
+
|
258 |
+
|
259 |
+
LANGS = [
|
260 |
+
'Python',
|
261 |
+
'Java',
|
262 |
+
'JavaScript',
|
263 |
+
'HTML',
|
264 |
+
'Common Lisp',
|
265 |
+
'Shell',
|
266 |
+
'R',
|
267 |
+
'Perl',
|
268 |
+
'Perl6', # Differentiate Perl6 from Perl
|
269 |
+
'SQL',
|
270 |
+
'C',
|
271 |
+
'C#',
|
272 |
+
'C++',
|
273 |
+
'TypeScript',
|
274 |
+
'Go',
|
275 |
+
'Rust',
|
276 |
+
'Swift',
|
277 |
+
'PHP',
|
278 |
+
'Dart',
|
279 |
+
'Kotlin',
|
280 |
+
'Matlab',
|
281 |
+
'MATLAB',
|
282 |
+
'Ruby'
|
283 |
+
]
|
284 |
+
|
285 |
+
for lang in LANGS:
|
286 |
+
if lang not in prog_langs:
|
287 |
+
print("Missing", lang)
|
288 |
+
|
289 |
+
def add_lang(example):
|
290 |
+
example["language"] = ext_to_lang.get(example["new_file"].split(".")[-1], "unknown")
|
291 |
+
return example
|
292 |
+
|
293 |
+
for path in paths:
|
294 |
+
ds = datasets.load_dataset("json", data_files=path)
|
295 |
+
ds = ds['train'].map(add_lang)
|
296 |
+
vals = ds.unique('language')
|
297 |
+
for val in vals:
|
298 |
+
ds.filter(lambda x: x['language'] == val).to_json(path.replace(".jsonl", f"_{val}.jsonl"), num_proc=NUM_PROC)
|
299 |
+
|
300 |
+
|
301 |
+
|
302 |
+
|