Create dataset.py
Browse files- dataset/dataset.py +46 -0
dataset/dataset.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
|
3 |
+
_LANGUAGES = ["python", "java", "kotlin"]
|
4 |
+
|
5 |
+
class BugLocalizationConfig(datasets.BuilderConfig):
|
6 |
+
"""BuilderConfig for BugLocalizationConfig"""
|
7 |
+
def __init__(self, **kwargs):
|
8 |
+
"""BuilderConfig for BugLocalization Dataset.
|
9 |
+
Args:
|
10 |
+
**kwargs: keyword arguments forwarded to super.
|
11 |
+
"""
|
12 |
+
super(BugLocalizationConfig, self).__init__(**kwargs)
|
13 |
+
|
14 |
+
|
15 |
+
class BugLocalizationDatset(datasets.GeneratorBasedBuilder):
|
16 |
+
"""BugLocalizationDatset Dataset"""
|
17 |
+
BUILDER_CONFIGS = [
|
18 |
+
BugLocalizationConfig(name=lang, description=f"Bug localization dataset for {lang}.")
|
19 |
+
for lang in _LANGUAGES
|
20 |
+
]
|
21 |
+
|
22 |
+
def _info(self):
|
23 |
+
return datasets.DatasetInfo(
|
24 |
+
features=datasets.Features({
|
25 |
+
"code": datasets.Value("string"),
|
26 |
+
"label": datasets.Value("string"),
|
27 |
+
})
|
28 |
+
)
|
29 |
+
|
30 |
+
def _split_generators(self, dl_manager):
|
31 |
+
urls = {
|
32 |
+
"python": "bug_localization_test_py.jsonl",
|
33 |
+
"java": "bug_localization_test_java.jsonl",
|
34 |
+
"kotlin": "bug_localization_test_kt.jsonl",
|
35 |
+
}
|
36 |
+
downloaded_files = dl_manager.download_and_extract(urls)
|
37 |
+
return [datasets.SplitGenerator(
|
38 |
+
name=datasets.Split.TRAIN,
|
39 |
+
gen_kwargs={"filepath": downloaded_files[self.config.name]}
|
40 |
+
)]
|
41 |
+
|
42 |
+
def _generate_examples(self, filepath):
|
43 |
+
with open(filepath, encoding="utf-8") as f:
|
44 |
+
for id_, line in enumerate(f):
|
45 |
+
data = json.loads(line)
|
46 |
+
yield data
|