code wiki / (root) / nx_food_research_fetch.nx

nx_food_research_fetch.nx source

↩ module page · 109 lines · 8421 B

1// nx_food_research_fetch.nx -- the Nishi RESEARCHER's sovereign web-fetch for THE FOOD-SCIENCE branch 2// (operator: "grows a food science branch that uses recipes and other things to help us really nail the 3// science down ... and use the nishi team to get them growing their capabilities via this work"). Mirrors 4// the proven nx_brand_research_fetch / nx_fin_research_fetch pattern: own TLS-1.3 (nx_https_fetch_follow) + 5// Mozilla CA store, saving each cited source to knowledge/fetched/food_*.raw so the research COMPOUNDS and 6// can be grepped to CITE the food-science store's ratios/pairings (grounding rule 4 -- verified facts, not 7// assumptions). This is the researcher GROWING a new capability domain (food), the team-growth the arc asks 8// for. 100% sovereign (own TLS, nx_cc->nxasm, no curl/wget/gcc). Idempotent have-skip = re-run fills gaps 9// (also the per-fetch mmap-leak workaround -- each pass is a fresh process so memory resets). 10// COVERAGE: 26 authoritative food-science topics. expect_exit: 0 license_tier: ORIGINAL 11import "nx_syscalls.nx" 12import "nx_x509_trust_store.nx" 13import "nx_trust_store_load_from_certdata.nx" 14import "nx_https_fetch_follow.nx" 15const K_MAGIC_4194304: i64 = 4194304 16const K_MAGIC_8388608: i64 = 8388608 17 18func 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 } 19func ff_putn(v: i64) -> i64 { 20 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 21 var m: i64 = v 22 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 23 let d: *u8 = sys_mmap(24); var k: i64 = 0 24 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 25 var j: i64 = k - 1 26 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 } 27 return 0 28} 29func have_file(path: *u8) -> i64 { 30 let fd: i64 = sys_openat_rd(path) 31 if fd < 0 { return 0 } 32 sys_close(fd) 33 return 1 34} 35func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 { 36 if have_file(opath) == 1 { ff_puts(opath); ff_puts(" [have-skip]\n" as *u8); return 1 } 37 let status: *i64 = sys_mmap(8) as *i64 38 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status) 39 ff_puts(url); ff_puts(" status=" as *u8); ff_putn(status[0]); ff_puts(" bytes=" as *u8); ff_putn(n) 40 if n <= 0 { ff_puts(" FETCH-FAIL\n" as *u8); return 0 } 41 var gz: i64 = 0 42 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } } 43 if gz == 1 { ff_puts(" [GZIP-skip]\n" as *u8); return 0 } 44 let fd: i64 = sys_openat_wr(opath, 0x1a4) 45 if fd < 0 { ff_puts(" SAVE-FAIL\n" as *u8); return 0 } 46 sys_write(fd, out, n) 47 sys_close(fd) 48 ff_puts(" SAVED\n" as *u8) 49 return 1 50} 51 52func main() -> i64 { 53 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 54 if r <= 0 { ff_puts("FOOD: certdata load failed\n" as *u8); return 1 } 55 let store: *TrustStore = r as *TrustStore 56 ff_puts("CA roots=" as *u8); ff_putn(trust_store_count(store)); ff_puts("\n" as *u8) 57 let cap: i64 = K_MAGIC_8388608 58 let out: *u8 = sys_mmap(cap) 59 var ok: i64 = 0 60 61 ff_puts("== TASTE & FLAVOR SCIENCE (the five tastes, umami, aroma, mouthfeel) ==\n" as *u8) 62 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Taste" as *u8, "knowledge/fetched/food_s1_taste.raw" as *u8, store, out, cap) 63 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Basic_taste" as *u8, "knowledge/fetched/food_s2_basic_taste.raw" as *u8, store, out, cap) 64 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Umami" as *u8, "knowledge/fetched/food_s3_umami.raw" as *u8, store, out, cap) 65 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Flavor" as *u8, "knowledge/fetched/food_s4_flavor.raw" as *u8, store, out, cap) 66 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Aroma_compound" as *u8, "knowledge/fetched/food_s5_aroma.raw" as *u8, store, out, cap) 67 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Mouthfeel" as *u8, "knowledge/fetched/food_s6_mouthfeel.raw" as *u8, store, out, cap) 68 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Pungency" as *u8, "knowledge/fetched/food_s7_pungency.raw" as *u8, store, out, cap) 69 70 ff_puts("== PAIRING & COMBINATION (the food-pairing hypothesis) ==\n" as *u8) 71 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Foodpairing" as *u8, "knowledge/fetched/food_p1_foodpairing.raw" as *u8, store, out, cap) 72 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Flavor_pairing" as *u8, "knowledge/fetched/food_p2_flavor_pairing.raw" as *u8, store, out, cap) 73 74 ff_puts("== TECHNIQUE & THE DISH (stir-fry, wok hei, Maillard, marination) ==\n" as *u8) 75 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Stir_frying" as *u8, "knowledge/fetched/food_t1_stir_frying.raw" as *u8, store, out, cap) 76 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Wok" as *u8, "knowledge/fetched/food_t2_wok.raw" as *u8, store, out, cap) 77 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Mongolian_barbecue" as *u8, "knowledge/fetched/food_t3_mongolian_bbq.raw" as *u8, store, out, cap) 78 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Maillard_reaction" as *u8, "knowledge/fetched/food_t4_maillard.raw" as *u8, store, out, cap) 79 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Marination" as *u8, "knowledge/fetched/food_t5_marination.raw" as *u8, store, out, cap) 80 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Mise_en_place" as *u8, "knowledge/fetched/food_t6_mise_en_place.raw" as *u8, store, out, cap) 81 82 ff_puts("== CUISINE & SAUCE (regional balance traditions) ==\n" as *u8) 83 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Chinese_cuisine" as *u8, "knowledge/fetched/food_c1_chinese.raw" as *u8, store, out, cap) 84 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Sichuan_cuisine" as *u8, "knowledge/fetched/food_c2_sichuan.raw" as *u8, store, out, cap) 85 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Cantonese_cuisine" as *u8, "knowledge/fetched/food_c3_cantonese.raw" as *u8, store, out, cap) 86 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Sauce" as *u8, "knowledge/fetched/food_c4_sauce.raw" as *u8, store, out, cap) 87 88 ff_puts("== STANDARD & ASPIRATION (Michelin, recipe, food science) ==\n" as *u8) 89 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Michelin_Guide" as *u8, "knowledge/fetched/food_a1_michelin.raw" as *u8, store, out, cap) 90 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Recipe" as *u8, "knowledge/fetched/food_a2_recipe.raw" as *u8, store, out, cap) 91 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Food_science" as *u8, "knowledge/fetched/food_a3_food_science.raw" as *u8, store, out, cap) 92 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Cooking" as *u8, "knowledge/fetched/food_a4_cooking.raw" as *u8, store, out, cap) 93 94 ff_puts("== EXTENSION (garden-to-table / farm-to-table / nutrition) ==\n" as *u8) 95 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Local_food" as *u8, "knowledge/fetched/food_e1_local_food.raw" as *u8, store, out, cap) 96 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Kitchen_garden" as *u8, "knowledge/fetched/food_e2_kitchen_garden.raw" as *u8, store, out, cap) 97 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Nutrition" as *u8, "knowledge/fetched/food_e3_nutrition.raw" as *u8, store, out, cap) 98 99 // PRIMARY RESEARCH + LICENSE-CLEAN RECIPE DATA (the "research not bro science" + "no-copyright recipe" 100 // sources -- CC-BY primary paper, CC-BY-SA Wikibooks recipe corpus, public-domain cookbook, US-gov data). 101 ff_puts("== PRIMARY RESEARCH + LICENSE-CLEAN RECIPE DATA ==\n" as *u8) 102 ok = ok + fetch_save("https://www.nature.com/articles/srep00196" as *u8, "knowledge/fetched/food_r1_flavor_network.raw" as *u8, store, out, cap) 103 ok = ok + fetch_save("https://en.wikibooks.org/wiki/Cookbook:Table_of_Contents" as *u8, "knowledge/fetched/food_r2_wikibooks_cookbook.raw" as *u8, store, out, cap) 104 ok = ok + fetch_save("https://en.wikisource.org/wiki/The_Boston_Cooking-School_Cook_Book" as *u8, "knowledge/fetched/food_r3_pd_cookbook.raw" as *u8, store, out, cap) 105 ok = ok + fetch_save("https://fdc.nal.usda.gov/" as *u8, "knowledge/fetched/food_r4_usda_fdc.raw" as *u8, store, out, cap) 106 107 ff_puts("READABLE SOURCES SAVED THIS PASS+HAVE: " as *u8); ff_putn(ok); ff_puts(" / 30\n" as *u8) 108 return 0 109}