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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and Serivce Now Authors.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""This is a loading script for the Stack-Repo dataset"""
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
import csv
|
| 18 |
+
import json
|
| 19 |
+
import os
|
| 20 |
+
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
|
| 23 |
+
import datasets
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
_CITATION = """\
|
| 27 |
+
@InProceedings{__placeholder__,
|
| 28 |
+
title = {__placeholder__},
|
| 29 |
+
author={__placeholder__
|
| 30 |
+
},
|
| 31 |
+
year={2023}
|
| 32 |
+
}
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
_DESCRIPTION = """\
|
| 36 |
+
This is the Stack-Repo dataset
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
_HOMEPAGE = "https://huggingface.co/datasets/RepoFusion/Stack-Repo"
|
| 40 |
+
|
| 41 |
+
_LICENSE = "other"
|
| 42 |
+
|
| 43 |
+
_SOURCES = {
|
| 44 |
+
'test': [
|
| 45 |
+
'thekoc', 'JellyBrother', 'shuli495', 'xiao-ren-wu', 'UzcDevelopmentTeam', 'Penguinz22', 'andrewvmail',
|
| 46 |
+
'richard-trotter', 'SlimPay', 'teknux-org', 'FIXTradingCommunity', 'Juliana-Felipe', 'exasol', 'iBiber',
|
| 47 |
+
'sebaslogen', 'billmcchesney1', 'ms-showcase', 'mP1', 'yokotaso', 'ErikHage', 'shadaileng', 'regular-project',
|
| 48 |
+
'wiwilin', '1273091433', 'liangxiong3403', 'wangzlei', 'Vitaliy-Yakovchuk', 'anshul-mohil', 'MarceloCavassani',
|
| 49 |
+
'cwhelan', 'score-server', 'meyer5', 'SeSac-Cloud-Backend-4', 'Hugo-Gao', 'Olivia0202', 'IceIce1ce', '4pxzhou',
|
| 50 |
+
'bboylin', 'acolebourne', '1725762388', 'iViolinSolo', 'diaolingzc', 'trungtuan', 'havenmoney', 'speak2me',
|
| 51 |
+
'VincenzoArceri', 'exadel-inc', 'JohnReeson', 'CyiceK', 'Vooy'
|
| 52 |
+
],
|
| 53 |
+
'train': [
|
| 54 |
+
'ValeriyKnyazhev', 'leshiv', 'MfromAzeroth', 'wugjin', 'MarbleDice', 'hivijayreddy', 'sidpatel-github',
|
| 55 |
+
'hellorizon', 'CreativePenguin', 'maulikpandey', 'a630140621', 'luminiusa', 'ot-maksim', 'akash-coded',
|
| 56 |
+
'eddiewgj', 'a616707902', 'oasis9', 'DeyanZhelyazkov', 'yweng47', 'JCThePants', 'Gorlem', 'dongjihui666',
|
| 57 |
+
'mediatrue', 'david2999999', 'comme-il-faut', 'jannal', 'tfjybj', 'DimkaGorhover', 'ZhangTizo', 'CIDARLAB',
|
| 58 |
+
'DwArFeng', 'mbarkley', 'VladRomanchuk', 'vivekmalhotragithub', 'android-little-boy', 'patrik999', 'madanalogy',
|
| 59 |
+
'TheTrueColonel', 'TreeZhiyuan', 'sistcoop', 'java-ea', 'DarwinReforged', 'DougEdey', '402d', 'wangdingfeng',
|
| 60 |
+
'WeiziPlus', 'fabionery', 'famartinrh', 'rghvgrv', 'QuincySx', 'raphaelcohn', 'hYdos', 'tacticalrce',
|
| 61 |
+
'danielkrajnik', 'SeanDecker1', 'bahaahussein', 'Team1772', 'zengfanmao', 'Hopp-Stu', 'My-DIGI-ID', 'slickqa',
|
| 62 |
+
'opentok', 'Manolomon', 'denhatmong', 'baishuo', 'zli78122', 'kenichi-ando', 'pengcash', 'Princelo',
|
| 63 |
+
'RuthDirnfeld', 'HRI-EU', 'jan438', 'sd2438892', 'rsofista', 'mpsitech', 'AvaN0x', 'JDode', 'dreadwail',
|
| 64 |
+
'pcjs156', 'MrWe', 'smallxiongxiong', 'wuxinlingluan', 'FLxmw', 'TransFICC', 'fengpod', 'orient33', 'hamsterxc',
|
| 65 |
+
'diegolemospadilha', 'CheRut', 'ToreAad', 'AndrewHYC', 'Azagwen', 'Ndivhuwo', 'gou02rav32', 'CDZR0',
|
| 66 |
+
'MFunction96', 'google', 'mariodavid', 'jacksontenorio8', 'DieguinhoHR'
|
| 67 |
+
],
|
| 68 |
+
'val': [
|
| 69 |
+
'malcolmgreaves', 'atlasapi', 'HeXavi8', 'fank243', 'StealWonders', 'asyakasimova', 'truthiswill',
|
| 70 |
+
'swiatecki', 'yanjingfan', 'vamnoize', 'Eugenemdk', 'explodingnuggets', 'MartinItsLinda',
|
| 71 |
+
'Web-Programmer-B-P', 'SergeyZhernovoy', 'sunhaidong', 'marcogrella', 'C0DEC0L0NY', 'JustinZuidgeest',
|
| 72 |
+
'ShareWiFi', 'ConusDaktis', 'lqhshishen', 'vaginessa', 'Juansero29', 'meghbhalerao', 'YunLemon',
|
| 73 |
+
'MeiVinEight', 'Huawei-DTSE-India-Delhi-NCR', 'ym-monkey', 'Selim042', 'ValentinGiboulot', 'jesusbmx',
|
| 74 |
+
'FantasybabyChange', 'zegelin', 'MeasureAuthoringTool', 'death-knight', 'abargnesi', 'cmunilla',
|
| 75 |
+
'sladyn98', 'jhaprabhatt', 'smartsv-dev', 'Lavaong', 'ShahabGT', 'WXB2010', 'digideskio', 'p1r9t3',
|
| 76 |
+
'chathamabate', 'heymysweetheart', 'blockchain-etl', 'Jeniel557'
|
| 77 |
+
]
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
class StackRepo(datasets.GeneratorBasedBuilder):
|
| 81 |
+
"""This is a builder class for the Stack-Repo dataset"""
|
| 82 |
+
|
| 83 |
+
VERSION = datasets.Version("1.0.0")
|
| 84 |
+
|
| 85 |
+
BUILDER_CONFIGS = [
|
| 86 |
+
datasets.BuilderConfig(
|
| 87 |
+
name="bm25_contexts",
|
| 88 |
+
version=VERSION,
|
| 89 |
+
description="This part of the dataset covers bm25 contexts"
|
| 90 |
+
),
|
| 91 |
+
datasets.BuilderConfig(
|
| 92 |
+
name="PP_contexts",
|
| 93 |
+
version=VERSION,
|
| 94 |
+
description="This part of the dataset covers PP contexts"
|
| 95 |
+
),
|
| 96 |
+
datasets.BuilderConfig(
|
| 97 |
+
name="randomNN_contexts",
|
| 98 |
+
version=VERSION,
|
| 99 |
+
description="This part of the dataset covers randomNN contexts"
|
| 100 |
+
),
|
| 101 |
+
datasets.BuilderConfig(
|
| 102 |
+
name="sources",
|
| 103 |
+
version=VERSION,
|
| 104 |
+
description="This part of the dataset covers java file sources used in building other configurations"
|
| 105 |
+
),
|
| 106 |
+
]
|
| 107 |
+
|
| 108 |
+
def _info(self):
|
| 109 |
+
if self.config.name == 'sources':
|
| 110 |
+
features = datasets.Features({
|
| 111 |
+
'file': datasets.Value('string'),
|
| 112 |
+
'content': datasets.Value('string')
|
| 113 |
+
})
|
| 114 |
+
else:
|
| 115 |
+
features = datasets.Features({
|
| 116 |
+
'id': datasets.Value('string'),
|
| 117 |
+
'hole_file': datasets.Value('string'),
|
| 118 |
+
'hole_line': datasets.Value('int32'),
|
| 119 |
+
'hole_pos': datasets.Value('int32'),
|
| 120 |
+
'question': datasets.Value('string'),
|
| 121 |
+
'target': datasets.Value('string'),
|
| 122 |
+
'answers': datasets.Sequence(
|
| 123 |
+
datasets.Value('string')
|
| 124 |
+
),
|
| 125 |
+
'ctxs': [{
|
| 126 |
+
'title': datasets.Value('string'),
|
| 127 |
+
'text': datasets.Value('string'),
|
| 128 |
+
'score': datasets.Value('float64')
|
| 129 |
+
}]
|
| 130 |
+
})
|
| 131 |
+
return datasets.DatasetInfo(
|
| 132 |
+
description=_DESCRIPTION,
|
| 133 |
+
features=features,
|
| 134 |
+
homepage=_HOMEPAGE,
|
| 135 |
+
license=_LICENSE,
|
| 136 |
+
citation=_CITATION,
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
@property
|
| 140 |
+
def manual_download_instructions(self):
|
| 141 |
+
# We are ok if user specifies local path instead of dataset name and data_dir
|
| 142 |
+
# for sources configuration and other configurations can be downloaded from the hub
|
| 143 |
+
# automatically. So, we manipulate return value here to get around manual_dir is None
|
| 144 |
+
# check in _check_manual_download
|
| 145 |
+
# NOTE: this hack can broke if implementaion of the _check_manual_download will change
|
| 146 |
+
# TODO: override _check_manual_download instead
|
| 147 |
+
if self.config.name == 'sources':
|
| 148 |
+
if not self.dl_manager.manual_dir is None:
|
| 149 |
+
base_path = Path(self.dl_manager.manual_dir)
|
| 150 |
+
else:
|
| 151 |
+
base_path = Path(self.base_path)
|
| 152 |
+
|
| 153 |
+
if base_path.expanduser().absolute().is_dir():
|
| 154 |
+
return None
|
| 155 |
+
|
| 156 |
+
return (
|
| 157 |
+
"first download the dataset to a local folder with "
|
| 158 |
+
"git clone https://huggingface.co/datasets/RepoFusion/Stack-Repo "
|
| 159 |
+
"<path/to/manual/data>"
|
| 160 |
+
)
|
| 161 |
+
else:
|
| 162 |
+
return None
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def _split_generators(self, dl_manager):
|
| 166 |
+
splits = [
|
| 167 |
+
(datasets.Split.TRAIN, 'train'),
|
| 168 |
+
(datasets.Split.TEST, 'test'),
|
| 169 |
+
(datasets.Split.VALIDATION, 'val')
|
| 170 |
+
]
|
| 171 |
+
|
| 172 |
+
if not dl_manager.manual_dir is None:
|
| 173 |
+
base_path = Path(dl_manager.manual_dir)
|
| 174 |
+
else:
|
| 175 |
+
base_path = Path(self.base_path)
|
| 176 |
+
|
| 177 |
+
if self.config.name == 'sources':
|
| 178 |
+
src = {
|
| 179 |
+
split[0]: [
|
| 180 |
+
el.relative_to(base_path)
|
| 181 |
+
for el in (base_path / f'data/{split[1]}/').rglob('*.java')
|
| 182 |
+
]
|
| 183 |
+
for split in splits
|
| 184 |
+
}
|
| 185 |
+
else:
|
| 186 |
+
src = {
|
| 187 |
+
split[0]: [
|
| 188 |
+
f'data/{split[1]}/{el}/hole_and_{self.config.name}.json'
|
| 189 |
+
for el in _SOURCES[split[1]]
|
| 190 |
+
]
|
| 191 |
+
for split in splits
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
data_dir = dl_manager.download_and_extract(src)
|
| 195 |
+
return [
|
| 196 |
+
datasets.SplitGenerator(
|
| 197 |
+
name=split[0],
|
| 198 |
+
gen_kwargs={
|
| 199 |
+
"filepaths": data_dir[split[0]],
|
| 200 |
+
"base_path": base_path
|
| 201 |
+
},
|
| 202 |
+
)
|
| 203 |
+
for split in splits
|
| 204 |
+
]
|
| 205 |
+
|
| 206 |
+
def _generate_examples(self, filepaths, base_path):
|
| 207 |
+
for filepath in filepaths:
|
| 208 |
+
if self.config.name == 'sources':
|
| 209 |
+
filepath = Path(filepath)
|
| 210 |
+
file = str(filepath.relative_to(base_path))
|
| 211 |
+
yield file, {
|
| 212 |
+
'file': file,
|
| 213 |
+
'content': filepath.read_text()
|
| 214 |
+
}
|
| 215 |
+
else:
|
| 216 |
+
with open(filepath, encoding="utf-8") as f:
|
| 217 |
+
for row in f:
|
| 218 |
+
data = json.loads(row)
|
| 219 |
+
parts = data['id'].rsplit('_', 2)
|
| 220 |
+
data['hole_file'] = str(base_path / parts[0])
|
| 221 |
+
data['hole_line'] = int(parts[1])
|
| 222 |
+
data['hole_pos'] = int(parts[2])
|
| 223 |
+
yield data['id'], data
|