java-cmpx / java-cmpx.py
anjandash's picture
Handled CSV field_size_limit
5c82dda
raw
history blame
2.02 kB
import os
import sys
import csv
import datasets
csv.field_size_limit(sys.maxsize)
_DESCRIPTION = "JEMMA Java CMPX"
_CITATION = "NOT AVAILABLE"
_HOMEPAGE = "NOT AVAILABLE"
_LICENSE = "MIT"
_BASE_TRAIN_FILE_URL = "https://huggingface.co/datasets/giganticode/java-cmpx/resolve/main/Jemma_Properties_Methods_CMPX__Huggingface_Dataset_TRAIN.csv"
_BASE_TEST_FILE_URL = "https://huggingface.co/datasets/giganticode/java-cmpx/resolve/main/Jemma_Properties_Methods_CMPX__Huggingface_Dataset_TEST.csv"
_URLS = {
"train": _BASE_TRAIN_FILE_URL,
"test": _BASE_TEST_FILE_URL
}
class JavaCMPX(datasets.GeneratorBasedBuilder):
"""Java CMPX"""
def _info(self):
"""Returns Info"""
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"method_id": datasets.Value("string"),
"cyclomatic_complexity": datasets.Value("int32"),
"method_text": datasets.Value("string")
}
),
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators"""
data_file = dl_manager.download(_URLS)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_file["train"]}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": data_file["test"]}),
]
def _generate_examples(self, filepath):
"""Yields Examples"""
with open(filepath, encoding="utf-8") as f:
reader = csv.reader(f)
for id_, row in enumerate(reader):
if id_ == 0:
continue
yield id_, {
"method_id": row[0],
"cyclomatic_complexity": row[1],
"method_text": row[2],
}