|
import datasets |
|
import json |
|
|
|
class HfreviewsConfig(datasets.BuilderConfig): |
|
def __init__(self, features, **kwargs): |
|
super(HfreviewsConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs) |
|
self.features = features |
|
|
|
class MedicalInstitutionsReviews(datasets.GeneratorBasedBuilder): |
|
BUILDER_CONFIGS = [ |
|
HfreviewsConfig( |
|
name="simple", |
|
description="Simple config", |
|
features=["review_id", "content", "general", "quality", "service", "equipment", "food", "location"], |
|
) |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description='Healthcare facilities reviews dataset.', |
|
features=datasets.Features( |
|
{ |
|
"review_id": datasets.Value("string"), |
|
"content": datasets.Value("string"), |
|
"general": datasets.Value("string"), |
|
"quality": datasets.Value("string"), |
|
"service": datasets.Value("string"), |
|
"equipment": datasets.Value("string"), |
|
"food": datasets.Value("string"), |
|
"location": datasets.Value("string"), |
|
"Idx": datasets.Value("int32"), |
|
} |
|
), |
|
) |
|
|
|
def _split_generators(self, dl_manager: datasets.DownloadManager): |
|
urls_to_download = { |
|
"train": "medical_institutions_reviews.jsonl" |
|
} |
|
downloaded_files = dl_manager.download_and_extract(urls_to_download) |
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}) |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
"""Yields examples.""" |
|
with open(filepath, encoding="utf-8") as f: |
|
for uid, row in enumerate(f): |
|
data = json.loads(row) |
|
data["Idx"] = uid |
|
yield uid, data |
|
|