code wiki / _hdl_build / nx_paper_emit.nx

nx_paper_emit.nx source

↩ module page · 50 lines · 4032 B

1// nx_paper_emit.nx -- the Scientist EMITS each proven result in TWO captured formats (operator: 2// structure + capture the output both as DATA and as RESEARCH PAPER so the team can publish): a 3// structured DATA RECORD (machine-parseable key=value, for re-analysis + the knowledge base) AND a 4// PAPER (the publishable document with the scientific-method sections). Emission is GATED by the 5// Scientist's review -- an OVERCLAIM is never captured as a paper (it would meet outside critics and 6// fall). The Librarian persists both. license_tier: ORIGINAL Refs: nx_scientist (the gate); data+paper duality. 7 8import "nx_scientist.nx" // SCI_PUBLISH + sci_decision (the gate) 9 10func pe_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 11func pe_app(buf: *u8, s: *u8) -> i64 { var oi: i64 = 0; while buf[oi] != (0 as u8) { oi = oi + 1 } var j: i64 = 0; while s[j] != (0 as u8) { buf[oi]=s[j]; oi=oi+1; j=j+1 } buf[oi]=0 as u8; return 0 } 12func pe_appn(buf: *u8, v: i64) -> i64 { var oi: i64 = 0; while buf[oi] != (0 as u8) { oi = oi + 1 } let t: *u8 = sys_mmap(28); var m: i64=v; var k: i64=0; if m<0 {buf[oi]=45;oi=oi+1;m=0-m} if m==0 {t[0]=48;k=1} while m>0 {t[k]=48+(m%10); m=m/10; k=k+1} var z: i64=0; while z<k {buf[oi]=t[k-1-z]; oi=oi+1; z=z+1} buf[oi]=0 as u8; return 0 } 13func pe_contains(buf: *u8, needle: *u8) -> i64 { let n: i64 = pe_slen(buf); let m: i64 = pe_slen(needle); if m==0 {return 1} var i: i64=0; while i+m<=n { var j: i64=0; var ok: i64=1; while j<m { if buf[i+j]!=needle[j] {ok=0;j=m} else {j=j+1} } if ok==1 {return 1} i=i+1 } return 0 } 14 15// the structured DATA RECORD (parseable, like the CREWMSG protocol but for a result). 16func pe_data_record(buf: *u8, cap: *u8, claim_tier: i64, metric: i64, baseline: i64, sota: i64, grade: i64, reproducible: i64) -> i64 { 17 buf[0] = 0 as u8 18 pe_app(buf, "RESULT cap=" as *u8); pe_app(buf, cap) 19 pe_app(buf, " claim_tier=" as *u8); pe_appn(buf, claim_tier) 20 pe_app(buf, " metric=" as *u8); pe_appn(buf, metric) 21 pe_app(buf, " baseline=" as *u8); pe_appn(buf, baseline) 22 pe_app(buf, " sota=" as *u8); pe_appn(buf, sota) 23 pe_app(buf, " grade=" as *u8); pe_appn(buf, grade) 24 pe_app(buf, " reproducible=" as *u8); pe_appn(buf, reproducible); pe_app(buf, "\n" as *u8) 25 return pe_slen(buf) 26} 27 28// the PAPER (the publishable document: the scientific-method sections, with the honest grade + data). 29func pe_paper(buf: *u8, cap: *u8, claim: *u8, method: *u8, metric: i64, baseline: i64, sota: i64, grade_word: *u8, caveat: *u8, gate: *u8) -> i64 { 30 buf[0] = 0 as u8 31 pe_app(buf, "# " as *u8); pe_app(buf, cap); pe_app(buf, "\n\n## Claim\n" as *u8); pe_app(buf, claim) 32 pe_app(buf, "\n\n## Method\n" as *u8); pe_app(buf, method) 33 pe_app(buf, "\n\n## Results (data)\nmetric=" as *u8); pe_appn(buf, metric); pe_app(buf, " baseline=" as *u8); pe_appn(buf, baseline); pe_app(buf, " sota=" as *u8); pe_appn(buf, sota) 34 pe_app(buf, "\n\n## Honest grade\n" as *u8); pe_app(buf, grade_word) 35 pe_app(buf, "\n\n## Caveats\n" as *u8); pe_app(buf, caveat) 36 pe_app(buf, "\n\n## Reproducibility\n" as *u8); pe_app(buf, gate); pe_app(buf, "\n" as *u8) 37 return pe_slen(buf) 38} 39 40// EMIT both formats, but ONLY if the Scientist's review says PUBLISH. returns the decision; on a 41// non-publish (e.g. overclaim) it refuses (leaves the buffers empty) -- nothing false is captured. 42func pe_publish(data_buf: *u8, paper_buf: *u8, complete: i64, no_overclaim: i64, reproducible: i64, cap: *u8, claim: *u8, method: *u8, claim_tier: i64, metric: i64, baseline: i64, sota: i64, grade: i64, grade_word: *u8, caveat: *u8, gate: *u8) -> i64 { 43 data_buf[0] = 0 as u8; paper_buf[0] = 0 as u8 44 let decision: i64 = sci_decision(complete, no_overclaim, reproducible) 45 if decision == SCI_PUBLISH { 46 pe_data_record(data_buf, cap, claim_tier, metric, baseline, sota, grade, reproducible) 47 pe_paper(paper_buf, cap, claim, method, metric, baseline, sota, grade_word, caveat, gate) 48 } 49 return decision 50}