File size: 4,302 Bytes
1da1e81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""CoNaLa dataset."""

import json
import datasets


_CITATION = """\
@inproceedings{yin2018learning,
  title={Learning to mine aligned code and natural language pairs from stack overflow},
  author={Yin, Pengcheng and Deng, Bowen and Chen, Edgar and Vasilescu, Bogdan and Neubig, Graham},
  booktitle={2018 IEEE/ACM 15th international conference on mining software repositories (MSR)},
  pages={476--486},
  year={2018},
  organization={IEEE}
}
"""

_DESCRIPTION = """\
CoNaLa is a dataset of code and natural language pairs crawled from Stack Overflow, for more details please refer to this paper: https://arxiv.org/pdf/1805.08949.pdf or the dataset page https://conala-corpus.github.io/.
"""

_HOMEPAGE = "https://conala-corpus.github.io/"
_URLs = {
    "mined": "data/conala-mined.json",
    "curated": {"train": "data/conala-paired-train.json", "test": "data/conala-paired-test.json" },
}

class Conala(datasets.GeneratorBasedBuilder):
    """CoNaLa Code dataset."""

    VERSION = datasets.Version("1.1.0")


    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name="curated",
            version=datasets.Version("1.1.0"),
            description=_DESCRIPTION,
        ),
        datasets.BuilderConfig(name="mined", version=datasets.Version("1.1.0"), description=_DESCRIPTION),
    ]

    DEFAULT_CONFIG_NAME = "curated"
    
    
    def _info(self):
        if self.config.name == "curated":
            features=datasets.Features({"question_id": datasets.Value("int64"),
                                            "intent": datasets.Value("string"),
                                            "rewritten_intent": datasets.Value("string"),
                                            "snippet": datasets.Value("string"), 
                                            })
        else:
            features=datasets.Features({"question_id": datasets.Value("int64"),
                                            "parent_answer_post_id": datasets.Value("int64"),
                                            "prob": datasets.Value("float64"),
                                            "snippet": datasets.Value("string"),
                                            "intent": datasets.Value("string"), 
                                            "id": datasets.Value("string"),
                                            })
        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)
        if self.config.name == "curated":
            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={"filepath": data_dir["train"], "split": "train"},
                ),
                datasets.SplitGenerator(
                    name=datasets.Split.TEST,
                    gen_kwargs={"filepath": data_dir["test"], "split": "test"},
                ),
                ]
        else:
            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