|
import csv |
|
|
|
import datasets |
|
import json |
|
from io import StringIO |
|
from pathlib import Path |
|
import pandas as pd |
|
|
|
_CITATION = """""" |
|
_DESCRIPTION = """""" |
|
_HOMEPAGE = "" |
|
_URLS = { |
|
"knowledge_questions": "data/knowledge_questions.json.zip", |
|
"rc_questions": "data/rc_questions.json.zip", |
|
"statutes": "data/statutes.tsv.zip", |
|
} |
|
|
|
|
|
|
|
_CONFIGS = {} |
|
|
|
_CONFIGS["knowledge_questions"] = { |
|
"description": "Answer knowledge questions about housing law in the different states.", |
|
"features": { |
|
"idx": datasets.Value("int32"), |
|
"state": datasets.Value("string"), |
|
"question": datasets.Value("string"), |
|
"answer": datasets.Value("string"), |
|
"question_group": datasets.Value("int32"), |
|
"statutes": datasets.Sequence( |
|
{ |
|
"citation": datasets.Value("string"), |
|
"excerpt": datasets.Value("string"), |
|
} |
|
), |
|
"original_question": datasets.Value("string"), |
|
"caveats": datasets.Sequence([datasets.Value("string")]), |
|
}, |
|
"license": None, |
|
} |
|
|
|
_CONFIGS["rc_questions"] = { |
|
"description": "Answer RC questions about housing law in the different states.", |
|
"features": { |
|
"idx": datasets.Value("int32"), |
|
"state": datasets.Value("string"), |
|
"question": datasets.Value("string"), |
|
"answer": datasets.Value("string"), |
|
"question_group": datasets.Value("int32"), |
|
"statutes": datasets.Sequence( |
|
{ |
|
"statute_idx": datasets.Value("int32"), |
|
"citation": datasets.Value("string"), |
|
"excerpt": datasets.Value("string"), |
|
} |
|
), |
|
"original_question": datasets.Value("string"), |
|
"caveats": datasets.Sequence([datasets.Value("string")]), |
|
}, |
|
"license": None, |
|
} |
|
|
|
_CONFIGS["statutes"] = { |
|
"description": "Corpus of statutes", |
|
"features": { |
|
"citation": datasets.Value("string"), |
|
"path": datasets.Value("string"), |
|
"state": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
"idx": datasets.Value("int32"), |
|
}, |
|
"license": None, |
|
} |
|
|
|
|
|
class HousingQA(datasets.GeneratorBasedBuilder): |
|
"""TODO""" |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name=task, version=datasets.Version("1.0.0"), description=task, |
|
) |
|
for task in _CONFIGS |
|
] |
|
|
|
def _info(self): |
|
features = _CONFIGS[self.config.name]["features"] |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features(features), |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
license=_CONFIGS[self.config.name]["license"], |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
downloaded_file_dir = Path(dl_manager.download_and_extract(_URLS[self.config.name])) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"downloaded_file_dir": downloaded_file_dir, |
|
"name": self.config.name, |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, downloaded_file_dir, name): |
|
"""Yields examples as (key, example) tuples.""" |
|
|
|
if name in ["knowledge_questions"]: |
|
fpath = downloaded_file_dir / f"{name}.json" |
|
data = json.loads(fpath.read_text()) |
|
for id_line, data in enumerate(data): |
|
yield id_line, data |
|
|
|
if name in ["rc_questions"]: |
|
fpath = downloaded_file_dir / f"{name}.json" |
|
data = json.loads(fpath.read_text()) |
|
for id_line, data in enumerate(data): |
|
yield id_line, data |
|
|
|
if name in ["statutes"]: |
|
fpath = downloaded_file_dir / f"{name}.tsv" |
|
data = pd.read_csv(fpath, sep="\t", dtype={'index': 'int32'}) |
|
data = data.to_dict(orient="records") |
|
for id_line, data in enumerate(data): |
|
yield id_line, data |