|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""TODO: Add a description here.""" |
|
|
|
|
|
import csv |
|
import json |
|
import os |
|
|
|
import datasets |
|
import pickle |
|
|
|
|
|
|
|
|
|
_CITATION = """""" |
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
This new dataset is designed to solve this great NLP task and is crafted with a lot of care. |
|
""" |
|
|
|
|
|
_HOMEPAGE = "" |
|
|
|
|
|
_LICENSE = "" |
|
|
|
|
|
|
|
|
|
languages=['python','javascript','java','go'] |
|
_URLs = {lang:f'https://funcdef.s3.amazonaws.com/{lang}.tar.gz' for lang in languages} |
|
_URLs['all']=_URLs.copy() |
|
|
|
|
|
|
|
class FundDefDataset(datasets.GeneratorBasedBuilder): |
|
VERSION = datasets.Version("1.0.0") |
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="all", version=VERSION, description="All available data"), |
|
datasets.BuilderConfig(name="python", version=VERSION, description="Python data"), |
|
datasets.BuilderConfig(name="javascript", version=VERSION, description="Javascript data"), |
|
datasets.BuilderConfig(name="java", version=VERSION, description="Java data"), |
|
datasets.BuilderConfig(name="go", version=VERSION, description="Go data"), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "all" |
|
|
|
def _info(self): |
|
|
|
|
|
features = datasets.Features( |
|
{ |
|
"repository_name": datasets.Value("string"), |
|
"function_path": datasets.Value("string"), |
|
"function_identifier": datasets.Value("string"), |
|
"language": datasets.Value("string"), |
|
"function": datasets.Sequence(datasets.Value("string")), |
|
"docstring": datasets.Value("string"), |
|
"function_url": datasets.Value("string"), |
|
"license":datasets.Value("string"), |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
my_urls = _URLs[self.config.name] |
|
if isinstance(my_urls, str): |
|
my_urls = {self.config.name:my_urls} |
|
data_dir = [os.path.join(lang_dir,lang) for lang,lang_dir in dl_manager.download_and_extract(my_urls).items()] |
|
splitpaths={split:os.path.join(lang_dir,f'{split}'.bin) for lang_dir in data_dir for split in ['train','valid','test']} |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": splitpaths['train'], |
|
"split": "train", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": splitpaths['test'], |
|
"split": "test" |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepath": splitpaths['valid'], |
|
"split": "valid", |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples( |
|
self, filepaths,split |
|
): |
|
""" Yields examples as (key, example) tuples. """ |
|
count=-1 |
|
for i,filepath in enumerate(filepaths): |
|
loaded_f=pickle.load(open(filepath,'rb')) |
|
for j, func in enumerate(loaded_f): |
|
count+=1 |
|
yield count,{ |
|
"repository_name": func['nwo'], |
|
"function_path":func['path'], |
|
"function_identifier": func['identifier'], |
|
"language": func['language'], |
|
"function": func['function'], |
|
"docstring": func['docstring'], |
|
"function_url": func['url'], |
|
"license":func['license'], |
|
} |
|
|