nx_sota_research_fetch.nx source
↩ module page · 96 lines · 6876 B
1// nx_sota_research_fetch.nx -- the Nishi RESEARCHER's sovereign web-fetch
2// for the FOOD-SCIENCE SOTA BENCHMARK + the hard-science foundations
3// (steam/thermodynamics, heat-transfer physics, solution chemistry,
4// numerical math). Grounds the SOTA-benchmark census (which names real
5// incumbent tools) AND the new physics/chemistry organs -- "research not
6// bro science". Mirrors the proven fetcher pattern: own TLS-1.3 + Mozilla
7// CA, idempotent have-skip, ->knowledge/fetched/foodsota_*.raw.
8// COVERAGE: 24 sources. expect_exit: 0 license_tier: ORIGINAL
9import "nx_syscalls.nx"
10import "nx_x509_trust_store.nx"
11import "nx_trust_store_load_from_certdata.nx"
12import "nx_https_fetch_follow.nx"
13const K_MAGIC_4194304: i64 = 4194304
14const K_MAGIC_8388608: i64 = 8388608
15
16func ff_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
17func ff_putn(v: i64) -> i64 {
18 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
19 var m: i64 = v
20 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
21 let d: *u8 = sys_mmap(24)
22 var k: i64 = 0
23 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
24 var j: i64 = k - 1
25 while j >= 0 { sys_write(1, (d as i64 + j) as *u8, 1); j = j - 1 }
26 return 0
27}
28func have_file(path: *u8) -> i64 {
29 let fd: i64 = sys_openat_rd(path)
30 if fd < 0 { return 0 }
31 sys_close(fd)
32 return 1
33}
34func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 {
35 if have_file(opath) == 1 { ff_puts(opath); ff_puts(" [have-skip]\n" as *u8); return 1 }
36 let status: *i64 = sys_mmap(8) as *i64
37 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status)
38 ff_puts(url); ff_puts(" status=" as *u8); ff_putn(status[0]); ff_puts(" bytes=" as *u8); ff_putn(n)
39 if n <= 0 { ff_puts(" FETCH-FAIL\n" as *u8); return 0 }
40 var gz: i64 = 0
41 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } }
42 if gz == 1 { ff_puts(" [GZIP-skip]\n" as *u8); return 0 }
43 let fd: i64 = sys_openat_wr(opath, 0x1a4)
44 if fd < 0 { ff_puts(" SAVE-FAIL\n" as *u8); return 0 }
45 sys_write(fd, out, n)
46 sys_close(fd)
47 ff_puts(" SAVED\n" as *u8)
48 return 1
49}
50
51func main() -> i64 {
52 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304)
53 if r <= 0 { ff_puts("SOTA: certdata load failed\n" as *u8); return 1 }
54 let store: *TrustStore = r as *TrustStore
55 ff_puts("CA roots=" as *u8); ff_putn(trust_store_count(store)); ff_puts("\n" as *u8)
56 let cap: i64 = K_MAGIC_8388608
57 let out: *u8 = sys_mmap(cap)
58 var ok: i64 = 0
59
60 ff_puts("== SOTA TOOLS + SYSTEMS (named incumbents to benchmark against) ==\n" as *u8)
61 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Predictive_microbiology" as *u8, "knowledge/fetched/foodsota_t1_predictive_microbiology.raw" as *u8, store, out, cap)
62 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Minitab" as *u8, "knowledge/fetched/foodsota_t2_minitab.raw" as *u8, store, out, cap)
63 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Laboratory_information_management_system" as *u8, "knowledge/fetched/foodsota_t3_lims.raw" as *u8, store, out, cap)
64 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Rheometer" as *u8, "knowledge/fetched/foodsota_t4_rheometer.raw" as *u8, store, out, cap)
65 ok = ok + fetch_save("https://en.wikipedia.org/wiki/High-performance_liquid_chromatography" as *u8, "knowledge/fetched/foodsota_t5_hplc.raw" as *u8, store, out, cap)
66 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Gas_chromatography" as *u8, "knowledge/fetched/foodsota_t6_gc.raw" as *u8, store, out, cap)
67
68 ff_puts("== STEAM + THERMODYNAMICS ==\n" as *u8)
69 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Steam" as *u8, "knowledge/fetched/foodsota_s1_steam.raw" as *u8, store, out, cap)
70 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Enthalpy_of_vaporization" as *u8, "knowledge/fetched/foodsota_s2_enthalpy_vaporization.raw" as *u8, store, out, cap)
71 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Psychrometrics" as *u8, "knowledge/fetched/foodsota_s3_psychrometrics.raw" as *u8, store, out, cap)
72 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Thermodynamics" as *u8, "knowledge/fetched/foodsota_s4_thermodynamics.raw" as *u8, store, out, cap)
73 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Enthalpy" as *u8, "knowledge/fetched/foodsota_s5_enthalpy.raw" as *u8, store, out, cap)
74 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Vapour_pressure_of_water" as *u8, "knowledge/fetched/foodsota_s6_vapour_pressure_water.raw" as *u8, store, out, cap)
75
76 ff_puts("== PHYSICS / HEAT TRANSFER ==\n" as *u8)
77 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Heat_transfer" as *u8, "knowledge/fetched/foodsota_p1_heat_transfer.raw" as *u8, store, out, cap)
78 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Thermal_conduction" as *u8, "knowledge/fetched/foodsota_p2_thermal_conduction.raw" as *u8, store, out, cap)
79 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Convective_heat_transfer" as *u8, "knowledge/fetched/foodsota_p3_convective_heat_transfer.raw" as *u8, store, out, cap)
80 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Biot_number" as *u8, "knowledge/fetched/foodsota_p4_biot_number.raw" as *u8, store, out, cap)
81 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Fourier_number" as *u8, "knowledge/fetched/foodsota_p5_fourier_number.raw" as *u8, store, out, cap)
82
83 ff_puts("== CHEMISTRY ==\n" as *u8)
84 ok = ok + fetch_save("https://en.wikipedia.org/wiki/PH" as *u8, "knowledge/fetched/foodsota_c1_ph.raw" as *u8, store, out, cap)
85 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Henderson%E2%80%93Hasselbalch_equation" as *u8, "knowledge/fetched/foodsota_c2_henderson_hasselbalch.raw" as *u8, store, out, cap)
86 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Molar_concentration" as *u8, "knowledge/fetched/foodsota_c3_molar_concentration.raw" as *u8, store, out, cap)
87 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Arrhenius_equation" as *u8, "knowledge/fetched/foodsota_c4_arrhenius.raw" as *u8, store, out, cap)
88 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Titration" as *u8, "knowledge/fetched/foodsota_c5_titration.raw" as *u8, store, out, cap)
89
90 ff_puts("== MATH ==\n" as *u8)
91 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Numerical_analysis" as *u8, "knowledge/fetched/foodsota_m1_numerical_analysis.raw" as *u8, store, out, cap)
92 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Binomial_distribution" as *u8, "knowledge/fetched/foodsota_m2_binomial_distribution.raw" as *u8, store, out, cap)
93
94 ff_puts("READABLE SOURCES SAVED THIS PASS+HAVE: " as *u8); ff_putn(ok); ff_puts(" / 24\n" as *u8)
95 return 0
96}