v2: per-trial structured configs from Old Bailey Online XML 7.2 (trials / sessions / ordinarys_accounts + verbatim TEI)
#4
by davanstrien HF Staff - opened
- README.md +13 -26
- data/train-00000-of-00002.parquet → ordinarys_accounts/train-00000-of-00001.parquet +2 -2
- scripts/parse_obo.py +262 -0
- data/train-00001-of-00002.parquet → sessions/train-00000-of-00006.parquet +2 -2
- sessions/train-00001-of-00006.parquet +3 -0
- sessions/train-00002-of-00006.parquet +3 -0
- sessions/train-00003-of-00006.parquet +3 -0
- sessions/train-00004-of-00006.parquet +3 -0
- sessions/train-00005-of-00006.parquet +3 -0
- trials/train-00000-of-00006.parquet +3 -0
- trials/train-00001-of-00006.parquet +3 -0
- trials/train-00002-of-00006.parquet +3 -0
- trials/train-00003-of-00006.parquet +3 -0
- trials/train-00004-of-00006.parquet +3 -0
- trials/train-00005-of-00006.parquet +3 -0
README.md
CHANGED
|
@@ -7,11 +7,11 @@ language_creators:
|
|
| 7 |
language:
|
| 8 |
- en
|
| 9 |
license:
|
| 10 |
-
- cc-by-4.0
|
| 11 |
multilinguality:
|
| 12 |
- monolingual
|
| 13 |
size_categories:
|
| 14 |
-
-
|
| 15 |
source_datasets:
|
| 16 |
- original
|
| 17 |
task_categories:
|
|
@@ -22,34 +22,21 @@ task_ids:
|
|
| 22 |
- language-modeling
|
| 23 |
- masked-language-modeling
|
| 24 |
pretty_name: Old Bailey Proceedings
|
| 25 |
-
dataset_info:
|
| 26 |
-
features:
|
| 27 |
-
- name: id
|
| 28 |
-
dtype: string
|
| 29 |
-
- name: text
|
| 30 |
-
dtype: string
|
| 31 |
-
- name: places
|
| 32 |
-
sequence: string
|
| 33 |
-
- name: type
|
| 34 |
-
dtype: string
|
| 35 |
-
- name: persons
|
| 36 |
-
sequence: string
|
| 37 |
-
- name: date
|
| 38 |
-
dtype: string
|
| 39 |
-
splits:
|
| 40 |
-
- name: train
|
| 41 |
-
num_bytes: 719949847
|
| 42 |
-
num_examples: 2638
|
| 43 |
-
download_size: 370751172
|
| 44 |
-
dataset_size: 719949847
|
| 45 |
configs:
|
| 46 |
-
- config_name:
|
|
|
|
| 47 |
data_files:
|
| 48 |
- split: train
|
| 49 |
-
path:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
---
|
| 51 |
-
[Needs More Information]
|
| 52 |
-
|
| 53 |
# Dataset Card for Old Bailey Proceedings
|
| 54 |
|
| 55 |
## Table of Contents
|
|
|
|
| 7 |
language:
|
| 8 |
- en
|
| 9 |
license:
|
| 10 |
+
- cc-by-nc-4.0
|
| 11 |
multilinguality:
|
| 12 |
- monolingual
|
| 13 |
size_categories:
|
| 14 |
+
- 100K<n<1M
|
| 15 |
source_datasets:
|
| 16 |
- original
|
| 17 |
task_categories:
|
|
|
|
| 22 |
- language-modeling
|
| 23 |
- masked-language-modeling
|
| 24 |
pretty_name: Old Bailey Proceedings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
configs:
|
| 26 |
+
- config_name: trials
|
| 27 |
+
default: true
|
| 28 |
data_files:
|
| 29 |
- split: train
|
| 30 |
+
path: trials/train-*
|
| 31 |
+
- config_name: sessions
|
| 32 |
+
data_files:
|
| 33 |
+
- split: train
|
| 34 |
+
path: sessions/train-*
|
| 35 |
+
- config_name: ordinarys_accounts
|
| 36 |
+
data_files:
|
| 37 |
+
- split: train
|
| 38 |
+
path: ordinarys_accounts/train-*
|
| 39 |
---
|
|
|
|
|
|
|
| 40 |
# Dataset Card for Old Bailey Proceedings
|
| 41 |
|
| 42 |
## Table of Contents
|
data/train-00000-of-00002.parquet → ordinarys_accounts/train-00000-of-00001.parquet
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fcd20cb624451c06d4c8c9d38b8e725d3af007f5686f53c7cae7f3aef359abfd
|
| 3 |
+
size 11081741
|
scripts/parse_obo.py
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Parse Old Bailey Online XML (v7.2, figshare 10.15131/shef.data.4775434.v2) into one row per trial, with typed
|
| 2 |
+
persons, offences, verdicts, punishments and the defendant→offence→verdict→punishment joins; one row per session; one
|
| 3 |
+
row per Ordinary's Account. Verbatim TEI is kept in an `xml` column.
|
| 4 |
+
|
| 5 |
+
Usage: python parse_obo.py <xml_root> <out_dir> [--limit N] [--stats]
|
| 6 |
+
|
| 7 |
+
Conventions (see dataset card):
|
| 8 |
+
- persons.type is null when the source assigns no role (part-1 names tagged by GATE without a role).
|
| 9 |
+
- name = the person's own surface text (nested <persName> excluded); given/surname/gender/age/occupation/place/aliases
|
| 10 |
+
come from <interp> children and persNameOccupation / persNamePlace / nameAlias joins (first value wins for interps —
|
| 11 |
+
no repeated interp types were found in the corpus sample).
|
| 12 |
+
- <lb/> inside text: joined without a space (hyphenation-style breaks are the majority) unless the break sits between a
|
| 13 |
+
word character and an upper-case letter, where a space is inserted.
|
| 14 |
+
- punishments: attached via defendantPunishment joins file-wide (part-1 sentences sit in a separate punishmentSummary
|
| 15 |
+
div; a few joins point across trial divs — kept as the source has them, and the punishment row records the trial div
|
| 16 |
+
it was found in). An in-trial punishment with no join anywhere is kept with defendant_ids = [].
|
| 17 |
+
- charges: criminalCharge joins; target ids that resolve to nothing in the trial are kept in `unresolved_ids`.
|
| 18 |
+
- sessions.summary_items: every <rs> outside a trialAccount div (offence/verdict/punishment/alias/occupation/crimeDate) with its
|
| 19 |
+
category, text, containing div and joined ids — the 1670s–80s sessions record outcomes in supplementaryMaterial, not trials.
|
| 20 |
+
"""
|
| 21 |
+
import re, sys, json, collections
|
| 22 |
+
from pathlib import Path
|
| 23 |
+
from lxml import etree
|
| 24 |
+
import polars as pl
|
| 25 |
+
|
| 26 |
+
ROOT = Path(sys.argv[1]); OUT = Path(sys.argv[2]); OUT.mkdir(parents=True, exist_ok=True)
|
| 27 |
+
LIMIT = int(sys.argv[sys.argv.index("--limit") + 1]) if "--limit" in sys.argv else None
|
| 28 |
+
STATS = "--stats" in sys.argv
|
| 29 |
+
STRICT = etree.XMLParser(huge_tree=True)
|
| 30 |
+
LENIENT = etree.XMLParser(recover=True, huge_tree=True)
|
| 31 |
+
WS = re.compile(r"\s+")
|
| 32 |
+
ENC_RE = re.compile(rb'^<\?xml[^>]*encoding\s*=\s*["\']([A-Za-z0-9._-]+)["\']')
|
| 33 |
+
|
| 34 |
+
stats = collections.Counter(); warnings = []
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def read_xml(path):
|
| 38 |
+
"""Return (root, verbatim_text). Decode with the declared encoding; parse strictly, fall back to recovery + warn."""
|
| 39 |
+
raw = path.read_bytes()
|
| 40 |
+
m = ENC_RE.match(raw[:200]); enc = m.group(1).decode() if m else "utf-8"
|
| 41 |
+
if raw.startswith(b"\xef\xbb\xbf"): enc = "utf-8-sig"
|
| 42 |
+
elif raw.startswith((b"\xff\xfe", b"\xfe\xff")): enc = "utf-16"
|
| 43 |
+
try: text = raw.decode(enc) # verbatim column must be lossless: no errors="replace"
|
| 44 |
+
except (UnicodeDecodeError, LookupError) as e:
|
| 45 |
+
raise SystemExit(f"{path.name}: cannot decode with declared encoding {enc!r}: {e}")
|
| 46 |
+
try: root = etree.fromstring(raw, STRICT)
|
| 47 |
+
except etree.XMLSyntaxError as e:
|
| 48 |
+
root = etree.fromstring(raw, LENIENT); warnings.append(f"{path.name}: recovered parse ({str(e)[:80]})"); stats["recovered_parse"] += 1
|
| 49 |
+
return root, text
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def norm(s): return WS.sub(" ", s or "").strip()
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _collect(el, parts, skip_tag=None):
|
| 56 |
+
if el.tag == "lb": parts.append("\x00")
|
| 57 |
+
elif el.text: parts.append(el.text)
|
| 58 |
+
for c in el:
|
| 59 |
+
if not (skip_tag is not None and c.tag == skip_tag): _collect(c, parts, skip_tag)
|
| 60 |
+
if c.tail: parts.append(c.tail)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def text_of(el, skip_tag=None):
|
| 64 |
+
parts = []; _collect(el, parts, skip_tag)
|
| 65 |
+
s = "".join(parts)
|
| 66 |
+
s = re.sub(r"(\w)\x00(?=[A-Z])", r"\1 ", s).replace("\x00", "")
|
| 67 |
+
return norm(s)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def interps(el):
|
| 71 |
+
d = {}
|
| 72 |
+
for i in el.findall("interp"): d.setdefault(i.get("type"), i.get("value"))
|
| 73 |
+
return d
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def parse_person(p):
|
| 77 |
+
d = interps(p)
|
| 78 |
+
has_nested = p.find(".//persName") is not None
|
| 79 |
+
name = text_of(p, skip_tag="persName")
|
| 80 |
+
if (has_nested or not name) and (d.get("given") or d.get("surname")): name = norm(f"{d.get('given') or ''} {d.get('surname') or ''}")
|
| 81 |
+
if not name: name = text_of(p)
|
| 82 |
+
return {"id": p.get("id"), "type": (p.get("type").replace("Name", "") if p.get("type") else None),
|
| 83 |
+
"name": name, "given": d.get("given"), "surname": d.get("surname"), "gender": d.get("gender"), "age": d.get("age"),
|
| 84 |
+
"occupation": d.get("occupation"), "place": None, "aliases": []}
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def parse_rs(rs):
|
| 88 |
+
d = interps(rs)
|
| 89 |
+
return {**d, "id": rs.get("id"), "text": text_of(rs)}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
trials, oas, sessions = [], [], []
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def index_file(root):
|
| 96 |
+
"""File-level indexes: rs by id, persons by id (enriched from joins), places, joins by member id."""
|
| 97 |
+
all_rs = {rs.get("id"): (rs, parse_rs(rs)) for rs in root.iter("rs") if rs.get("id")}
|
| 98 |
+
all_place = {x.get("id"): text_of(x) for x in root.iter("placeName") if x.get("id")}
|
| 99 |
+
pers_el = [p for p in root.iter("persName")]
|
| 100 |
+
all_pers = {p.get("id"): parse_person(p) for p in pers_el if p.get("id")}
|
| 101 |
+
joins = collections.defaultdict(list); by_member = collections.defaultdict(list)
|
| 102 |
+
for j in root.iter("join"):
|
| 103 |
+
res, targets = j.get("result"), j.get("targets", "").split()
|
| 104 |
+
stats[f"join:{res}"] += 1; joins[res].append(targets)
|
| 105 |
+
for t in targets: by_member[t].append((res, targets))
|
| 106 |
+
for pid, per in all_pers.items(): # enrich persons from joins, once, file-wide
|
| 107 |
+
for res, targets in by_member.get(pid, []):
|
| 108 |
+
others = [t for t in targets if t != pid]
|
| 109 |
+
if res == "persNameOccupation" and per["occupation"] is None:
|
| 110 |
+
for t in others:
|
| 111 |
+
if t in all_rs: per["occupation"] = all_rs[t][1]["text"]
|
| 112 |
+
elif res == "persNamePlace" and per["place"] is None:
|
| 113 |
+
for t in others:
|
| 114 |
+
if t in all_place: per["place"] = all_place[t]
|
| 115 |
+
elif res == "nameAlias":
|
| 116 |
+
for t in others:
|
| 117 |
+
if t in all_rs and all_rs[t][1]["text"] not in per["aliases"]: per["aliases"].append(all_rs[t][1]["text"])
|
| 118 |
+
return all_rs, all_place, all_pers, pers_el, joins, by_member
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def parse_session(path):
|
| 122 |
+
root, raw_text = read_xml(path)
|
| 123 |
+
if root is None: stats["unparseable"] += 1; return
|
| 124 |
+
session_id = path.stem
|
| 125 |
+
all_rs, all_place, all_pers, pers_el, joins, by_member = index_file(root)
|
| 126 |
+
rs_div = {}
|
| 127 |
+
for rs in root.iter("rs"):
|
| 128 |
+
if rs.get("id"):
|
| 129 |
+
anc = next(rs.iterancestors("div1"), None); rs_div[rs.get("id")] = anc.get("id") if anc is not None else None
|
| 130 |
+
body = root.find(".//body")
|
| 131 |
+
div_types = collections.Counter(d.get("type") for d in root.iter("div1"))
|
| 132 |
+
summary_items = [] # rs elements outside trialAccount divs (supplementaryMaterial / punishmentSummary / no div): early sessions record outcomes here
|
| 133 |
+
for rs in root.iter("rs"):
|
| 134 |
+
anc = next(rs.iterancestors("div1"), None)
|
| 135 |
+
if rs.get("id") and (anc is None or anc.get("type") != "trialAccount"):
|
| 136 |
+
d = all_rs[rs.get("id")][1]
|
| 137 |
+
linked = sorted({t for res, targets in by_member.get(rs.get("id"), []) for t in targets if t != rs.get("id")})
|
| 138 |
+
cat = d.get("offenceCategory") or d.get("verdictCategory") or d.get("punishmentCategory")
|
| 139 |
+
sub = d.get("offenceSubcategory") or d.get("verdictSubcategory") or d.get("punishmentSubcategory")
|
| 140 |
+
summary_items.append({"id": rs.get("id"), "type": rs.get("type"), "category": cat, "subcategory": sub, "text": d["text"],
|
| 141 |
+
"found_in": anc.get("id") if anc is not None else None, "linked_ids": linked})
|
| 142 |
+
stats[f"summary_item:{rs.get('type')}"] += 1
|
| 143 |
+
sessions.append({"summary_items": summary_items, "session_id": session_id, "date": session_id[:8], "part": 1 if session_id[:8] <= "18341024" else 2,
|
| 144 |
+
"text": text_of(body) if body is not None else text_of(root), "xml": raw_text, "n_trials": div_types.get("trialAccount", 0),
|
| 145 |
+
"div_types": json.dumps(dict(div_types)), "persons": [all_pers[p.get("id")] if p.get("id") else parse_person(p) for p in pers_el],
|
| 146 |
+
"places": [text_of(x) for x in root.iter("placeName")], "obo_url": f"https://www.oldbaileyonline.org/browse.jsp?name={session_id}"})
|
| 147 |
+
for div in root.iter("div1"):
|
| 148 |
+
stats[f"div1:{div.get('type')}"] += 1
|
| 149 |
+
if div.get("type") != "trialAccount": continue
|
| 150 |
+
tid = div.get("id"); di = interps(div)
|
| 151 |
+
persons = [all_pers[p.get("id")] if p.get("id") else parse_person(p) for p in div.iter("persName")]
|
| 152 |
+
def_ids = [p["id"] for p in persons if p["type"] == "defendant" and p["id"]] # source order
|
| 153 |
+
def_set = set(def_ids)
|
| 154 |
+
offences = [parse_rs(rs) for rs in div.iter("rs") if rs.get("type") == "offenceDescription"]
|
| 155 |
+
verdicts = [parse_rs(rs) for rs in div.iter("rs") if rs.get("type") == "verdictDescription"]
|
| 156 |
+
off_ids = {o["id"] for o in offences}; ver_ids = {v["id"] for v in verdicts}
|
| 157 |
+
for o in offences:
|
| 158 |
+
o["victim_ids"] = []; o["crime_date"] = None; o["place"] = None
|
| 159 |
+
for res, targets in by_member.get(o["id"], []):
|
| 160 |
+
others = [t for t in targets if t != o["id"]]
|
| 161 |
+
if res == "offenceVictim": o["victim_ids"] += others
|
| 162 |
+
elif res == "offencePlace":
|
| 163 |
+
for t in others:
|
| 164 |
+
if t in all_place: o["place"] = all_place[t]
|
| 165 |
+
elif res == "offenceCrimeDate":
|
| 166 |
+
for t in others:
|
| 167 |
+
if t in all_rs: o["crime_date"] = all_rs[t][1]["text"]
|
| 168 |
+
charges = []
|
| 169 |
+
for targets in joins.get("criminalCharge", []):
|
| 170 |
+
if not any(t in def_set for t in targets): continue
|
| 171 |
+
unresolved = [t for t in targets if t not in def_set and t not in off_ids and t not in ver_ids]
|
| 172 |
+
if unresolved: stats["charge_unresolved_targets"] += 1
|
| 173 |
+
charges.append({"defendant_ids": [t for t in targets if t in def_set], "offence_ids": [t for t in targets if t in off_ids],
|
| 174 |
+
"verdict_ids": [t for t in targets if t in ver_ids], "unresolved_ids": unresolved})
|
| 175 |
+
pun_rows = {}
|
| 176 |
+
for d_id in def_ids: # deterministic: defendant source order
|
| 177 |
+
for res, targets in by_member.get(d_id, []):
|
| 178 |
+
if res != "defendantPunishment": continue
|
| 179 |
+
for t in targets:
|
| 180 |
+
if t in all_rs and all_rs[t][0].get("type") == "punishmentDescription":
|
| 181 |
+
row = pun_rows.setdefault(t, {**all_rs[t][1], "defendant_ids": [], "found_in": rs_div.get(t)})
|
| 182 |
+
if d_id not in row["defendant_ids"]: row["defendant_ids"].append(d_id)
|
| 183 |
+
if rs_div.get(t) not in (None, tid): stats["punishment_cross_trial"] += 1
|
| 184 |
+
for rs in div.iter("rs"): # every punishment whose text lives in this trial, with whatever defendants the joins name (possibly another trial's)
|
| 185 |
+
pid = rs.get("id")
|
| 186 |
+
if rs.get("type") == "punishmentDescription" and pid and pid not in pun_rows:
|
| 187 |
+
joined = [t for res, targets in by_member.get(pid, []) if res == "defendantPunishment" for t in targets if t != pid and t in all_pers]
|
| 188 |
+
pun_rows[pid] = {**parse_rs(rs), "defendant_ids": joined, "found_in": tid}
|
| 189 |
+
if not joined: stats["punishment_unjoined"] += 1
|
| 190 |
+
elif not any(j in def_set for j in joined): stats["punishment_text_here_defendant_elsewhere"] += 1
|
| 191 |
+
trials.append({
|
| 192 |
+
"trial_id": tid, "session_id": session_id, "date": di.get("date") or session_id[:8], "part": 1 if session_id[:8] <= "18341024" else 2,
|
| 193 |
+
"text": text_of(div), "xml": etree.tostring(div, encoding="unicode"), "n_defendants": len(def_ids), "persons": persons,
|
| 194 |
+
"offences": [{"id": o["id"], "category": o.get("offenceCategory"), "subcategory": o.get("offenceSubcategory"), "text": o["text"],
|
| 195 |
+
"crime_date": o["crime_date"], "place": o["place"], "victim_ids": o["victim_ids"]} for o in offences],
|
| 196 |
+
"verdicts": [{"id": v["id"], "category": v.get("verdictCategory"), "subcategory": v.get("verdictSubcategory"), "text": v["text"]} for v in verdicts],
|
| 197 |
+
"punishments": [{"id": p["id"], "category": p.get("punishmentCategory"), "subcategory": p.get("punishmentSubcategory"), "text": p["text"],
|
| 198 |
+
"defendant_ids": p["defendant_ids"], "found_in": p["found_in"]} for p in pun_rows.values()],
|
| 199 |
+
"charges": charges, "places": [text_of(x) for x in div.iter("placeName")],
|
| 200 |
+
"obo_url": f"https://www.oldbaileyonline.org/browse.jsp?div={tid}"})
|
| 201 |
+
stats["trials"] += 1
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def parse_oa(path):
|
| 205 |
+
root, raw_text = read_xml(path)
|
| 206 |
+
if root is None: stats["unparseable_oa"] += 1; return
|
| 207 |
+
_, _, all_pers, pers_el, _, _ = index_file(root)
|
| 208 |
+
div = root.find(".//div0"); di = interps(div) if div is not None else {}
|
| 209 |
+
body = root.find(".//body")
|
| 210 |
+
oas.append({"oa_id": path.stem, "date": di.get("date") or path.stem[2:10], "text": text_of(body) if body is not None else text_of(root), "xml": raw_text,
|
| 211 |
+
"persons": [all_pers[p.get("id")] if p.get("id") else parse_person(p) for p in pers_el],
|
| 212 |
+
"places": [text_of(x) for x in root.iter("placeName")], "obo_url": f"https://www.oldbaileyonline.org/browse.jsp?name={path.stem}"})
|
| 213 |
+
stats["oa"] += 1
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
files = sorted((ROOT / "sessionsPapers").glob("*.xml"))
|
| 217 |
+
if LIMIT: files = files[::max(1, len(files) // LIMIT)][:LIMIT]
|
| 218 |
+
for i, f in enumerate(files):
|
| 219 |
+
parse_session(f)
|
| 220 |
+
if i % 200 == 0: print(f"{i}/{len(files)} {f.name} trials so far {stats['trials']}", flush=True)
|
| 221 |
+
oa_files = sorted((ROOT / "ordinarysAccounts").glob("*.xml"))
|
| 222 |
+
if LIMIT: oa_files = oa_files[:max(2, LIMIT // 5)]
|
| 223 |
+
for f in oa_files: parse_oa(f)
|
| 224 |
+
|
| 225 |
+
used = set()
|
| 226 |
+
for t in trials: # source quirk: a few supplementary items share an id (e.g. s16980504-1) — suffix collision-safely and report
|
| 227 |
+
base = t["trial_id"]
|
| 228 |
+
if base in used:
|
| 229 |
+
k = 2
|
| 230 |
+
while f"{base}-dup{k}" in used: k += 1
|
| 231 |
+
t["trial_id"] = f"{base}-dup{k}"; stats["dup_trial_id"] += 1; warnings.append(f"duplicate trial id {base} -> {t['trial_id']}")
|
| 232 |
+
used.add(t["trial_id"])
|
| 233 |
+
|
| 234 |
+
PERSON = pl.Struct({"id": pl.Utf8, "type": pl.Utf8, "name": pl.Utf8, "given": pl.Utf8, "surname": pl.Utf8, "gender": pl.Utf8, "age": pl.Utf8,
|
| 235 |
+
"occupation": pl.Utf8, "place": pl.Utf8, "aliases": pl.List(pl.Utf8)})
|
| 236 |
+
SCHEMA = {
|
| 237 |
+
"trial_id": pl.Utf8, "session_id": pl.Utf8, "date": pl.Utf8, "part": pl.Int8, "text": pl.Utf8, "xml": pl.Utf8, "n_defendants": pl.Int32,
|
| 238 |
+
"persons": pl.List(PERSON),
|
| 239 |
+
"offences": pl.List(pl.Struct({"id": pl.Utf8, "category": pl.Utf8, "subcategory": pl.Utf8, "text": pl.Utf8, "crime_date": pl.Utf8, "place": pl.Utf8, "victim_ids": pl.List(pl.Utf8)})),
|
| 240 |
+
"verdicts": pl.List(pl.Struct({"id": pl.Utf8, "category": pl.Utf8, "subcategory": pl.Utf8, "text": pl.Utf8})),
|
| 241 |
+
"punishments": pl.List(pl.Struct({"id": pl.Utf8, "category": pl.Utf8, "subcategory": pl.Utf8, "text": pl.Utf8, "defendant_ids": pl.List(pl.Utf8), "found_in": pl.Utf8})),
|
| 242 |
+
"charges": pl.List(pl.Struct({"defendant_ids": pl.List(pl.Utf8), "offence_ids": pl.List(pl.Utf8), "verdict_ids": pl.List(pl.Utf8), "unresolved_ids": pl.List(pl.Utf8)})),
|
| 243 |
+
"places": pl.List(pl.Utf8), "obo_url": pl.Utf8,
|
| 244 |
+
}
|
| 245 |
+
df = pl.from_dicts(trials, schema=SCHEMA); assert df["trial_id"].n_unique() == df.height
|
| 246 |
+
df.write_parquet(OUT / "trials.parquet", compression="zstd")
|
| 247 |
+
oa = pl.from_dicts(oas, schema={"oa_id": pl.Utf8, "date": pl.Utf8, "text": pl.Utf8, "xml": pl.Utf8, "persons": pl.List(PERSON), "places": pl.List(pl.Utf8), "obo_url": pl.Utf8})
|
| 248 |
+
oa.write_parquet(OUT / "ordinarys_accounts.parquet", compression="zstd")
|
| 249 |
+
ses = pl.from_dicts(sessions, schema={"session_id": pl.Utf8, "date": pl.Utf8, "part": pl.Int8, "text": pl.Utf8, "xml": pl.Utf8, "n_trials": pl.Int32, "div_types": pl.Utf8,
|
| 250 |
+
"persons": pl.List(PERSON), "places": pl.List(pl.Utf8),
|
| 251 |
+
"summary_items": pl.List(pl.Struct({"id": pl.Utf8, "type": pl.Utf8, "category": pl.Utf8, "subcategory": pl.Utf8, "text": pl.Utf8, "found_in": pl.Utf8, "linked_ids": pl.List(pl.Utf8)})),
|
| 252 |
+
"obo_url": pl.Utf8})
|
| 253 |
+
ses.write_parquet(OUT / "sessions.parquet", compression="zstd")
|
| 254 |
+
print("\nwrote", df.shape, "trials;", ses.shape, "sessions;", oa.shape, "OA")
|
| 255 |
+
(OUT / "parse_warnings.txt").write_text("\n".join(warnings))
|
| 256 |
+
if warnings: print(f"{len(warnings)} parse warnings -> {OUT / 'parse_warnings.txt'}")
|
| 257 |
+
if STATS:
|
| 258 |
+
for k, v in sorted(stats.items()): print(f" {k:32s} {v}")
|
| 259 |
+
g = df.filter(pl.col("verdicts").list.eval(pl.element().struct.field("category") == "guilty").list.any())
|
| 260 |
+
print("guilty trials:", g.height, "| guilty with 0 punishments:", g.filter(pl.col("punishments").list.len() == 0).height)
|
| 261 |
+
print("trials with 0 offences:", df.filter(pl.col("offences").list.len() == 0).height, "| 0 charges:", df.filter(pl.col("charges").list.len() == 0).height,
|
| 262 |
+
"| punishments with no defendant:", df.explode("punishments").filter(pl.col("punishments").struct.field("defendant_ids").list.len() == 0).height)
|
data/train-00001-of-00002.parquet → sessions/train-00000-of-00006.parquet
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4551ba366ab3890d3bde1370053b312a38b34db9136995aebc9d20b403ba110f
|
| 3 |
+
size 15186765
|
sessions/train-00001-of-00006.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:eb237d2fdd0b8d2ab3655597ec580bea471c2a777142097d98a8a93833390bde
|
| 3 |
+
size 47803176
|
sessions/train-00002-of-00006.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d06a3d67f2c5d7ad76fff12e3fcc8d8d06171f0928f2bf81ebe3ec134ca63692
|
| 3 |
+
size 101858942
|
sessions/train-00003-of-00006.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6a2e664daae9a0f7e1d3ccd65999639254072b42c273669e32438c1f6bf48e33
|
| 3 |
+
size 167173049
|
sessions/train-00004-of-00006.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:74eae50f7f9fe817a7f537b57d0324c9859362e039ddb76c565a880727ef35de
|
| 3 |
+
size 106169184
|
sessions/train-00005-of-00006.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:401f347df6b68345d7918dfea34ef4aff7742baa50d64b28d5185721c6e6e5fd
|
| 3 |
+
size 101726630
|
trials/train-00000-of-00006.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2eedca50e5277bb6d2218ad972a0743ecaa5d13d92744463babb525d464839d3
|
| 3 |
+
size 57743360
|
trials/train-00001-of-00006.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:562f7c30dceb588b44581d0e1435c0d5dbac5017d372ae0ee58d3c1537cbb7e9
|
| 3 |
+
size 102484245
|
trials/train-00002-of-00006.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0e3bb17e70fd12e15929e92f462286ebec25bf224ce2c359109b9b1f4f09766e
|
| 3 |
+
size 72977789
|
trials/train-00003-of-00006.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c1dbc263b826b35fb69e45c0083a58cead914010067814693a8ee07f2cdd8ee1
|
| 3 |
+
size 74899894
|
trials/train-00004-of-00006.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9250a50e11396a8ca0057852b22c5e3cccbe06b811255c15c8b9c2c1f64584ae
|
| 3 |
+
size 105293938
|
trials/train-00005-of-00006.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4b63c9a5ac97aeb0acafeaf27139be43556c40986679a955aaa569e210dc25dd
|
| 3 |
+
size 133381765
|