Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Parser for Swiss federal law (OR, ZGB, BV) - extracts structured articles from official AkomaNtoso XML for LLM applications

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages