nx_legalsem_gate.nx source
↩ module page · 67 lines · 5447 B
1// nx_legalsem_gate.nx -- INDEPENDENT GATE: concept-level (paraphrase) clause matching + POLARITY.
2// INHERITS nx_gate_verdict (D001) so nx_gate_green can judge it and it records a harness.jrnl frame.
3//
4// The teeth:
5// u2605PARAPHRASE WORKS: "indemnify and hold harmless" vs "defend against claims" share almost no words --
6// word-level matching scores them unrelated -- but they invoke the SAME legal concept and match here.
7// u2605u2605NEGATION IS NOT SEMANTIC NOISE: "shall indemnify" and "shall NOT indemnify" invoke IDENTICAL
8// concepts and score 1000 overlap. That is exactly where dense vector embeddings fail on contracts.
9// The reversal detector is BITE-PROVEN: it must FIRE on the inverted clause and stay SILENT on a
10// genuine paraphrase -- a detector that cannot distinguish those is not a detector.
11// u2605NO VACUOUS AGREEMENT: two texts invoking no known concept are not "identical".
12// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
13
14import "nx_legalsem_lib.nx"
15import "nx_gate_verdict.nx"
16
17func main(argc: i64, argv: *i64) -> i64 {
18 let ctr: *i64 = gv_ctr()
19 gv_head("NISHI-LEGALSEM-GATE (concept-level paraphrase matching + polarity)" as *u8)
20
21 let indem_a: *u8 = "Supplier shall indemnify and hold harmless Customer from all claims" as *u8
22 let indem_b: *u8 = "Supplier agrees to defend Customer against every third party demand" as *u8
23 let indem_neg: *u8 = "Supplier shall not indemnify Customer for any claims whatsoever" as *u8
24 let conf_a: *u8 = "Recipient shall protect all confidential information of Discloser" as *u8
25 let conf_b: *u8 = "Recipient shall safeguard the proprietary materials it receives" as *u8
26 let alien_a: *u8 = "The parties shall meet quarterly in a mutually agreed location" as *u8
27 let alien_b: *u8 = "Deliverables will be reviewed at each scheduled progress session" as *u8
28
29 // ---- C: the ontology ----
30 gv_check("C1 indemnify maps to the indemnity concept" as *u8, sem_concept_of("indemnify" as *u8) == SEM_INDEMNITY, ctr)
31 gv_check("C2 harmless maps to the SAME concept" as *u8, sem_concept_of("harmless" as *u8) == SEM_INDEMNITY, ctr)
32 gv_check("C3 defend maps there too" as *u8, sem_concept_of("defend" as *u8) == SEM_INDEMNITY, ctr)
33 gv_check("C4 proprietary maps to confidentiality" as *u8, sem_concept_of("proprietary" as *u8) == SEM_CONFIDENTIALITY, ctr)
34 gv_check("C5 an ordinary word maps to no concept" as *u8, sem_concept_of("quarterly" as *u8) == SEM_NONE, ctr)
35 gv_check("C6 uncapped is its own concept, not liability" as *u8, sem_concept_of("uncapped" as *u8) == SEM_UNCAPPED, ctr)
36
37 // ---- P: PARAPHRASE ----
38 gv_check("P1 clause A invokes indemnity" as *u8, sem_has_concept(indem_a, SEM_INDEMNITY) == 1, ctr)
39 gv_check("P2 clause B invokes it in different words" as *u8, sem_has_concept(indem_b, SEM_INDEMNITY) == 1, ctr)
40 gv_check("P3 word-level matching sees them as barely related" as *u8, cl_retained_permille(indem_a, indem_b) < 400, ctr)
41 gv_check("P4 concept-level sees them as the SAME clause" as *u8, sem_overlap_permille(indem_a, indem_b) == 1000, ctr)
42 gv_check("P5 so they are EQUIVALENT despite the vocabulary gap" as *u8, sem_equivalent(indem_a, indem_b) == 1, ctr)
43 gv_check("P6 confidentiality paraphrase also matches" as *u8, sem_equivalent(conf_a, conf_b) == 1, ctr)
44
45 // ---- N: POLARITY -- where embedding similarity fails ----
46 gv_check("N1 the negated clause invokes the SAME concept" as *u8, sem_has_concept(indem_neg, SEM_INDEMNITY) == 1, ctr)
47 gv_check("N2 concept overlap with the positive clause is TOTAL" as *u8, sem_overlap_permille(indem_a, indem_neg) == 1000, ctr)
48 gv_check("N3 the positive clause is not negated" as *u8, sem_negated(indem_a) == 0, ctr)
49 gv_check("N4 the negated clause is detected" as *u8, sem_negated(indem_neg) == 1, ctr)
50 gv_check("N5 despite 1000 overlap they are NOT equivalent" as *u8, sem_equivalent(indem_a, indem_neg) == 0, ctr)
51 gv_bite("N6 reversal detector (fires on inverted, silent on paraphrase)" as *u8, sem_reversal(indem_a, indem_neg), sem_reversal(indem_a, indem_b), ctr)
52 gv_check("N7 'without' registers as negation" as *u8, sem_negated("Customer accepts the goods without warranty" as *u8) == 1, ctr)
53 gv_check("N8 'nothing' must NOT register as 'not'" as *u8, sem_negated("Nothing herein limits the parties rights" as *u8) == 0, ctr)
54
55 // ---- V: the verdict cannot blur a reversal into a weak match ----
56 gv_check("V1 paraphrase -> EQUIVALENT" as *u8, sem_verdict(indem_a, indem_b) == 1, ctr)
57 gv_check("V2 inverted obligation -> REVERSED, not 'different'" as *u8, sem_verdict(indem_a, indem_neg) == 2, ctr)
58 gv_check("V3 unrelated clause -> DIFFERENT" as *u8, sem_verdict(indem_a, conf_a) == 0, ctr)
59
60 // ---- Z: no vacuous agreement ----
61 gv_check("Z1 an unrecognised clause invokes no concepts" as *u8, sem_concept_count(alien_a) == 0, ctr)
62 gv_check("Z2 two concept-free texts are NOT identical" as *u8, sem_overlap_permille(alien_a, alien_b) == 0, ctr)
63 gv_check("Z3 and are never equivalent by vacuous agreement" as *u8, sem_equivalent(alien_a, alien_b) == 0, ctr)
64 gv_check("Z4 indemnity clause invokes exactly one concept" as *u8, sem_concept_count(indem_a) == 1, ctr)
65
66 return gv_verdict("LEGALSEM-POLARITY" as *u8, ctr, "paraphrase matches across vocabulary; an inverted obligation is a REVERSAL not a weak match" as *u8)
67}