File size: 5,643 Bytes
9bfab44 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
from pathlib import Path
from typing import Dict, List, Tuple
from dataclasses import dataclass
import datasets
import json
import xml.etree.ElementTree as ET
_CITATION = """\
@article{nuranti2022predicting,
title={Predicting the Category and the Length of Punishment in Indonesian Courts Based on Previous Court Decision Documents},
author={Nuranti, Eka Qadri and Yulianti, Evi and Husin, Husna Sarirah},
journal={Computers},
volume={11},
number={6},
pages={88},
year={2022},
publisher={Multidisciplinary Digital Publishing Institute}
}
"""
_LANGUAGES = ["id"]
_LOCAL = False
_DATASETNAME = "indo_law"
_DESCRIPTION = """\
This study presents predictions of first-level judicial decisions by utilizing a collection of Indonesian court decision documents.
We propose using multi-level learning, namely, CNN+attention, using decision document sections as features to predict the category and the length of punishment in Indonesian courts.
Our results demonstrate that the decision document sections that strongly affected the accuracy of the prediction model were prosecution history, facts, legal facts, and legal considerations.
"""
_HOMEPAGE = ""
_LICENSE = "Unknown"
_URLS = {
_DATASETNAME: "https://github.com/ir-nlp-csui/indo-law/zipball/master",
}
_SOURCE_VERSION = "1.0.0"
@dataclass
class IndoLawConfig(datasets.BuilderConfig):
name: str = None
version: datasets.Version = None
description: str = None
schema: str = None
subset_id: str = None
class IndoLaw(datasets.GeneratorBasedBuilder):
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
_LABELS = ["pidana-khusus", "pidana-umum"]
BUILDER_CONFIGS = [
IndoLawConfig(
name="indo_law_source",
version=SOURCE_VERSION,
description="Indo-Law source schema",
schema="source",
subset_id="indo_law",
),
IndoLawConfig(
name="indo_law_nusantara_text",
version=SOURCE_VERSION,
description="Indo-Law Nusantara schema",
schema="nusantara_text",
subset_id="indo_law",
),
]
DEFAULT_CONFIG_NAME = "indo_law_source"
def _get_features(self, label_names):
return datasets.Features(
{
"id": datasets.Value("string"),
"text": datasets.Value("string"),
"label": datasets.ClassLabel(names=label_names),
}
)
def _info(self) -> datasets.DatasetInfo:
if self.config.schema == "source":
features = datasets.Features(
{
"id": datasets.Value("string"),
"klasifikasi": datasets.Value("string"),
"sub_klasifikasi": datasets.Value("string"),
"paragraphs": datasets.Sequence({
"tag": datasets.Value("string"),
"value": datasets.Value("string"),
}),
}
)
elif self.config.schema == "nusantara_text":
features = self._get_features(self._LABELS)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[
datasets.SplitGenerator]:
urls = _URLS[_DATASETNAME]
data_dir = dl_manager.download_and_extract(urls)
data_dir = os.path.join(data_dir, "ir-nlp-csui-indo-law-6734033", "dataset")
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": data_dir,
"split": "train",
},
),
]
def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
files = os.listdir(filepath)
results = []
for file in files:
data = self._parse_file(os.path.join(filepath, file))
results.append(data)
if self.config.schema == "source":
key = 0
for result in results:
example = {
"id": result["id"],
"klasifikasi": result["klasifikasi"],
"sub_klasifikasi": result["klasifikasi"],
"paragraphs": [],
}
for tag in result["paragraphs"]:
example["paragraphs"].append({
"tag": tag,
"value": result["paragraphs"][tag]
})
yield key, example
key += 1
elif self.config.schema == "nusantara_text":
key = 0
for result in results:
example = {
"id": result["id"],
"text": json.dumps(result["paragraphs"]),
"label": result["klasifikasi"],
}
yield key, example
key += 1
def _parse_file(self, file_path):
root = ET.parse(file_path).getroot()
data = {
"id": root.attrib["id"],
"klasifikasi": root.attrib["klasifikasi"],
"sub_klasifikasi": root.attrib["sub_klasifikasi"],
"paragraphs": {}
}
for child in root:
data["paragraphs"].update({
child.tag: child.text
})
return data
|