How najonghwa/safety-law-db works
Purpose and Deliverables
This repository builds a local SQLite, article-level search database for Korean safety and environmental regulations. It gathers laws, administrative notices, annexes, KOSHA guidance, and chemical-substance lists, then packages a Claude Code-facing search workspace. Primary target definitions are in laws.json; vocabulary normalization is in synonyms.json.
Pipeline Entry Points
The intended batch sequence is:
1. Collect legal texts: collector.py
2. Collect annexes and parse HWP/text: annex_collector.py
3. Collect KOSHA guidance and optionally PDFs: kosha_collector.py
4. Collect regulated-substance lists: substance_collector.py
5. Normalize and import into SQLite: importer.py
6. Audit generated data: verify_db.py
These are independent Python CLI stages, run manually on an internet-connected machine.
Source Acquisition Boundary
Collectors isolate external-source concerns from database construction:
• collector.py obtains legislation and notices from law.go.kr without an API key.
• annex_collector.py handles separately published annex content, including HWP extraction.
• kosha_collector.py consumes the data.go.kr KOSHA Guide service; a local kosha_config.json API key enables PDF retrieval.
• substance_collector.py imports chemical regulatory data from ICIS.
Optional binary parsing dependencies (pypdf, gethwp, olefile) affect annex/PDF completeness but not the basic legal-text pipeline.
Database Construction and Quality Gate
importer.py is the central integration boundary: it converts heterogeneous collector outputs into data/laws.db, performs legal-text parsing, extracts CAS identifiers, cleans problematic NULL characters, and chunks annex content for retrieval. verify_db.py is the required quality gate, comparing database content with source collection output for loss, omissions, and search spot checks—particularly important because HWP/PDF extraction can truncate content.
Search Distribution Runtime
dist/she-law-db/ is a self-contained consumer workspace rather than a build artifact to execute from the repository root. Its SQLite search CLI, dist/she-law-db/search_law.py, uses the generated database copied to dist/she-law-db/data/laws.db. It supports text, substance/CAS, and law-name lookup and is designed to run without application servers or LLM infrastructure.
Claude Code Integration Boundary
Claude Code behavior is constrained in the distributable workspace:
• dist/she-law-db/CLAUDE.md defines evidence-first response rules.
• dist/she-law-db/.claude/skills/she-law/SKILL.md defines the search skill.
• dist/she-law-db/search_law.py is the retrieval mechanism Claude invokes.
The integration requires cited source provisions; when retrieval yields no evidence, the intended behavior is to report that verification is unavailable rather than synthesize an answer.
Main entry points: collector.py Legal text collector · importer.py SQLite importer · kosha_collector.py KOSHA collector · substance_collector.py Substance collector
Components 17
Definitions
- Law targets · Primary target law definitions.
laws.json - Vocabulary normalization
synonyms.json
Source Collection
- law.go.kr · Public laws and administrative notices.
- KOSHA Guide API · Optional API-key-enabled PDF retrieval.
- ICIS
- Legal text collector
collector.py - Annex collector · Collects annexes and extracts HWP/text.
annex_collector.py - KOSHA collector · Collects guidance and optional PDFs.
kosha_collector.py - Substance collector
substance_collector.py
Database Build
- Collected source outputs · Intermediate legal, annex, guide, and substance content.
- SQLite importer · Parses, cleans, extracts CAS, and chunks annex retrieval content.
importer.py - Search database · Article-level Korean safety and environmental regulation index.
- Database audit · Checks loss, omissions, extraction completeness, and search results.
verify_db.py
Search Workspace
- Bundled database
- Search CLI · Text, substance/CAS, and law-name retrieval.
dist/she-law-db/search_law.py - Evidence rules · Requires cited provisions and unavailable-verification responses.
dist/she-law-db/CLAUDE.md - SHE law search skill
dist/she-law-db/.claude/skills/she-law/SKILL.md
Connections 17
- Law targets → Legal text collector: defines targets
- law.go.kr → Legal text collector: collects
- Legal text collector → Collected source outputs: legal texts
- Annex collector → Collected source outputs: annexes
- KOSHA Guide API → KOSHA collector: guidance and PDFs
- KOSHA collector → Collected source outputs: KOSHA content
- ICIS → Substance collector: regulatory lists
- Substance collector → Collected source outputs: substances
- Vocabulary normalization → SQLite importer: normalizes vocabulary
- Collected source outputs → SQLite importer: integrates
- SQLite importer → Search database: builds
- Collected source outputs → Database audit: compares sources
- Search database → Database audit: audits
- Search database → Bundled database: copies for distribution
- Bundled database → Search CLI: queries
- Evidence rules → SHE law search skill: constrains behavior
- SHE law search skill → Search CLI: invokes retrieval