Samip Dahal commited on
Commit
a236881
·
1 Parent(s): 4969ef7
Files changed (1) hide show
  1. func.py +141 -0
func.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ import csv
19
+ import json
20
+ import os
21
+
22
+ import datasets
23
+ import pickle
24
+
25
+
26
+ # TODO: Add BibTeX citation
27
+ # Find for instance the citation on arxiv or on the dataset repo/website
28
+ _CITATION = """"""
29
+
30
+ # TODO: Add description of the dataset here
31
+ # You can copy an official description
32
+ _DESCRIPTION = """\
33
+ This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
34
+ """
35
+
36
+ # TODO: Add a link to an official homepage for the dataset here
37
+ _HOMEPAGE = ""
38
+
39
+ # TODO: Add the licence for the dataset here if you can find it
40
+ _LICENSE = ""
41
+
42
+ # TODO: Add link to the official dataset URLs here
43
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
44
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
45
+ languages=['python','javascript','java','go']
46
+ _URLs = {lang:f'https://funcdef.s3.amazonaws.com/{lang}.tar.gz' for lang in languages}
47
+ _URLs['all']=_URLs.copy()
48
+
49
+
50
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
51
+ class FundDefDataset(datasets.GeneratorBasedBuilder):
52
+ VERSION = datasets.Version("1.0.0")
53
+ BUILDER_CONFIGS = [
54
+ datasets.BuilderConfig(name="all", version=VERSION, description="All available data"),
55
+ datasets.BuilderConfig(name="python", version=VERSION, description="Python data"),
56
+ datasets.BuilderConfig(name="javascript", version=VERSION, description="Javascript data"),
57
+ datasets.BuilderConfig(name="java", version=VERSION, description="Java data"),
58
+ datasets.BuilderConfig(name="go", version=VERSION, description="Go data"),
59
+ ]
60
+
61
+ DEFAULT_CONFIG_NAME = "all"
62
+
63
+ def _info(self):
64
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
65
+
66
+ features = datasets.Features(
67
+ {
68
+ "repository_name": datasets.Value("string"),
69
+ "function_path": datasets.Value("string"),
70
+ "function_identifier": datasets.Value("string"),
71
+ "language": datasets.Value("string"),
72
+ "function": datasets.Sequence(datasets.Value("string")),
73
+ "docstring": datasets.Value("string"),
74
+ "function_url": datasets.Value("string"),
75
+ "license":datasets.Value("string"),
76
+ }
77
+ )
78
+ return datasets.DatasetInfo(
79
+ description=_DESCRIPTION,
80
+ features=features, # Here we define them above because they are different between the two configurations
81
+ supervised_keys=None,
82
+ homepage=_HOMEPAGE,
83
+ license=_LICENSE,
84
+ citation=_CITATION,
85
+ )
86
+
87
+ def _split_generators(self, dl_manager):
88
+ """Returns SplitGenerators."""
89
+ my_urls = _URLs[self.config.name]
90
+ if isinstance(my_urls, str):
91
+ my_urls = [my_urls]
92
+ data_dir = [os.path.join(lang_dir,lang) for lang,lang_dir in dl_manager.download_and_extract(my_urls).items()]
93
+ splitpaths={split:os.path.join(lang_dir,f'{split}'.bin) for lang_dir in data_dir for split in ['train','valid','test']}
94
+
95
+ return [
96
+ datasets.SplitGenerator(
97
+ name=datasets.Split.TRAIN,
98
+ # These kwargs will be passed to _generate_examples
99
+ gen_kwargs={
100
+ "filepath": splitpaths['train'],
101
+ "split": "train",
102
+ },
103
+ ),
104
+ datasets.SplitGenerator(
105
+ name=datasets.Split.TEST,
106
+ # These kwargs will be passed to _generate_examples
107
+ gen_kwargs={
108
+ "filepath": splitpaths['test'],
109
+ "split": "test"
110
+ },
111
+ ),
112
+ datasets.SplitGenerator(
113
+ name=datasets.Split.VALIDATION,
114
+ # These kwargs will be passed to _generate_examples
115
+ gen_kwargs={
116
+ "filepath": splitpaths['valid'],
117
+ "split": "valid",
118
+ },
119
+ ),
120
+ ]
121
+
122
+ def _generate_examples(
123
+ self, filepaths,split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
124
+ ):
125
+ """ Yields examples as (key, example) tuples. """
126
+ count=-1
127
+ for i,filepath in enumerate(filepaths):
128
+ loaded_f=pickle.load(open(filepath,'rb'))
129
+ for j, func in enumerate(loaded_f):
130
+ count+=1
131
+ yield count,{
132
+ "repository_name": func['nwo'],
133
+ "function_path":func['path'],
134
+ "function_identifier": func['identifier'],
135
+ "language": func['language'],
136
+ "function": func['function'],
137
+ "docstring": func['docstring'],
138
+ "function_url": func['url'],
139
+ "license":func['license'],
140
+ }
141
+