andstor commited on
Commit
874d81a
1 Parent(s): f90a46e

Upload process.ipynb

Browse files
Files changed (1) hide show
  1. process.ipynb +228 -0
process.ipynb ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 23,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stderr",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "100%|██████████| 7440/7440 [02:42<00:00, 45.75it/s] \n"
13
+ ]
14
+ }
15
+ ],
16
+ "source": [
17
+ "import json\n",
18
+ "import os\n",
19
+ "from tqdm import tqdm\n",
20
+ "from pathlib import Path\n",
21
+ "\n",
22
+ "\n",
23
+ "split = \"train\" # \"test\", \"eval\"\n",
24
+ "\n",
25
+ "def load_json_files(filepath):\n",
26
+ " with open(filepath, 'r') as f:\n",
27
+ " data = json.load(f)\n",
28
+ " return data\n",
29
+ "\n",
30
+ "\n",
31
+ "folders = [os.path.join('dataset', split, f) for f in os.listdir('dataset/'+ split )]\n",
32
+ "data = []\n",
33
+ "for folderpath in tqdm(folders):\n",
34
+ " if not os.path.isdir(folderpath):\n",
35
+ " continue\n",
36
+ " files = [os.path.join(folderpath, f) for f in os.listdir(folderpath)]\n",
37
+ " for filepath in files:\n",
38
+ " if filepath.endswith('.json'):\n",
39
+ " \n",
40
+ " data.append({\"id\": str(Path(filepath).stem), **load_json_files(filepath)})\n",
41
+ "\n",
42
+ "\n"
43
+ ]
44
+ },
45
+ {
46
+ "cell_type": "code",
47
+ "execution_count": 24,
48
+ "metadata": {},
49
+ "outputs": [
50
+ {
51
+ "name": "stderr",
52
+ "output_type": "stream",
53
+ "text": [
54
+ "100%|██████████| 624022/624022 [00:11<00:00, 53122.61it/s]\n"
55
+ ]
56
+ }
57
+ ],
58
+ "source": [
59
+ "\n",
60
+ "results = []\n",
61
+ "for item in tqdm(data):\n",
62
+ " # Focal class\n",
63
+ " focal_class = \"class\" + \" \" + item[\"focal_class\"][\"identifier\"]\n",
64
+ "\n",
65
+ " if item[\"focal_class\"][\"superclass\"]:\n",
66
+ " focal_class += \" \" + item[\"focal_class\"][\"superclass\"]\n",
67
+ "\n",
68
+ " if item[\"focal_class\"][\"interfaces\"]:\n",
69
+ " focal_class += \" \" + item[\"focal_class\"][\"interfaces\"]\n",
70
+ "\n",
71
+ " focal_class += \" {\"\n",
72
+ "\n",
73
+ " indent = item[\"focal_method\"][\"body\"].split(\"\\n\")[-1][:-1]\n",
74
+ "\n",
75
+ " # Focal method\n",
76
+ " focal_method = indent + item[\"focal_method\"][\"body\"]\n",
77
+ "\n",
78
+ " # Constructors\n",
79
+ " constructors = []\n",
80
+ " for method in item[\"focal_class\"][\"methods\"]:\n",
81
+ " if method[\"constructor\"]:\n",
82
+ " constructor = indent + method[\"full_signature\"] + \";\"\n",
83
+ " constructors.append(constructor)\n",
84
+ "\n",
85
+ " # Methods\n",
86
+ " methods = []\n",
87
+ " for method in item[\"focal_class\"][\"methods\"]:\n",
88
+ " if item[\"focal_method\"][\"full_signature\"] == method[\"full_signature\"]:\n",
89
+ " continue\n",
90
+ " #if method[\"testcase\"]:\n",
91
+ " # continue\n",
92
+ "\n",
93
+ " if not method[\"constructor\"]:\n",
94
+ " method_code = indent + method[\"full_signature\"] + \";\"\n",
95
+ " methods.append(method_code)\n",
96
+ "\n",
97
+ " # Fields\n",
98
+ " fields = []\n",
99
+ " for field in item[\"focal_class\"][\"fields\"]:\n",
100
+ " field_code = indent\n",
101
+ " field_code += field[\"modifier\"] + \" \" + field[\"type\"] + \" \" + field[\"var_name\"] + \";\"\n",
102
+ " fields.append(field_code)\n",
103
+ "\n",
104
+ "\n",
105
+ " # TEST\n",
106
+ " # Test class\n",
107
+ " test_class = \"class\" + \" \" + item[\"test_class\"][\"identifier\"]\n",
108
+ "\n",
109
+ " if item[\"test_class\"][\"superclass\"]:\n",
110
+ " test_class += \" \" + item[\"focal_class\"][\"superclass\"]\n",
111
+ "\n",
112
+ " if item[\"test_class\"][\"interfaces\"]:\n",
113
+ " test_class += \" \" + item[\"focal_class\"][\"interfaces\"]\n",
114
+ "\n",
115
+ " test_class += \" {\"\n",
116
+ "\n",
117
+ " indent = item[\"test_case\"][\"body\"].split(\"\\n\")[-1][:-1]\n",
118
+ " # Test case\n",
119
+ " fields = []\n",
120
+ " for field in item[\"test_class\"][\"fields\"]:\n",
121
+ " field_code = indent\n",
122
+ " field_code += field[\"modifier\"] + \" \" + field[\"type\"] + \" \" + field[\"var_name\"] + \";\"\n",
123
+ " fields.append(field_code)\n",
124
+ " test_case = indent + item[\"test_case\"][\"body\"]\n",
125
+ "\n",
126
+ " d = {\n",
127
+ " 'id': item['id'],\n",
128
+ " 't': test_case,\n",
129
+ " 't_tc': \"\\n\\n\".join(filter(None, [test_class, \"\\n\".join(fields), test_case, \"}\"])),\n",
130
+ " 'fm': focal_method,\n",
131
+ " 'fm_fc': \"\\n\\n\".join(filter(None, [focal_class, focal_method, \"}\"])),\n",
132
+ " 'fm_fc_c': \"\\n\\n\".join(filter(None, [focal_class, focal_method, \"\\n\".join(constructors), \"}\"])),\n",
133
+ " 'fm_fc_c_m': \"\\n\\n\".join(filter(None, [focal_class, focal_method, \"\\n\".join(constructors), \"\\n\".join(methods), \"}\"])),\n",
134
+ " 'fm_fc_c_m_f': \"\\n\\n\".join(filter(None, [focal_class, focal_method, \"\\n\".join(constructors), \"\\n\".join(methods), \"\\n\".join(fields), \"}\"])),\n",
135
+ " }\n",
136
+ " results.append(d)\n",
137
+ "\n"
138
+ ]
139
+ },
140
+ {
141
+ "cell_type": "code",
142
+ "execution_count": 25,
143
+ "metadata": {},
144
+ "outputs": [],
145
+ "source": [
146
+ "# sort by id\n",
147
+ "results_sorted = sorted(results, key=lambda k: int(k['id']))"
148
+ ]
149
+ },
150
+ {
151
+ "cell_type": "code",
152
+ "execution_count": 27,
153
+ "metadata": {},
154
+ "outputs": [],
155
+ "source": [
156
+ "from datasets import Dataset\n",
157
+ "train_dataset = Dataset.from_list(results_sorted)"
158
+ ]
159
+ },
160
+ {
161
+ "cell_type": "code",
162
+ "execution_count": 28,
163
+ "metadata": {},
164
+ "outputs": [],
165
+ "source": [
166
+ "from datasets import DatasetDict\n",
167
+ "\n",
168
+ "dataset_dict = DatasetDict({'train': train_dataset, 'test': test_dataset, 'validation': eval_dataset})"
169
+ ]
170
+ },
171
+ {
172
+ "cell_type": "code",
173
+ "execution_count": 30,
174
+ "metadata": {},
175
+ "outputs": [
176
+ {
177
+ "name": "stderr",
178
+ "output_type": "stream",
179
+ "text": [
180
+ "Creating parquet from Arrow format: 100%|██████████| 57/57 [00:00<00:00, 134.38ba/s]\n",
181
+ "Creating parquet from Arrow format: 100%|██████████| 57/57 [00:00<00:00, 143.75ba/s]\n",
182
+ "Creating parquet from Arrow format: 100%|██████████| 57/57 [00:00<00:00, 140.60ba/s]\n",
183
+ "Creating parquet from Arrow format: 100%|██████████| 57/57 [00:00<00:00, 150.07ba/s]\n",
184
+ "Creating parquet from Arrow format: 100%|██████████| 57/57 [00:00<00:00, 164.71ba/s]\n",
185
+ "Creating parquet from Arrow format: 100%|██████████| 57/57 [00:00<00:00, 157.03ba/s]\n",
186
+ "Creating parquet from Arrow format: 100%|██████████| 57/57 [00:00<00:00, 146.53ba/s]\n",
187
+ "Creating parquet from Arrow format: 100%|██████████| 57/57 [00:00<00:00, 154.88ba/s]\n",
188
+ "Creating parquet from Arrow format: 100%|██████████| 57/57 [00:00<00:00, 151.50ba/s]\n",
189
+ "Creating parquet from Arrow format: 100%|██████████| 57/57 [00:00<00:00, 144.52ba/s]\n",
190
+ "Creating parquet from Arrow format: 100%|██████████| 57/57 [00:00<00:00, 145.44ba/s]\n",
191
+ "Uploading the dataset shards: 100%|██████████| 11/11 [01:26<00:00, 7.90s/it]\n",
192
+ "Creating parquet from Arrow format: 100%|██████████| 40/40 [00:00<00:00, 155.49ba/s]\n",
193
+ "Creating parquet from Arrow format: 100%|██████████| 40/40 [00:00<00:00, 138.47ba/s]\n",
194
+ "Uploading the dataset shards: 100%|██████████| 2/2 [00:11<00:00, 5.58s/it]\n",
195
+ "Creating parquet from Arrow format: 100%|██████████| 40/40 [00:00<00:00, 145.22ba/s]\n",
196
+ "Creating parquet from Arrow format: 100%|██████████| 40/40 [00:00<00:00, 139.08ba/s]\n",
197
+ "Uploading the dataset shards: 100%|██████████| 2/2 [00:12<00:00, 6.28s/it]\n",
198
+ "README.md: 100%|██████████| 21.0/21.0 [00:00<00:00, 8.60kB/s]\n"
199
+ ]
200
+ }
201
+ ],
202
+ "source": [
203
+ "dataset_dict.push_to_hub('andstor/methods2test')"
204
+ ]
205
+ }
206
+ ],
207
+ "metadata": {
208
+ "kernelspec": {
209
+ "display_name": ".venv",
210
+ "language": "python",
211
+ "name": "python3"
212
+ },
213
+ "language_info": {
214
+ "codemirror_mode": {
215
+ "name": "ipython",
216
+ "version": 3
217
+ },
218
+ "file_extension": ".py",
219
+ "mimetype": "text/x-python",
220
+ "name": "python",
221
+ "nbconvert_exporter": "python",
222
+ "pygments_lexer": "ipython3",
223
+ "version": "3.9.13"
224
+ }
225
+ },
226
+ "nbformat": 4,
227
+ "nbformat_minor": 2
228
+ }