Skip to content

Latest commit

 

History

History
55 lines (41 loc) · 1.53 KB

File metadata and controls

55 lines (41 loc) · 1.53 KB

fedlex-parser

Parser for Swiss federal law documents. Downloads official AkomaNtoso XML from fedlex.admin.ch and extracts structured articles with full heading context, ready for LLM pipelines.

Supported Laws

Key Name Articles
OR Obligationenrecht (Code of Obligations) ~1600
ZGB Zivilgesetzbuch (Civil Code) ~472
BV Bundesverfassung (Federal Constitution) ~232

Setup

python3 -m venv .swisslaw-llm
source .swisslaw-llm/bin/activate
pip install -r requirements.txt

Usage

from law_repo.law_repo import LawRepo
from parser.article_parser import parse_articles

xml = LawRepo.get_xml("OR")       # downloads & caches to raw/
articles = parse_articles(xml)

art = articles[0]
art.article_number  # "1"
art.paragraphs      # ["Zum Abschlusse eines Vertrages ...", ...]
art.context          # ["Erste Abteilung: Allgemeine Bestimmungen", ...]

Each Article contains:

  • article_number — e.g. "1", "17a"
  • paragraphs — list of paragraph texts (including list items and authorial notes for repealed articles)
  • context — heading hierarchy from outermost to innermost (part, title, chapter, section, ...)

Tests

python -m unittest discover -s test -p "test*.py" -v

Project Structure

model/          Article dataclass
parser/         XML parser (AkomaNtoso 3.0)
law_repo/       Download & cache layer
test/           Unit tests + fixtures
raw/            Cached XML files (gitignored)