File size: 3,005 Bytes
b8c07f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""Odex dataset."""

import json
import datasets


_CITATION = """\

"""

_DESCRIPTION = """\

"""

_HOMEPAGE = " "
LIST_LANG = ['ada', 'agda', 'alloy', 'antlr', 'applescript', 'assembly', 'augeas', 'awk', 'batchfile', 'bison',
 'bluespec', 'c', 'c++', 'c-sharp', 'clojure', 'cmake', 'coffeescript', 'common-lisp', 'css', 'cuda', 'dart', 'dockerfile', 'elixir',
'elm', 'emacs-lisp','erlang', 'f-sharp', 'fortran', 'glsl', 'go', 'groovy', 'haskell','html', 'idris', 'isabelle', 'java', 
'java-server-pages', 'javascript', 'julia', 'kotlin', 'lean', 'literate-agda', 'literate-coffeescript', 'literate-haskell',
 'lua', 'makefile', 'maple', 'markdown', 'mathematica', 'matlab', 'ocaml', 'pascal', 'perl', 'php', 'powershell', 'prolog',
  'protocol-buffer', 'python', 'r', 'racket', 'restructuredtext', 'rmarkdown', 'ruby', 'rust', 'sas', 'scala', 'scheme', 
  'shell', 'smalltalk', 'solidity', 'sparql', 'sql', 'stan', 'standard-ml', 'stata', 'systemverilog', 'tcl', 'tcsh', 'tex', 
  'thrift', 'typescript', 'verilog', 'vhdl', 'visual-basic', 'xslt', 'yacc', 'zig']

_URLs = {lang: f"data/{lang}/data.json" for lang in LIST_LANG}


class Stack(datasets.GeneratorBasedBuilder):
    """Stack Code dataset."""

    VERSION = datasets.Version("1.0.0")


    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name=lang,
            version=datasets.Version("1.0.0"),
            description=_DESCRIPTION,
        ) for lang in _URLs.keys()
    ]

    DEFAULT_CONFIG_NAME = "python"
    
    
    def _info(self):
        features = datasets.Features({"content": datasets.Value("string"),
                                        "lang": datasets.Value("string"),
                                        "size": datasets.Value("int64"),
                                        "ext": datasets.Value("string"),
                                        "max_stars_count": datasets.Value("int64"),
                                        "avg_line_length": datasets.Value("float64"),
                                        "max_line_length": datasets.Value("int64"),
                                        "alphanum_fraction": datasets.Value("float64"),
                                        })
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            supervised_keys=None,
            citation=_CITATION,
            homepage=_HOMEPAGE)

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        config_urls = _URLs[self.config.name]
        data_dir = dl_manager.download_and_extract(config_urls)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={"filepath": data_dir, "split": "train"},
            ),
            ]


    def _generate_examples(self, filepath, split):
        key = 0
        for line in open(filepath, encoding="utf-8"):
            line = json.loads(line)
            yield key, line   
            key += 1