mod: Ext 2 — weighted/aggregate scoring (:score-at-least), 154/154
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 52s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 52s
Report :signals ({:kind :weight}) project to signal(Id, 'kind', weight) facts;
condition (:score-at-least N) compiles to aggregate_all(sum(W), signal(Id,_,W),T),
T >= N. Low-confidence signals accumulate past a threshold via genuine Prolog
arithmetic aggregation. Default policy untouched — proven via custom rule sets.
+8 extension tests.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
;; lib/mod/schema.sx — report representation + Prolog fact generation.
|
||||
;;
|
||||
;; A report is a dict {:id :by :about :reason :evidence :attrs}. :evidence is a
|
||||
;; list of accumulated evidence entries {:kind :val} (human review, automated
|
||||
;; scanners). :attrs is a list of attribute names (e.g. "verified") used by
|
||||
;; negation-as-failure conditions. The engine derives keyword classifications
|
||||
;; from the reason text and projects the report, its classifications, evidence,
|
||||
;; and attributes into Prolog facts that policy clauses match against.
|
||||
;; A report is a dict {:id :by :about :reason :evidence :attrs :signals}.
|
||||
;; :evidence — accumulated {:kind :val} entries (human review, scanners)
|
||||
;; :attrs — attribute names ("verified") for negation-as-failure conditions
|
||||
;; :signals — weighted {:kind :weight} entries for aggregate scoring rules
|
||||
;; The engine derives keyword classifications from the reason text and projects
|
||||
;; the report, its classifications, evidence, attributes, and signals into Prolog
|
||||
;; facts that policy clauses match against.
|
||||
|
||||
(define mod/mk-report (fn (id by about reason) {:attrs (list) :id id :by by :evidence (list) :about about :reason reason}))
|
||||
(define mod/mk-report (fn (id by about reason) {:attrs (list) :id id :signals (list) :by by :evidence (list) :about about :reason reason}))
|
||||
|
||||
(define mod/report-id (fn (r) (get r :id)))
|
||||
(define mod/report-by (fn (r) (get r :by)))
|
||||
@@ -22,19 +23,37 @@
|
||||
mod/report-attrs
|
||||
(fn (r) (let ((a (get r :attrs))) (if (nil? a) (list) a))))
|
||||
|
||||
(define
|
||||
mod/report-signals
|
||||
(fn (r) (let ((s (get r :signals))) (if (nil? s) (list) s))))
|
||||
|
||||
(define mod/mk-evidence (fn (kind val) {:val val :kind kind}))
|
||||
(define mod/evidence-kind (fn (e) (get e :kind)))
|
||||
(define mod/evidence-val (fn (e) (get e :val)))
|
||||
|
||||
(define mod/report* (fn (r evs attrs) {:attrs attrs :id (mod/report-id r) :by (mod/report-by r) :evidence evs :about (mod/report-about r) :reason (mod/report-reason r)}))
|
||||
(define mod/mk-signal (fn (kind weight) {:kind kind :weight weight}))
|
||||
(define mod/signal-kind (fn (s) (get s :kind)))
|
||||
(define mod/signal-weight (fn (s) (get s :weight)))
|
||||
|
||||
(define mod/report* (fn (r evs attrs sigs) {:attrs attrs :id (mod/report-id r) :signals sigs :by (mod/report-by r) :evidence evs :about (mod/report-about r) :reason (mod/report-reason r)}))
|
||||
|
||||
(define
|
||||
mod/with-evidence
|
||||
(fn (r evs) (mod/report* r evs (mod/report-attrs r))))
|
||||
(fn
|
||||
(r evs)
|
||||
(mod/report* r evs (mod/report-attrs r) (mod/report-signals r))))
|
||||
|
||||
(define
|
||||
mod/with-attrs
|
||||
(fn (r attrs) (mod/report* r (mod/report-evidence r) attrs)))
|
||||
(fn
|
||||
(r attrs)
|
||||
(mod/report* r (mod/report-evidence r) attrs (mod/report-signals r))))
|
||||
|
||||
(define
|
||||
mod/with-signals
|
||||
(fn
|
||||
(r sigs)
|
||||
(mod/report* r (mod/report-evidence r) (mod/report-attrs r) sigs)))
|
||||
|
||||
(define
|
||||
mod/attach-evidence
|
||||
@@ -46,6 +65,10 @@
|
||||
mod/attach-attr
|
||||
(fn (r a) (mod/with-attrs r (append (mod/report-attrs r) (list a)))))
|
||||
|
||||
(define
|
||||
mod/attach-signal
|
||||
(fn (r s) (mod/with-signals r (append (mod/report-signals r) (list s)))))
|
||||
|
||||
;; ── substring search (the prolog-loaded env lacks includes?; slice/len do work) ──
|
||||
|
||||
(define
|
||||
@@ -162,6 +185,25 @@
|
||||
(id attrs)
|
||||
(mod/join-with "\n" (map (fn (a) (str "attr(" id ", " a ").")) attrs))))
|
||||
|
||||
(define
|
||||
mod/signal-facts
|
||||
(fn
|
||||
(id sigs)
|
||||
(mod/join-with
|
||||
"\n"
|
||||
(map
|
||||
(fn
|
||||
(s)
|
||||
(str
|
||||
"signal("
|
||||
id
|
||||
", "
|
||||
(mod/pl-quote (mod/signal-kind s))
|
||||
", "
|
||||
(mod/signal-weight s)
|
||||
")."))
|
||||
sigs))))
|
||||
|
||||
(define
|
||||
mod/report-facts
|
||||
(fn
|
||||
@@ -173,7 +215,8 @@
|
||||
(let
|
||||
((cls (mod/classification-facts id (mod/classify-keywords r)))
|
||||
(evs (mod/evidence-facts id (mod/report-evidence r)))
|
||||
(ats (mod/attr-facts id (mod/report-attrs r))))
|
||||
(ats (mod/attr-facts id (mod/report-attrs r)))
|
||||
(sgs (mod/signal-facts id (mod/report-signals r))))
|
||||
(mod/join-with
|
||||
"\n"
|
||||
(list
|
||||
@@ -181,4 +224,5 @@
|
||||
(str "report_count(" about ", " count ").")
|
||||
cls
|
||||
evs
|
||||
ats))))))
|
||||
ats
|
||||
sgs))))))
|
||||
|
||||
Reference in New Issue
Block a user