Update codeforces_question_solution_label.py
Browse files
codeforces_question_solution_label.py
CHANGED
|
@@ -3,14 +3,19 @@ import os
|
|
| 3 |
import json
|
| 4 |
|
| 5 |
class CodeforcesQuestionSolutionLabel(datasets.GeneratorBasedBuilder):
|
|
|
|
|
|
|
|
|
|
| 6 |
BUILDER_CONFIGS = [
|
| 7 |
-
datasets.BuilderConfig(name="cpp", description="C++
|
| 8 |
-
datasets.BuilderConfig(name="py", description="Python
|
| 9 |
-
datasets.BuilderConfig(name="java", description="Java
|
| 10 |
]
|
| 11 |
|
| 12 |
def _info(self):
|
|
|
|
| 13 |
return datasets.DatasetInfo(
|
|
|
|
| 14 |
features=datasets.Features({
|
| 15 |
"contest_id": datasets.Value("string"),
|
| 16 |
"problem_id": datasets.Value("string"),
|
|
@@ -19,11 +24,16 @@ class CodeforcesQuestionSolutionLabel(datasets.GeneratorBasedBuilder):
|
|
| 19 |
"code": datasets.Value("string"),
|
| 20 |
"language": datasets.Value("string"),
|
| 21 |
}),
|
|
|
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
def _split_generators(self, dl_manager):
|
|
|
|
| 25 |
config = self.config.name
|
| 26 |
-
data_dir =
|
|
|
|
|
|
|
| 27 |
return [
|
| 28 |
datasets.SplitGenerator(
|
| 29 |
name=datasets.Split.TRAIN,
|
|
@@ -40,6 +50,7 @@ class CodeforcesQuestionSolutionLabel(datasets.GeneratorBasedBuilder):
|
|
| 40 |
]
|
| 41 |
|
| 42 |
def _generate_examples(self, filepath):
|
|
|
|
| 43 |
with open(filepath, encoding="utf-8") as f:
|
| 44 |
for key, row in enumerate(f):
|
| 45 |
data = json.loads(row)
|
|
|
|
| 3 |
import json
|
| 4 |
|
| 5 |
class CodeforcesQuestionSolutionLabel(datasets.GeneratorBasedBuilder):
|
| 6 |
+
"""Codeforces Question Solution Label Dataset."""
|
| 7 |
+
|
| 8 |
+
# Define supported configurations (language subsets)
|
| 9 |
BUILDER_CONFIGS = [
|
| 10 |
+
datasets.BuilderConfig(name="cpp", description="C++ solutions for Codeforces problems"),
|
| 11 |
+
datasets.BuilderConfig(name="py", description="Python solutions for Codeforces problems"),
|
| 12 |
+
datasets.BuilderConfig(name="java", description="Java solutions for Codeforces problems"),
|
| 13 |
]
|
| 14 |
|
| 15 |
def _info(self):
|
| 16 |
+
# Define dataset features (fields and types)
|
| 17 |
return datasets.DatasetInfo(
|
| 18 |
+
description="A dataset of Codeforces problem solutions labeled by language",
|
| 19 |
features=datasets.Features({
|
| 20 |
"contest_id": datasets.Value("string"),
|
| 21 |
"problem_id": datasets.Value("string"),
|
|
|
|
| 24 |
"code": datasets.Value("string"),
|
| 25 |
"language": datasets.Value("string"),
|
| 26 |
}),
|
| 27 |
+
homepage="https://codeforces.com/",
|
| 28 |
+
citation="Data collected from Codeforces API",
|
| 29 |
)
|
| 30 |
|
| 31 |
def _split_generators(self, dl_manager):
|
| 32 |
+
# Get the current configuration (language)
|
| 33 |
config = self.config.name
|
| 34 |
+
data_dir = os.path.join("data", config) # Data files are in data/<language>/
|
| 35 |
+
|
| 36 |
+
# Define generators for each split
|
| 37 |
return [
|
| 38 |
datasets.SplitGenerator(
|
| 39 |
name=datasets.Split.TRAIN,
|
|
|
|
| 50 |
]
|
| 51 |
|
| 52 |
def _generate_examples(self, filepath):
|
| 53 |
+
# Generate examples from the file
|
| 54 |
with open(filepath, encoding="utf-8") as f:
|
| 55 |
for key, row in enumerate(f):
|
| 56 |
data = json.loads(row)
|