Datasets:
Refresh/add Brunei official snapshot (92 laws)
Browse files- MANIFEST.md +15 -8
- README.md +26 -25
- data/articles.parquet +2 -2
- data/laws.parquet +2 -2
- scrapers/archive_fallbacks.py +57 -35
- scrapers/collect_bn.py +51 -3
- scrapers/common.py +27 -4
MANIFEST.md
CHANGED
|
@@ -1,9 +1,16 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ipfs_brunei_laws manifest
|
| 2 |
|
| 3 |
+
generated_utc: 2026-09-08T22:53:36Z
|
| 4 |
+
cc: bn
|
| 5 |
+
laws_rows: 92
|
| 6 |
+
articles_rows: 354
|
| 7 |
+
laws_bytes: 1146003
|
| 8 |
+
articles_bytes: 886893
|
| 9 |
+
laws_sha256: e5abc1745c4caa9175801e10793092f267194f7a1312046b0b92068090d2ce71
|
| 10 |
+
articles_sha256: 3f34177b4bb9cb11451814f0abeb88fbeb1133d9d1011c7e1b68ccf71b8bd901
|
| 11 |
+
compression: zstd
|
| 12 |
+
live_count: 92
|
| 13 |
+
archive_count: 0
|
| 14 |
+
collector: scrapers/collect_bn.py
|
| 15 |
+
license: Laws of Brunei / AGC official texts prevail. Not legal advice.
|
| 16 |
+
uploaded: false
|
README.md
CHANGED
|
@@ -1,15 +1,17 @@
|
|
| 1 |
---
|
| 2 |
-
pretty_name: Laws
|
| 3 |
license: other
|
| 4 |
-
license_name: bn-agc-
|
| 5 |
language:
|
| 6 |
- en
|
|
|
|
| 7 |
task_categories:
|
| 8 |
- text-retrieval
|
| 9 |
tags:
|
| 10 |
- legal
|
| 11 |
- law
|
| 12 |
- brunei
|
|
|
|
| 13 |
- official-texts
|
| 14 |
size_categories:
|
| 15 |
- n<1K
|
|
@@ -21,44 +23,43 @@ configs:
|
|
| 21 |
data_files: data/articles.parquet
|
| 22 |
---
|
| 23 |
|
| 24 |
-
# Laws
|
| 25 |
|
| 26 |
-
Research snapshot of
|
| 27 |
|
| 28 |
-
**Not legal advice.**
|
|
|
|
| 29 |
|
| 30 |
## Snapshot
|
| 31 |
|
| 32 |
| Field | Value |
|
| 33 |
| --- | --- |
|
| 34 |
-
| Snapshot date | 2026-09-
|
| 35 |
-
|
|
| 36 |
-
| Source | AGC Laws of Brunei |
|
| 37 |
| Collector | `scrapers/collect_bn.py` |
|
| 38 |
-
| Laws / instruments |
|
| 39 |
-
| Articles |
|
| 40 |
-
| Language | en |
|
| 41 |
-
|
|
| 42 |
-
| License | `bn-agc-laws` |
|
| 43 |
|
| 44 |
## Contents
|
| 45 |
|
| 46 |
-
- `data/laws.parquet` — one row per instrument (
|
| 47 |
-
- `data/articles.parquet` —
|
| 48 |
- `scrapers/collect_bn.py` — research collector used to build this snapshot.
|
| 49 |
-
- `scrapers/common.py` — shared collector helpers.
|
| 50 |
-
- `scrapers/world_lib.py` — shared fetch (live official URL, Wayback fallback).
|
| 51 |
-
- `scrapers/archive_fallbacks.py` — Wayback / Common Crawl CDX helpers.
|
| 52 |
|
| 53 |
## License / reuse
|
| 54 |
|
| 55 |
-
|
| 56 |
-
source portal. This packaging, metadata, and collector script are provided
|
| 57 |
-
for research.
|
| 58 |
|
| 59 |
-
This dataset is **not**
|
| 60 |
-
The official source prevails.
|
| 61 |
|
| 62 |
-
##
|
| 63 |
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
pretty_name: Brunei Laws (AGC / agc.gov.bn)
|
| 3 |
license: other
|
| 4 |
+
license_name: bn-agc-official-texts
|
| 5 |
language:
|
| 6 |
- en
|
| 7 |
+
- ms
|
| 8 |
task_categories:
|
| 9 |
- text-retrieval
|
| 10 |
tags:
|
| 11 |
- legal
|
| 12 |
- law
|
| 13 |
- brunei
|
| 14 |
+
- agc
|
| 15 |
- official-texts
|
| 16 |
size_categories:
|
| 17 |
- n<1K
|
|
|
|
| 23 |
data_files: data/articles.parquet
|
| 24 |
---
|
| 25 |
|
| 26 |
+
# Brunei Laws (AGC / agc.gov.bn)
|
| 27 |
|
| 28 |
+
Research snapshot of **national legislation** from official sources listed below.
|
| 29 |
|
| 30 |
+
**Not legal advice.** The official gazette / authentic text of the jurisdiction
|
| 31 |
+
prevails over this corpus.
|
| 32 |
|
| 33 |
## Snapshot
|
| 34 |
|
| 35 |
| Field | Value |
|
| 36 |
| --- | --- |
|
| 37 |
+
| Snapshot date | 2026-09-02 |
|
| 38 |
+
| Source | Attorney General's Chambers — Laws of Brunei (agc.gov.bn) |
|
|
|
|
| 39 |
| Collector | `scrapers/collect_bn.py` |
|
| 40 |
+
| Laws / instruments | 92 |
|
| 41 |
+
| Articles | 354 |
|
| 42 |
+
| Language | en, ms |
|
| 43 |
+
| License | `bn-agc-official-texts` |
|
|
|
|
| 44 |
|
| 45 |
## Contents
|
| 46 |
|
| 47 |
+
- `data/laws.parquet` — one row per instrument (zstd).
|
| 48 |
+
- `data/articles.parquet` — article/section rows for the same snapshot.
|
| 49 |
- `scrapers/collect_bn.py` — research collector used to build this snapshot.
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
## License / reuse
|
| 52 |
|
| 53 |
+
Laws of Brunei / AGC official texts prevail. Not legal advice.
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
This dataset is **not legal advice**. The official gazette prevails.
|
|
|
|
| 56 |
|
| 57 |
+
## Source
|
| 58 |
|
| 59 |
+
- https://www.agc.gov.bn/
|
| 60 |
+
- https://agc.gov.bn/
|
| 61 |
+
|
| 62 |
+
## Known gaps
|
| 63 |
+
|
| 64 |
+
- Incomplete vs full AGC corpus.
|
| 65 |
+
- Markup PDF variants skipped.
|
data/articles.parquet
CHANGED
|
@@ -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:3f34177b4bb9cb11451814f0abeb88fbeb1133d9d1011c7e1b68ccf71b8bd901
|
| 3 |
+
size 886893
|
data/laws.parquet
CHANGED
|
@@ -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:e5abc1745c4caa9175801e10793092f267194f7a1312046b0b92068090d2ce71
|
| 3 |
+
size 1146003
|
scrapers/archive_fallbacks.py
CHANGED
|
@@ -24,8 +24,10 @@ from requests.adapters import HTTPAdapter
|
|
| 24 |
|
| 25 |
log = logging.getLogger("archive_fallbacks")
|
| 26 |
|
| 27 |
-
WAYBACK_CDX = "
|
| 28 |
-
WAYBACK_WEB = "
|
|
|
|
|
|
|
| 29 |
CC_COLLINFO = "https://index.commoncrawl.org/collinfo.json"
|
| 30 |
CC_DATA = "https://data.commoncrawl.org"
|
| 31 |
ARCHIVE_IS_NEWEST = "https://archive.is/newest/"
|
|
@@ -207,7 +209,10 @@ def _wayback_cdx_page(
|
|
| 207 |
items = [(k, psz if k == "limit" else v) for k, v in items]
|
| 208 |
_sleep_wayback(1.5)
|
| 209 |
try:
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
| 211 |
except requests.RequestException as exc:
|
| 212 |
last_err = exc
|
| 213 |
log.warning("wayback cdx fail %s: %s", url, exc)
|
|
@@ -283,22 +288,27 @@ def search_wayback_machine(
|
|
| 283 |
|
| 284 |
|
| 285 |
def get_wayback_content(url: str, timestamp: Optional[str] = None) -> dict:
|
| 286 |
-
"""Fetch a snapshot; id_ modifier skips Wayback chrome. No CDX search.
|
|
|
|
|
|
|
|
|
|
| 287 |
if timestamp:
|
| 288 |
-
|
| 289 |
else:
|
| 290 |
-
|
| 291 |
r = None
|
| 292 |
last_err = None
|
| 293 |
-
|
| 294 |
-
|
|
|
|
|
|
|
| 295 |
try:
|
| 296 |
-
r = session().get(
|
| 297 |
except requests.RequestException as exc:
|
| 298 |
last_err = str(exc)
|
| 299 |
log.info("wayback replay fail %s: %s", url, exc)
|
| 300 |
continue
|
| 301 |
-
if r.status_code in (403, 429, 503, 502, 504) and attempt <
|
| 302 |
log.info("wayback replay HTTP %s %s attempt=%s", r.status_code, url, attempt)
|
| 303 |
continue
|
| 304 |
break
|
|
@@ -349,32 +359,40 @@ def get_wayback_content(url: str, timestamp: Optional[str] = None) -> dict:
|
|
| 349 |
|
| 350 |
# --- Common Crawl ---
|
| 351 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 352 |
def cc_indexes(n: int = 6) -> list[str]:
|
| 353 |
global _cc_indexes
|
| 354 |
if _cc_indexes is None:
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
|
|
|
|
|
|
| 378 |
return _cc_indexes[:n]
|
| 379 |
|
| 380 |
|
|
@@ -400,8 +418,12 @@ def search_common_crawl(url: str, *, limit: int = 80, indexes: Optional[list[str
|
|
| 400 |
try:
|
| 401 |
r = session().get(idx, params=params, timeout=(12, 25))
|
| 402 |
except requests.RequestException as exc:
|
| 403 |
-
|
| 404 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
if r.status_code == 404:
|
| 406 |
msg = (r.text or "")[:80]
|
| 407 |
log.info("cc cdx no-captures %s %s", idx.split("/")[-1], msg)
|
|
|
|
| 24 |
|
| 25 |
log = logging.getLogger("archive_fallbacks")
|
| 26 |
|
| 27 |
+
WAYBACK_CDX = "https://web.archive.org/cdx/search/cdx"
|
| 28 |
+
WAYBACK_WEB = "https://web.archive.org/web"
|
| 29 |
+
WAYBACK_CDX_HTTP = "http://web.archive.org/cdx/search/cdx"
|
| 30 |
+
WAYBACK_WEB_HTTP = "http://web.archive.org/web"
|
| 31 |
CC_COLLINFO = "https://index.commoncrawl.org/collinfo.json"
|
| 32 |
CC_DATA = "https://data.commoncrawl.org"
|
| 33 |
ARCHIVE_IS_NEWEST = "https://archive.is/newest/"
|
|
|
|
| 209 |
items = [(k, psz if k == "limit" else v) for k, v in items]
|
| 210 |
_sleep_wayback(1.5)
|
| 211 |
try:
|
| 212 |
+
try:
|
| 213 |
+
r = session().get(WAYBACK_CDX, params=items, timeout=(20, 90))
|
| 214 |
+
except requests.RequestException:
|
| 215 |
+
r = session().get(WAYBACK_CDX_HTTP, params=items, timeout=(20, 90))
|
| 216 |
except requests.RequestException as exc:
|
| 217 |
last_err = exc
|
| 218 |
log.warning("wayback cdx fail %s: %s", url, exc)
|
|
|
|
| 288 |
|
| 289 |
|
| 290 |
def get_wayback_content(url: str, timestamp: Optional[str] = None) -> dict:
|
| 291 |
+
"""Fetch a snapshot; id_ modifier skips Wayback chrome. No CDX search.
|
| 292 |
+
|
| 293 |
+
Prefer HTTP Wayback; HTTPS Wayback SSL-EOFs from this host (same as VN VBPL).
|
| 294 |
+
"""
|
| 295 |
if timestamp:
|
| 296 |
+
path = f"/{timestamp}id_/{url}"
|
| 297 |
else:
|
| 298 |
+
path = f"/2id_/{url}"
|
| 299 |
r = None
|
| 300 |
last_err = None
|
| 301 |
+
candidates = [WAYBACK_WEB_HTTP + path, WAYBACK_WEB + path]
|
| 302 |
+
for attempt in range(1, 4):
|
| 303 |
+
target = candidates[min(attempt-1, len(candidates)-1)]
|
| 304 |
+
_sleep_wayback(0.8 if attempt == 1 else min(8.0, 1.8 * attempt))
|
| 305 |
try:
|
| 306 |
+
r = session().get(target, timeout=(20, 90), allow_redirects=True)
|
| 307 |
except requests.RequestException as exc:
|
| 308 |
last_err = str(exc)
|
| 309 |
log.info("wayback replay fail %s: %s", url, exc)
|
| 310 |
continue
|
| 311 |
+
if r.status_code in (403, 429, 503, 502, 504) and attempt < 3:
|
| 312 |
log.info("wayback replay HTTP %s %s attempt=%s", r.status_code, url, attempt)
|
| 313 |
continue
|
| 314 |
break
|
|
|
|
| 359 |
|
| 360 |
# --- Common Crawl ---
|
| 361 |
|
| 362 |
+
def _http_cc_index(url: str) -> str:
|
| 363 |
+
if url.startswith("https://index.commoncrawl.org"):
|
| 364 |
+
return "http://" + url[len("https://"):]
|
| 365 |
+
return url
|
| 366 |
+
|
| 367 |
+
|
| 368 |
def cc_indexes(n: int = 6) -> list[str]:
|
| 369 |
global _cc_indexes
|
| 370 |
if _cc_indexes is None:
|
| 371 |
+
cols = []
|
| 372 |
+
last_exc = None
|
| 373 |
+
for coll in (CC_COLLINFO, CC_COLLINFO.replace("https://", "http://", 1)):
|
| 374 |
+
try:
|
| 375 |
+
r = session().get(coll, timeout=30)
|
| 376 |
+
if r.status_code == 200:
|
| 377 |
+
cols = r.json() or []
|
| 378 |
+
break
|
| 379 |
+
except Exception as exc:
|
| 380 |
+
last_exc = exc
|
| 381 |
+
log.warning("cc collinfo %s: %s", coll, exc)
|
| 382 |
+
ids = []
|
| 383 |
+
for c in cols:
|
| 384 |
+
cid = c.get("id") or ""
|
| 385 |
+
cdx = c.get("cdx-api") or c.get("cdx_api") or ""
|
| 386 |
+
if cid:
|
| 387 |
+
ids.append(_http_cc_index(cdx or f"http://index.commoncrawl.org/{cid}-index"))
|
| 388 |
+
# collinfo is newest-first. Do not drop crawls that 404 a
|
| 389 |
+
# specific URL (that means "no captures", not a dead index).
|
| 390 |
+
_cc_indexes = ids or [
|
| 391 |
+
"http://index.commoncrawl.org/CC-MAIN-2026-34-index",
|
| 392 |
+
"http://index.commoncrawl.org/CC-MAIN-2024-33-index",
|
| 393 |
+
]
|
| 394 |
+
if last_exc and not ids:
|
| 395 |
+
log.warning("cc collinfo fallback indexes after %s", last_exc)
|
| 396 |
return _cc_indexes[:n]
|
| 397 |
|
| 398 |
|
|
|
|
| 418 |
try:
|
| 419 |
r = session().get(idx, params=params, timeout=(12, 25))
|
| 420 |
except requests.RequestException as exc:
|
| 421 |
+
alt = _http_cc_index(idx) if idx.startswith("https://") else idx.replace("http://", "https://", 1)
|
| 422 |
+
try:
|
| 423 |
+
r = session().get(alt, params=params, timeout=(12, 25))
|
| 424 |
+
except requests.RequestException as exc2:
|
| 425 |
+
log.info("cc cdx %s fail %s / %s", idx, exc, exc2)
|
| 426 |
+
continue
|
| 427 |
if r.status_code == 404:
|
| 428 |
msg = (r.text or "")[:80]
|
| 429 |
log.info("cc cdx no-captures %s %s", idx.split("/")[-1], msg)
|
scrapers/collect_bn.py
CHANGED
|
@@ -19,6 +19,44 @@ ART = re.compile(r"(?im)^\s*((?:Section|Article|Art\.?)\s+[0-9]+)\b")
|
|
| 19 |
log = logging.getLogger("bn")
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def discover():
|
| 23 |
items, seen = [], set()
|
| 24 |
def add(url):
|
|
@@ -45,11 +83,21 @@ def discover():
|
|
| 45 |
"www.agc.gov.bn/agc%20images/laws/",
|
| 46 |
"www.agc.gov.bn/AGC Images/LAWS/",
|
| 47 |
):
|
| 48 |
-
for h in cdx_urls(prefix, limit=env_int("CDX_LIMIT",
|
| 49 |
extra_filters=["mimetype:application/pdf"]):
|
| 50 |
orig = h.get("original") or ""
|
| 51 |
if orig:
|
| 52 |
add(orig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
log.info("catalog %s", len(items))
|
| 54 |
return items
|
| 55 |
|
|
@@ -57,8 +105,8 @@ def discover():
|
|
| 57 |
def main():
|
| 58 |
setup_log(CC)
|
| 59 |
t0 = utcnow()
|
| 60 |
-
max_new = env_int("MAX_NEW",
|
| 61 |
-
max_seconds = env_int("MAX_SECONDS",
|
| 62 |
t_start = time.time()
|
| 63 |
done = existing_ids(CC)
|
| 64 |
ok = skip = fail = 0
|
|
|
|
| 19 |
log = logging.getLogger("bn")
|
| 20 |
|
| 21 |
|
| 22 |
+
def load_prior_catalog(seen: set) -> list:
|
| 23 |
+
"""Resume from raw/catalog.jsonl, index.jsonl, or instrument source_urls when CDX fails."""
|
| 24 |
+
import json
|
| 25 |
+
from common import ROOT
|
| 26 |
+
items = []
|
| 27 |
+
def add_pair(ident, url):
|
| 28 |
+
if not url or url in seen:
|
| 29 |
+
return
|
| 30 |
+
seen.add(url)
|
| 31 |
+
items.append((ident or Path(url.split("?")[0]).stem[:160], url))
|
| 32 |
+
cat = ROOT / "bn" / "raw" / "catalog.jsonl"
|
| 33 |
+
if cat.exists():
|
| 34 |
+
for line in cat.open(encoding="utf-8"):
|
| 35 |
+
try:
|
| 36 |
+
row = json.loads(line)
|
| 37 |
+
except Exception:
|
| 38 |
+
continue
|
| 39 |
+
add_pair(row.get("ident") or row.get("identifier"), row.get("url") or row.get("source_url"))
|
| 40 |
+
idx = ROOT / "bn" / "index.jsonl"
|
| 41 |
+
if idx.exists():
|
| 42 |
+
for line in idx.open(encoding="utf-8"):
|
| 43 |
+
try:
|
| 44 |
+
row = json.loads(line)
|
| 45 |
+
except Exception:
|
| 46 |
+
continue
|
| 47 |
+
add_pair(row.get("identifier") or row.get("id"), row.get("source_url") or row.get("url"))
|
| 48 |
+
inst = ROOT / "bn" / "instruments"
|
| 49 |
+
if inst.exists():
|
| 50 |
+
for jp in inst.glob("*.json"):
|
| 51 |
+
try:
|
| 52 |
+
row = json.loads(jp.read_text(encoding="utf-8"))
|
| 53 |
+
except Exception:
|
| 54 |
+
continue
|
| 55 |
+
add_pair(row.get("official_identifier") or row.get("identifier") or jp.stem,
|
| 56 |
+
row.get("source_url") or (row.get("metadata") or {}).get("source_url"))
|
| 57 |
+
return items
|
| 58 |
+
|
| 59 |
+
|
| 60 |
def discover():
|
| 61 |
items, seen = [], set()
|
| 62 |
def add(url):
|
|
|
|
| 83 |
"www.agc.gov.bn/agc%20images/laws/",
|
| 84 |
"www.agc.gov.bn/AGC Images/LAWS/",
|
| 85 |
):
|
| 86 |
+
for h in cdx_urls(prefix, limit=env_int("CDX_LIMIT", 1200), match_type="prefix",
|
| 87 |
extra_filters=["mimetype:application/pdf"]):
|
| 88 |
orig = h.get("original") or ""
|
| 89 |
if orig:
|
| 90 |
add(orig)
|
| 91 |
+
if not items:
|
| 92 |
+
items = load_prior_catalog(seen)
|
| 93 |
+
log.info("cdx empty — reused prior catalog %s", len(items))
|
| 94 |
+
else:
|
| 95 |
+
# persist for idempotent resume when CDX is flaky
|
| 96 |
+
cat = Path(__file__).resolve().parents[1] / "bn" / "raw" / "catalog.jsonl"
|
| 97 |
+
cat.parent.mkdir(parents=True, exist_ok=True)
|
| 98 |
+
with cat.open("w", encoding="utf-8") as f:
|
| 99 |
+
for ident, url in items:
|
| 100 |
+
f.write(__import__("json").dumps({"ident": ident, "url": url}, ensure_ascii=False) + "\n")
|
| 101 |
log.info("catalog %s", len(items))
|
| 102 |
return items
|
| 103 |
|
|
|
|
| 105 |
def main():
|
| 106 |
setup_log(CC)
|
| 107 |
t0 = utcnow()
|
| 108 |
+
max_new = env_int("MAX_NEW", 400)
|
| 109 |
+
max_seconds = env_int("MAX_SECONDS", 7200)
|
| 110 |
t_start = time.time()
|
| 111 |
done = existing_ids(CC)
|
| 112 |
ok = skip = fail = 0
|
scrapers/common.py
CHANGED
|
@@ -234,13 +234,11 @@ def xml_to_text(raw: str, skip_tags: Optional[set[str]] = None) -> str:
|
|
| 234 |
|
| 235 |
ARTICLE_SPLIT = re.compile(
|
| 236 |
r"(?im)^\s*((?:art(?:icle|ikel|\.)|§|článek|článok|član|artikkel|articolo|"
|
| 237 |
-
r"artigo|artículo|artykuł|art\.
|
| 238 |
-
r"
|
| 239 |
-
r"[\dIVXLCDMΑ-Ω]+[a-zA-ZΑ-Ωa-z]?)\b"
|
| 240 |
)
|
| 241 |
|
| 242 |
|
| 243 |
-
|
| 244 |
def split_articles(text: str, law_id: str, source_url: str, date: Optional[str] = None) -> list[dict]:
|
| 245 |
if not text or len(text) < 40:
|
| 246 |
return []
|
|
@@ -506,3 +504,28 @@ def iso_date(val: Optional[str]) -> Optional[str]:
|
|
| 506 |
if m:
|
| 507 |
return f"{m.group(3)}-{m.group(2)}-{m.group(1)}"
|
| 508 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
|
| 235 |
ARTICLE_SPLIT = re.compile(
|
| 236 |
r"(?im)^\s*((?:art(?:icle|ikel|\.)|§|článek|článok|član|artikkel|articolo|"
|
| 237 |
+
r"artigo|artículo|artykuł|art\.|str\.|para(?:graph)?\.?|szakasz)\s+"
|
| 238 |
+
r"[\dIVXLCDM]+[a-zA-Z]?)\b"
|
|
|
|
| 239 |
)
|
| 240 |
|
| 241 |
|
|
|
|
| 242 |
def split_articles(text: str, law_id: str, source_url: str, date: Optional[str] = None) -> list[dict]:
|
| 243 |
if not text or len(text) < 40:
|
| 244 |
return []
|
|
|
|
| 504 |
if m:
|
| 505 |
return f"{m.group(3)}-{m.group(2)}-{m.group(1)}"
|
| 506 |
return None
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
def pdf_bytes_to_text(raw: bytes, timeout: int = 180) -> str:
|
| 510 |
+
"""Extract text from PDF bytes via pdftotext. Empty on failure."""
|
| 511 |
+
import subprocess
|
| 512 |
+
if not raw:
|
| 513 |
+
return ""
|
| 514 |
+
if raw[:4] != b"%PDF":
|
| 515 |
+
idx = raw.find(b"%PDF", 0, 8192)
|
| 516 |
+
if idx < 0:
|
| 517 |
+
return ""
|
| 518 |
+
raw = raw[idx:]
|
| 519 |
+
try:
|
| 520 |
+
with tempfile.NamedTemporaryFile(suffix=".pdf", delete=True) as tmp:
|
| 521 |
+
tmp.write(raw)
|
| 522 |
+
tmp.flush()
|
| 523 |
+
proc = subprocess.run(
|
| 524 |
+
["pdftotext", "-layout", "-enc", "UTF-8", tmp.name, "-"],
|
| 525 |
+
check=False, capture_output=True, timeout=timeout,
|
| 526 |
+
)
|
| 527 |
+
if proc.returncode == 0 and proc.stdout:
|
| 528 |
+
return proc.stdout.decode("utf-8", "replace").strip()
|
| 529 |
+
except Exception:
|
| 530 |
+
return ""
|
| 531 |
+
return ""
|