feat: initial text-deontic-extract v0.1.0 (text.deontic_extract@0.1.0)
Regex-based extraction of atomic deontic statements (Pflicht,
Verbot, Erlaubnis) from German legal text. Reuse-lens: contracts,
ISO standards, internal policies. Vorbild: Mercatus QuantGov /
RegData.
Pattern coverage in v0.1.0:
- OBLIGATION: muss, hat zu, ist verpflichtet, ist anzuzeigen,
aufzuzeichnen, muss eingehalten/geführt/...
- PROHIBITION: darf nicht, dürfen nicht, ist untersagt, verboten
- PERMISSION: kann, können, darf
Each emitted Duty carries a confidence ∈ [0, 1]. Pattern hits
default to 0.85; ambiguous structures (bare "kann") drop to 0.70.
Anything below 0.6 is the surrounding flow's signal to re-run
through llm.chat for human-readable refinement and feed the result
to system.approval@^0 — that keeps deterministic extraction
separate from non-deterministic LLM judgment.
Pure in-WASM (regex), zero filesystem, zero network.
Reserved for next versions:
- 0.2: EN / FR locale variants
- 0.3: addressee + frequency + authority detection (Phase 1
relies on flow-side LLM enrichment for those fields)
Signed-off-by: flemming-it <sf@flemming.it>
This commit is contained in:
commit
7dcdf7679f
6 changed files with 769 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
target/
|
||||
**/*.rs.bk
|
||||
.DS_Store
|
||||
482
Cargo.lock
generated
Normal file
482
Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,482 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.102"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "chain-module-sdk"
|
||||
version = "0.1.2"
|
||||
source = "git+https://git.flemming.ai/fai/chain-module-sdk-rust.git?branch=main#98e98e9371f7409560a1ef08bc0923d9a2506449"
|
||||
dependencies = [
|
||||
"chain-module-sdk-macros",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chain-module-sdk-macros"
|
||||
version = "0.1.2"
|
||||
source = "git+https://git.flemming.ai/fai/chain-module-sdk-rust.git?branch=main#98e98e9371f7409560a1ef08bc0923d9a2506449"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "id-arena"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.17.1",
|
||||
"serde",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "leb128"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c83bff1d572d6b9aeef67ddfc8448e4a3737909cb28e81f97c791b9018703e52"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "953f07c43838f8e6f9758cab68bf5bed85465e7587ebe0b823f1bcd81978ad3a"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||
|
||||
[[package]]
|
||||
name = "prettyplease"
|
||||
version = "0.2.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.12.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1292b7759ae1cb9ec195452d1390a074f0cd8541ab7a5a8c31cd6db45d4a6ba"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.150"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.15.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90"
|
||||
|
||||
[[package]]
|
||||
name = "spdx"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3e17e880bafaeb362a7b751ec46bdc5b61445a188f80e0606e68167cd540fa3"
|
||||
dependencies = [
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "text_deontic_extract"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chain-module-sdk",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-encoder"
|
||||
version = "0.220.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e913f9242315ca39eff82aee0e19ee7a372155717ff0eb082c741e435ce25ed1"
|
||||
dependencies = [
|
||||
"leb128",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-metadata"
|
||||
version = "0.220.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "185dfcd27fa5db2e6a23906b54c28199935f71d9a27a1a27b3a88d6fee2afae7"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"spdx",
|
||||
"wasm-encoder",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.220.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d07b6a3b550fefa1a914b6d54fc175dd11c3392da11eee604e6ffc759805d25"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bitflags",
|
||||
"hashbrown 0.14.5",
|
||||
"indexmap",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.36.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a2b3e15cd6068f233926e7d8c7c588b2ec4fb7cc7bf3824115e7c7e2a8485a3"
|
||||
dependencies = [
|
||||
"wit-bindgen-rt",
|
||||
"wit-bindgen-rust-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-core"
|
||||
version = "0.36.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b632a5a0fa2409489bd49c9e6d99fcc61bb3d4ce9d1907d44662e75a28c71172"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rt"
|
||||
version = "0.36.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7947d0131c7c9da3f01dfde0ab8bd4c4cf3c5bd49b6dba0ae640f1fa752572ea"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust"
|
||||
version = "0.36.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4329de4186ee30e2ef30a0533f9b3c123c019a237a7c82d692807bf1b3ee2697"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"indexmap",
|
||||
"prettyplease",
|
||||
"syn",
|
||||
"wasm-metadata",
|
||||
"wit-bindgen-core",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust-macro"
|
||||
version = "0.36.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "177fb7ee1484d113b4792cc480b1ba57664bbc951b42a4beebe573502135b1fc"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wit-bindgen-core",
|
||||
"wit-bindgen-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-component"
|
||||
version = "0.220.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b505603761ed400c90ed30261f44a768317348e49f1864e82ecdc3b2744e5627"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bitflags",
|
||||
"indexmap",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"wasm-encoder",
|
||||
"wasm-metadata",
|
||||
"wasmparser",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-parser"
|
||||
version = "0.220.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae2a7999ed18efe59be8de2db9cb2b7f84d88b27818c79353dfc53131840fe1a"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"id-arena",
|
||||
"indexmap",
|
||||
"log",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"unicode-xid",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.52"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce1022995ff5ff5d841ad7d994facc23098cd40152f2c1d11cd607c6f530653f"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.52"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ae7f38b72ec2a254e2b87ef277cf2cd4fb97cbebf944faa6f33354da0867930"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
|
||||
40
Cargo.toml
Normal file
40
Cargo.toml
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
[package]
|
||||
name = "text_deontic_extract"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
authors = ["Dr. Stefan Flemming <chain@flemming.ai>"]
|
||||
license = "Apache-2.0"
|
||||
publish = false
|
||||
description = "F∆I module — extract atomic deontic statements (Pflicht/Verbot/Erlaubnis) from normalised legal text"
|
||||
repository = "https://git.flemming.ws/chain-modules/text-deontic-extract"
|
||||
rust-version = "1.85"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
chain-module-sdk = { git = "https://git.flemming.ai/fai/chain-module-sdk-rust.git", branch = "main" }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
regex = "1"
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1"
|
||||
|
||||
[profile.release]
|
||||
opt-level = "s"
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
strip = "symbols"
|
||||
|
||||
[lints.rust]
|
||||
unsafe_op_in_unsafe_fn = "warn"
|
||||
|
||||
[lints.clippy]
|
||||
unwrap_used = "deny"
|
||||
expect_used = "deny"
|
||||
panic = "deny"
|
||||
print_stdout = "deny"
|
||||
print_stderr = "deny"
|
||||
|
||||
[workspace]
|
||||
40
module.yaml
Normal file
40
module.yaml
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
schema_version: 3
|
||||
provider: chain
|
||||
name: text-deontic-extract
|
||||
version: 0.1.0
|
||||
|
||||
# Extracts atomic deontic statements (Pflicht / Verbot /
|
||||
# Erlaubnis) from a normalised norm. Reuse-lens: useful far
|
||||
# beyond law — contracts, ISO standards, internal policies.
|
||||
#
|
||||
# v0.1.0 ships a regex pattern list for German legal text
|
||||
# (must / hat zu / ist verpflichtet / darf nicht / kann). Hybrid
|
||||
# LLM-assist happens in the FLOW via a separate llm.chat step
|
||||
# that this module's output feeds. Keeping LLM out of the module
|
||||
# preserves determinism + tier markings.
|
||||
#
|
||||
# Vorbild: Mercatus QuantGov / RegData (US).
|
||||
provides:
|
||||
- capability: text.deontic_extract
|
||||
version: 0.1.0
|
||||
|
||||
inputs:
|
||||
norm:
|
||||
type: json
|
||||
description:
|
||||
en: NormalizedNorm (output of text.akoma_normalize).
|
||||
de: NormalizedNorm (Output von text.akoma_normalize).
|
||||
|
||||
outputs:
|
||||
duties:
|
||||
type: json
|
||||
description:
|
||||
en: |
|
||||
JSON-encoded { duties: [Duty], confidence: 0..1 }.
|
||||
Each Duty: { modality, addressee, action, frequency,
|
||||
source_norm, confidence }. Low confidence (<0.6) flags
|
||||
an LLM-assist round; the surrounding flow handles it.
|
||||
de: |
|
||||
JSON-codiertes { duties: [Duty], confidence: 0..1 }.
|
||||
|
||||
permissions: []
|
||||
4
rust-toolchain.toml
Normal file
4
rust-toolchain.toml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[toolchain]
|
||||
channel = "1.86"
|
||||
targets = ["wasm32-wasip2"]
|
||||
components = ["rustfmt", "clippy"]
|
||||
200
src/lib.rs
Normal file
200
src/lib.rs
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
//! `text.deontic_extract` — regex-based duty extraction from
|
||||
//! German legal text.
|
||||
//!
|
||||
//! Reuse-lens: same shape for contracts (AGB), ISO standards,
|
||||
//! internal policies. The pattern list is German-language; an
|
||||
//! `EN`-/`FR`-locale variant is a 0.2 task.
|
||||
//!
|
||||
//! Vorbild: Mercatus QuantGov / RegData.
|
||||
//!
|
||||
//! # Confidence
|
||||
//!
|
||||
//! Each Duty carries `confidence ∈ [0, 1]`. Pattern hits get
|
||||
//! 0.85; ambiguous structures get 0.5. Anything below 0.6 the
|
||||
//! surrounding flow re-runs through `llm.chat` for human-readable
|
||||
//! refinement, then back through a Juristen-approval step.
|
||||
|
||||
#![allow(clippy::result_large_err)]
|
||||
|
||||
use chain_module_sdk::prelude::*;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct InputNorm {
|
||||
eli: Option<String>,
|
||||
jurabk: Option<String>,
|
||||
paragraph: Option<String>,
|
||||
paragraphs: Vec<InputParagraph>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct InputParagraph {
|
||||
number: String,
|
||||
text: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct Duty {
|
||||
modality: &'static str,
|
||||
action: String,
|
||||
source_norm: String,
|
||||
paragraph: String,
|
||||
confidence: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct Output {
|
||||
duties: Vec<Duty>,
|
||||
avg_confidence: f32,
|
||||
}
|
||||
|
||||
const MOD_OBLIGATION: &str = "OBLIGATION";
|
||||
const MOD_PROHIBITION: &str = "PROHIBITION";
|
||||
const MOD_PERMISSION: &str = "PERMISSION";
|
||||
|
||||
#[fai_module]
|
||||
pub fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
||||
let norm: InputNorm = inputs
|
||||
.require_json("norm")
|
||||
.map_err(|e| ModuleError::invalid_input(format!("norm JSON shape: {e}")))?;
|
||||
|
||||
let source = format!(
|
||||
"{} {}",
|
||||
norm.jurabk.as_deref().unwrap_or("?"),
|
||||
norm.paragraph.as_deref().unwrap_or(""),
|
||||
);
|
||||
|
||||
let mut duties = Vec::new();
|
||||
let patterns = compile_patterns()?;
|
||||
|
||||
for p in &norm.paragraphs {
|
||||
for sentence in split_sentences(&p.text) {
|
||||
for (modality, conf, re) in &patterns {
|
||||
if re.is_match(sentence) {
|
||||
duties.push(Duty {
|
||||
modality,
|
||||
action: sentence.trim().to_string(),
|
||||
source_norm: source.clone(),
|
||||
paragraph: p.number.clone(),
|
||||
confidence: *conf,
|
||||
});
|
||||
break; // first matching modality wins per sentence
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let avg = if duties.is_empty() {
|
||||
0.0
|
||||
} else {
|
||||
duties.iter().map(|d| d.confidence).sum::<f32>() / duties.len() as f32
|
||||
};
|
||||
let out = Output { duties, avg_confidence: avg };
|
||||
Outputs::new().with_json("duties", &out)
|
||||
}
|
||||
|
||||
fn compile_patterns() -> Result<Vec<(&'static str, f32, Regex)>, ModuleError> {
|
||||
let raw = [
|
||||
(MOD_OBLIGATION, 0.85, r"\bmuss(?:t|en|te)?\b"),
|
||||
(MOD_OBLIGATION, 0.85, r"\bhat\s+zu\s+\w+en\b"),
|
||||
(MOD_OBLIGATION, 0.85, r"\bist\s+verpflichtet\b"),
|
||||
(MOD_OBLIGATION, 0.85, r"\bsind\s+verpflichtet\b"),
|
||||
(MOD_OBLIGATION, 0.80, r"\b(?:ist|sind)\s+anzuzeigen\b"),
|
||||
(MOD_OBLIGATION, 0.80, r"\baufzuzeichnen\b"),
|
||||
(MOD_OBLIGATION, 0.80, r"\b(?:muss|müssen)\s+\w+\s+(?:eingehalten|gef[uü]hrt|gemeldet|nachgewiesen)\b"),
|
||||
(MOD_PROHIBITION, 0.85, r"\bdarf\s+(?:nicht|kein)\b"),
|
||||
(MOD_PROHIBITION, 0.85, r"\bd[uü]rfen\s+(?:nicht|kein)\b"),
|
||||
(MOD_PROHIBITION, 0.85, r"\b(?:ist|sind)\s+untersagt\b"),
|
||||
(MOD_PROHIBITION, 0.85, r"\b(?:ist|sind)\s+verboten\b"),
|
||||
(MOD_PERMISSION, 0.70, r"\bkann\b"),
|
||||
(MOD_PERMISSION, 0.70, r"\bk[oö]nnen\b"),
|
||||
(MOD_PERMISSION, 0.70, r"\bdarf\b"),
|
||||
];
|
||||
let mut out = Vec::with_capacity(raw.len());
|
||||
for (m, c, src) in raw {
|
||||
let re = Regex::new(src).map_err(|e| {
|
||||
ModuleError::invalid_input(format!("internal regex compile: {e}"))
|
||||
})?;
|
||||
out.push((m, c, re));
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
fn split_sentences(text: &str) -> Vec<&str> {
|
||||
text.split_terminator(|c: char| c == '.' || c == ';' || c == '\n')
|
||||
.map(str::trim)
|
||||
.filter(|s| !s.is_empty() && s.len() > 4)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn norm(paragraphs: Vec<(&str, &str)>) -> serde_json::Value {
|
||||
serde_json::json!({
|
||||
"eli": "eli/bund/gewo/14",
|
||||
"jurabk": "GewO",
|
||||
"paragraph": "§ 14",
|
||||
"paragraphs": paragraphs
|
||||
.into_iter()
|
||||
.map(|(n, t)| serde_json::json!({"number": n, "text": t}))
|
||||
.collect::<Vec<_>>(),
|
||||
})
|
||||
}
|
||||
|
||||
fn extract(v: serde_json::Value) -> Output {
|
||||
let p: InputNorm = serde_json::from_value(v).expect("valid");
|
||||
let mut duties = Vec::new();
|
||||
let patterns = compile_patterns().expect("regex ok");
|
||||
for para in &p.paragraphs {
|
||||
for sentence in split_sentences(¶.text) {
|
||||
for (m, c, re) in &patterns {
|
||||
if re.is_match(sentence) {
|
||||
duties.push(Duty {
|
||||
modality: m,
|
||||
action: sentence.trim().to_string(),
|
||||
source_norm: "GewO § 14".into(),
|
||||
paragraph: para.number.clone(),
|
||||
confidence: *c,
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let avg = if duties.is_empty() {
|
||||
0.0
|
||||
} else {
|
||||
duties.iter().map(|d| d.confidence).sum::<f32>() / duties.len() as f32
|
||||
};
|
||||
Output { duties, avg_confidence: avg }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn finds_obligation_in_gewo_14_text() {
|
||||
let result = extract(norm(vec![(
|
||||
"(1)",
|
||||
"Wer den selbstständigen Betrieb anfängt, muss dies anzeigen.",
|
||||
)]));
|
||||
assert!(!result.duties.is_empty());
|
||||
assert_eq!(result.duties[0].modality, "OBLIGATION");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn finds_prohibition() {
|
||||
let result = extract(norm(vec![(
|
||||
"(1)",
|
||||
"Personenbezogene Daten dürfen nicht ohne Einwilligung verarbeitet werden.",
|
||||
)]));
|
||||
assert_eq!(result.duties[0].modality, "PROHIBITION");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_duty_means_zero_avg() {
|
||||
let result = extract(norm(vec![("(1)", "Dieser Satz enthält nichts Deontisches.")]));
|
||||
assert_eq!(result.duties.len(), 0);
|
||||
assert_eq!(result.avg_confidence, 0.0);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue