Datasets:
Delete loading script
Browse files- wikihow_es.py +0 -114
wikihow_es.py
DELETED
@@ -1,114 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import re
|
3 |
-
import csv
|
4 |
-
import json
|
5 |
-
import datasets
|
6 |
-
|
7 |
-
_DESCRIPTION = "Spanish articles from WikiHow"
|
8 |
-
_HOMEPAGE = "https://www.wikihow.com"
|
9 |
-
_LICENSE = "CC BY-NC-SA 3.0"
|
10 |
-
_VERSION = "1.1.0"
|
11 |
-
|
12 |
-
_DATAPATH = "wikihow_es.jsonl"
|
13 |
-
|
14 |
-
_CATEGORIES = [
|
15 |
-
"salud",
|
16 |
-
"viajes",
|
17 |
-
"deportes",
|
18 |
-
"relaciones",
|
19 |
-
"pasatiempos",
|
20 |
-
"adolescentes",
|
21 |
-
"vida-familiar",
|
22 |
-
"en-el-trabajo",
|
23 |
-
"comida-y-diversión",
|
24 |
-
"finanzas-y-negocios",
|
25 |
-
"mascotas-y-animales",
|
26 |
-
"carreras-y-educación",
|
27 |
-
"filosofía-y-religión",
|
28 |
-
"arte-y-entretenimiento",
|
29 |
-
"en-la-casa-y-el-jardín",
|
30 |
-
"cuidado-y-estilo-personal",
|
31 |
-
"computadoras-y-electrónica",
|
32 |
-
"días-de-fiesta-y-tradiciones",
|
33 |
-
"automóviles-y-otros-vehículos",
|
34 |
-
]
|
35 |
-
|
36 |
-
def format_methods(methods, short=False):
|
37 |
-
EOL = "\n" if short else "\n\n"
|
38 |
-
formatted = []
|
39 |
-
for method in methods:
|
40 |
-
if method["title"].lower() != "pasos":
|
41 |
-
content = f"Método {method['number']}: {method['title']}{EOL}"
|
42 |
-
else:
|
43 |
-
content = f"Sigue los siguientes pasos:{EOL}"
|
44 |
-
for step in method["steps"]:
|
45 |
-
step_content = re.sub(r"\n+", "\n", step).strip()
|
46 |
-
if short:
|
47 |
-
step_content = step_content.split("\n")[0]
|
48 |
-
content += step_content + EOL
|
49 |
-
formatted.append(content.strip())
|
50 |
-
return formatted
|
51 |
-
|
52 |
-
|
53 |
-
class WikiHowEs(datasets.GeneratorBasedBuilder):
|
54 |
-
""" WikiHowEs: Collection of Spanish tutorials. """
|
55 |
-
|
56 |
-
VERSION = datasets.Version(_VERSION)
|
57 |
-
|
58 |
-
DEFAULT_CONFIG_NAME = "all"
|
59 |
-
BUILDER_CONFIGS = [datasets.BuilderConfig(name="all", version=VERSION, description="All articles from WikiHow-ES.")]
|
60 |
-
for _CAT in _CATEGORIES:
|
61 |
-
BUILDER_CONFIGS.append(
|
62 |
-
datasets.BuilderConfig(name=_CAT, version=VERSION, description=f"Articles from the category {_CAT}")
|
63 |
-
)
|
64 |
-
|
65 |
-
@staticmethod
|
66 |
-
def _info():
|
67 |
-
features = datasets.Features(
|
68 |
-
{
|
69 |
-
"category": datasets.Value("string"),
|
70 |
-
"question": datasets.Value("string"),
|
71 |
-
"introduction": datasets.Value("string"),
|
72 |
-
"answers": datasets.features.Sequence(datasets.Value("string")),
|
73 |
-
"short_answers": datasets.features.Sequence(datasets.Value("string")),
|
74 |
-
"url": datasets.Value("string"),
|
75 |
-
"num_answers": datasets.Value("int32"),
|
76 |
-
"num_refs": datasets.Value("int32"),
|
77 |
-
"expert_author": datasets.Value("bool"),
|
78 |
-
}
|
79 |
-
)
|
80 |
-
return datasets.DatasetInfo(
|
81 |
-
description=_DESCRIPTION,
|
82 |
-
features=features,
|
83 |
-
homepage=_HOMEPAGE,
|
84 |
-
license=_LICENSE,
|
85 |
-
)
|
86 |
-
|
87 |
-
@staticmethod
|
88 |
-
def _split_generators(dl_manager):
|
89 |
-
data_dir = dl_manager.download_and_extract(_DATAPATH)
|
90 |
-
return [
|
91 |
-
datasets.SplitGenerator(
|
92 |
-
name=datasets.Split.TRAIN,
|
93 |
-
gen_kwargs={
|
94 |
-
"filepath": data_dir,
|
95 |
-
},
|
96 |
-
),
|
97 |
-
]
|
98 |
-
|
99 |
-
def _generate_examples(self, filepath):
|
100 |
-
with open(filepath, encoding="utf-8") as f:
|
101 |
-
for key, row in enumerate(f):
|
102 |
-
data = json.loads(row)
|
103 |
-
if self.config.name in ["all", data["category"].lower()]:
|
104 |
-
yield key, {
|
105 |
-
"category": data["category"],
|
106 |
-
"question": f"¿{data['title']}?",
|
107 |
-
"introduction": data["intro"],
|
108 |
-
"answers": format_methods(data["methods"], short=False),
|
109 |
-
"short_answers": format_methods(data["methods"], short=True),
|
110 |
-
"num_answers": data["num_methods"],
|
111 |
-
"num_refs": data["num_refs"],
|
112 |
-
"expert_author": data["expert_author"],
|
113 |
-
"url": data["url"],
|
114 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|