File size: 1,394 Bytes
d74f6f1
 
 
dc1f8e7
d74f6f1
 
dc1f8e7
d74f6f1
 
 
 
 
 
 
 
dc1f8e7
 
d74f6f1
 
 
 
 
 
dc1f8e7
718c4ae
dc1f8e7
 
 
c7060ab
 
 
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
42
43
import json
import os
import datasets

# Define the different configurations (languages)
_LANGUAGES = ["java", "kt", "py"]

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


class BugLocalization(datasets.GeneratorBasedBuilder):
    """BugLocalization dataset"""
    BUILDER_CONFIGS = [
        BugLocalizationConfig(name=lang, description=f"My dataset for {lang}.")
        for lang in _LANGUAGES
    ]
       def _info(self):
           pass

       def _split_generators(self, dl_manager):
           urls = {
               "python": "python.jsonl",
               "java": "java.jsonl",
               "kotlin": "kotlin.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