File size: 1,469 Bytes
dc1f8e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
718c4ae
dc1f8e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
   import datasets

   _LANGUAGES = ["python", "java", "kotlin"]

   class BugLocalizationConfig(datasets.BuilderConfig):
       """BuilderConfig for BugLocalizationConfig"""
       def __init__(self, **kwargs):
           """BuilderConfig for BugLocalization Dataset.
           Args:
               **kwargs: keyword arguments forwarded to super.
           """
           super(BugLocalizationConfig, self).__init__(**kwargs)


   class BugLocalizationDatset(datasets.GeneratorBasedBuilder):
       """BugLocalizationDatset Dataset"""
       BUILDER_CONFIGS = [
           BugLocalizationConfig(name=lang, description=f"Bug localization dataset for {lang}.")
           for lang in _LANGUAGES
       ]

       def _info(self):
           pass

       def _split_generators(self, dl_manager):
           urls = {
               "python": "bug_localization_test_py.jsonl",
               "java": "bug_localization_test_java.jsonl",
               "kotlin": "bug_localization_test_kt.jsonl",
           }
           downloaded_files = dl_manager.download_and_extract(urls)
           return [datasets.SplitGenerator(
               name=datasets.Split.TRAIN,
               gen_kwargs={"filepath": downloaded_files[self.config.name]}
           )]

       def _generate_examples(self, filepath):
           with open(filepath, encoding="utf-8") as f:
               for id_, line in enumerate(f):
                   data = json.loads(line)
                   yield data