interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / protocol / synapse / map / src / 60-route.om

597 lines · 9188 bytes Raw Blame History
1note ======== where and check ========
2note where: lexical score = sum over shared query tokens of idf * (1 + boost), boost 1 for name and
3note topic tokens; archived repos are halved. Lexical and semantic (xerj) scores are each scaled to
4note their maximum (1000), then combined 6:4. Without xerj the lexical score alone ranks.
5
6text tkscore2 "score"
7text tkwhy "why"
8text tksimil "similar"
9text tkwarn "warn"
10text twunr "xerj unreachable"
11text twidx "xerj index unavailable; run synapse-map index"
12text twterms "terms "
13text twnone "no shared terms"
14text twsem "; semantic "
15text tnomatch "synapse-map: no repo matched the task\n"
16text tkkind "kind"
17text tkother "other"
18text tkjac "jaccard"
19text tksem "semantic"
20text tforphan "orphan"
21text tfmiss "missing_parent"
22text tfarch "archived_parent"
23text tfinfp "inferred_parent"
24text tfdup "duplicate_purpose"
25text tffork "fork_parent"
26
27fn sm_wlex to void
28mx = ulong 0
29for r ulong get gst SNREC
30s = ulong 0
31for i ulong sm_sn SQSET
32t = and sm_sget SQSET i 4294967295
33h = sm_shas r t
34if gt h 0
35s = add s mul sm_idf t h
36end
37end
38if ne sm_kg r KARCH 0
39s = div s 2
40end
41put gsc r s
42if gt s mx
43mx = s
44end
45end
46put gst SMAXL mx
47end
48
49note sm_semfill: xerj hits (gxr) into gsm (repos) or gsks (skills); returns the maximum score
50fn sm_semfill sk bool to ulong
51mx = ulong 0
52for i ulong get gst SNXR
53c = get gxr mul i 2
54v = get gxr add mul i 2 1
55if sk
56if ge c 1048576
57put gsks sub c 1048576 v
58end
59else
60if lt c 1048576
61if ne sm_kg c KARCH 0
62v = div v 2
63end
64put gsm c v
65end
66end
67if gt v mx
68mx = v
69end
70end
71ret mx
72end
73
74fn sm_scale v ulong mx ulong to ulong
75if eq mx 0
76ret 0
77end
78ret div mul v 1000 mx
79end
80
81fn sm_wcomb hs bool to void
82ml = get gst SMAXL
83ms = get gst SMAXS
84for r ulong get gst SNREC
85l = sm_scale get gsc r ml
86if hs
87sv = sm_scale get gsm r ms
88w = div add mul l 6 mul sv 4 10
89put gcb r w
90else
91put gcb r l
92end
93put gpick r 0
94end
95end
96
97note sm_sklex: lexical task score of skill s (query terms found in its name and description)
98fn sm_sklex s ulong to ulong
99sm_sclr SXSET
100b4 = mul s 4
101p0 = get gsk b4
102p1 = get gsk add b4 1
103sm_tokz p0 p1 SXSET 0
104p0 = get gsk add b4 2
105p1 = get gsk add b4 3
106sm_tokz p0 p1 SXSET 0
107v = ulong 0
108for i ulong sm_sn SQSET
109t = and sm_sget SQSET i 4294967295
110if gt sm_shas SXSET t 0
111v = add v sm_idf t
112end
113end
114ret v
115end
116
117note sm_skscore: task score per skill (lexical over name and description, plus semantic when present)
118fn sm_skscore hs bool ms ulong to void
119mx = ulong 0
120for s ulong get gst SNSKL
121v = sm_sklex s
122put gskl s v
123if gt v mx
124mx = v
125end
126end
127for s ulong get gst SNSKL
128l = sm_scale get gskl s mx
129if hs
130sv = sm_scale get gsks s ms
131w = div add mul l 6 mul sv 4 10
132put gskc s w
133else
134put gskc s l
135end
136end
137end
138
139note sm_skval: task score of skill s for row r, +300 when its name or description names the repo
140fn sm_skval s ulong r ulong to ulong
141v = get gskc s
142if eq v 0
143ret 0
144end
145b4 = mul s 4
146fo = sm_fo r FNAME
147fl = sm_fl r FNAME
148no = get gsk b4
149nl = get gsk add b4 1
150nm = sm_isub no nl fo fl
151if not nm
152no = get gsk add b4 2
153nl = get gsk add b4 3
154nm = sm_isub no nl fo fl
155end
156if nm
157v = add v 300
158end
159ret v
160end
161
162note sm_skrow: up to 3 skills for row r (task score, +300 when the skill names the repo)
163fn sm_skrow r ulong to void
164sm_okc tkskills
165sm_ob 91
166p1 = SNONE
167p2 = SNONE
168for k ulong 3
169b = SNONE
170bv = ulong 0
171for s ulong get gst SNSKL
172if and ne s p1 ne s p2
173v = sm_skval s r
174if gt v bv
175bv = v
176b = s
177end
178end
179end
180if eq b SNONE
181break
182end
183if gt k 0
184sm_ob 44
185end
186b4 = mul b 4
187no = get gsk b4
188nl = get gsk add b4 1
189sm_oq no nl
190if eq k 0
191p1 = b
192else
193p2 = b
194end
195end
196sm_ob 93
197end
198
199note sm_simrow: up to 3 other repos with the highest Jaccard index of doc sets
200fn sm_simrow r ulong to void
201sm_okc tksimil
202sm_ob 91
203p1 = SNONE
204p2 = SNONE
205for k ulong 3
206b = SNONE
207bv = ulong 0
208for o ulong get gst SNREC
209if and ne o r and ne o p1 ne o p2
210v = sm_jac r o
211if gt v bv
212bv = v
213b = o
214end
215end
216end
217if eq b SNONE
218break
219end
220if gt k 0
221sm_ob 44
222end
223sm_fq b FREPO
224if eq k 0
225p1 = b
226else
227p2 = b
228end
229end
230sm_ob 93
231end
232
233fn sm_why r ulong to void
234sm_okc tkwhy
235sm_ob 34
236n = ulong 0
237for i ulong sm_sn SQSET
238t = and sm_sget SQSET i 4294967295
239if gt sm_shas r t 0
240if eq n 0
241sm_ot twterms
242else
243sm_ob 44
244end
245sm_otext get gtko t get gtkl t
246n = add n 1
247end
248end
249if eq n 0
250sm_ot twnone
251end
252if gt get gsm r 0
253sm_ot twsem
254sm_omil sm_scale get gsm r get gst SMAXS
255end
256sm_ob 34
257end
258
259fn sm_wrow r ulong to void
260sm_ob 123
261sm_ok tkrepo
262sm_fq r FREPO
263sm_okc tkscore2
264sm_omil get gcb r
265sm_okc tkpurp
266sm_fq r FPUR
267sm_okc tkpar
268if ne sm_kg r KPNUL 0
269sm_onull
270else
271sm_fq r FPAR
272end
273sm_why r
274sm_skrow r
275sm_simrow r
276sm_ob 125
277sm_ob 10
278end
279
280fn sm_warn t view uchar * to void
281sm_ob 123
282sm_ok tkwarn
283sm_otq t
284sm_ob 125
285sm_ob 10
286end
287
288note sm_bestpick: unpicked record with the highest combined score above 0, or SNONE
289fn sm_bestpick to ulong
290b = SNONE
291bv = ulong 0
292for r ulong get gst SNREC
293if eq get gpick r 0
294v = get gcb r
295if gt v bv
296bv = v
297b = r
298end
299end
300end
301ret b
302end
303
304fn sm_cwhere to int
305np = sm_argscan tvfwh tswnox
306if ne np 1
307sm_usage
308end
309qi = get gst SSLEN
310lim = ulong 5
311l = sm_aval tflimit
312if gt l 0
313lim = sm_anum l
314if or eq lim 0 gt lim 100
315sm_err tbadnum
316sm_err tflimit
317sm_errnl
318sm_die 64
319end
320end
321sm_home
322sm_xopts
323sm_loadmap
324sm_loadtop
325sm_loadskl
326sm_tokrec
327qo = sm_apool qi
328qn = get gst SSLEN
329sm_sclr SQSET
330sm_tokz qo qn SQSET 0
331sm_wlex
332for r ulong get gst SNREC
333put gsm r 0
334end
335for s ulong get gst SNSKL
336put gsks s 0
337end
338hs = false
339ms2 = ulong 0
340if eq get gst SXST 0
341x = sm_xsearch qo qn 0 25
342if ge x 0
343hs = true
344put gst SMAXS sm_semfill false
345if gt get gst SNSKL 0
346y = sm_xsearch qo qn 1 10
347if ge y 0
348ms2 = sm_semfill true
349end
350end
351else
352if eq get gst SXST 2
353sm_warn twunr
354else
355sm_warn twidx
356end
357end
358end
359put gst SHSEM 0
360sm_wcomb hs
361sm_skscore hs ms2
362nrow = ulong 0
363for k ulong lim
364b = sm_bestpick
365if eq b SNONE
366break
367end
368put gpick b 1
369sm_wrow b
370nrow = add nrow 1
371end
372if eq nrow 0
373sm_err tnomatch
374sm_die 4
375end
376ret 0
377end
378
379note ---- check ----
380fn sm_fhead t view uchar * r ulong to void
381sm_ob 123
382sm_ok tkkind
383sm_otq t
384sm_okc tkrepo
385sm_fq r FREPO
386end
387
388fn sm_fpar r ulong to void
389sm_okc tkpar
390sm_fq r FPAR
391end
392
393fn sm_fend to void
394sm_ob 125
395sm_ob 10
396end
397
398note sm_semnb: xerj top-3 neighbours (codes + 1) of record r's purpose into gtop; false when xerj fails
399fn sm_semnb r ulong to bool
400po = sm_fo r FPUR
401pl = sm_fl r FPUR
402x = sm_xsearch po pl 0 4
403if lt x 0
404ret false
405end
406b4 = mul r 4
407k = ulong 0
408for i ulong get gst SNXR
409c = get gxr mul i 2
410if and ne c r lt k 3
411put gtop add b4 k add c 1
412k = add k 1
413end
414end
415ret true
416end
417
418note sm_semtop: xerj top-3 neighbours (codes + 1) of every live record's purpose into gtop
419fn sm_semtop to bool
420for r ulong get gst SNREC
421b4 = mul r 4
422put gtop b4 0
423put gtop add b4 1 0
424put gtop add b4 2 0
425if and eq sm_kg r KARCH 0 gt sm_fl r FPUR 0
426if ne get gst SXST 2
427if not sm_semnb r
428ret false
429end
430end
431end
432end
433ret ne get gst SXST 2
434end
435
436fn sm_isnb a ulong b ulong to bool
437for i ulong 3
438if eq get gtop add mul a 4 i add b 1
439ret true
440end
441end
442ret false
443end
444
445note sm_dlive: a and b (a before b) are both live and both have a purpose
446fn sm_dlive a ulong b ulong to bool
447if ge a b
448ret false
449end
450if ne sm_kg a KARCH 0
451ret false
452end
453if ne sm_kg b KARCH 0
454ret false
455end
456if eq sm_fl a FPUR 0
457ret false
458end
459ret gt sm_fl b FPUR 0
460end
461
462note sm_dpair: emit a duplicate_purpose finding for live pair a b when it clears th; true when emitted
463fn sm_dpair a ulong b ulong th ulong hs bool to bool
464ia = add 1024 a
465ib = add 1024 b
466j = sm_jac ia ib
467nb = false
468if hs
469n1 = sm_isnb a b
470n2 = sm_isnb b a
471nb = and n1 n2
472end
473j2 = mul j 2
474hit = ge j th
475if nb
476if ge j2 th
477hit = true
478end
479end
480if not hit
481ret false
482end
483sm_fhead tfdup a
484sm_okc tkother
485sm_fq b FREPO
486sm_okc tkjac
487sm_omil j
488sm_okc tksem
489if hs
490n1 = sm_isnb a b
491n2 = sm_isnb b a
492sm_obool or n1 n2
493else
494sm_onull
495end
496sm_fend
497ret true
498end
499
500note sm_cdup: duplicate_purpose pairs; returns the number of findings
501fn sm_cdup th ulong hs bool to ulong
502nf = ulong 0
503for a ulong get gst SNREC
504for b ulong get gst SNREC
505if sm_dlive a b
506if sm_dpair a b th hs
507nf = add nf 1
508end
509end
510end
511end
512ret nf
513end
514
515text tdthr "synapse-map: xerj unreachable; duplicate_purpose uses Jaccard only (semantic null)\n"
516
517fn sm_ccheck to int
518np = sm_argscan tvfchk tswnox
519if ne np 0
520sm_usage
521end
522th = ulong 500
523m = sm_aval tfminj
524if gt m 0
525th = sm_anum m
526if or eq th SNONE gt th 1000
527sm_err tbadnum
528sm_err tfminj
529sm_errnl
530sm_die 64
531end
532end
533sm_home
534sm_xopts
535sm_loadmap
536sm_tokrec
537nf = ulong 0
538for r ulong get gst SNREC
539nf = add nf sm_crec r
540end
541hs = false
542if eq get gst SNOX 0
543hs = sm_semtop
544if not hs
545sm_err tdthr
546end
547end
548nf = add nf sm_cdup th hs
549if gt nf 0
550sm_die 1
551end
552ret 0
553end
554
555note sm_crec: per-record findings (orphan, missing, archived, fork and inferred parents)
556fn sm_crec r ulong to ulong
557nf = ulong 0
558if sm_feqt r FPST tsnone
559sm_fhead tforphan r
560sm_okc tkrule
561sm_fq r FRULE
562sm_fend
563nf = add nf 1
564end
565if eq sm_kg r KPNUL 0
566p = sm_kg r KPIDX
567if eq p 0
568sm_fhead tfmiss r
569sm_fpar r
570sm_fend
571nf = add nf 1
572else
573q = sub p 1
574if and ne sm_kg q KARCH 0 eq sm_kg r KARCH 0
575sm_fhead tfarch r
576sm_fpar r
577sm_fend
578nf = add nf 1
579end
580if and ne sm_kg q KFORK 0 eq sm_kg r KFORK 0
581sm_fhead tffork r
582sm_fpar r
583sm_fend
584nf = add nf 1
585end
586end
587end
588if sm_feqt r FPST tsinf
589sm_fhead tfinfp r
590sm_fpar r
591sm_okc tkrule
592sm_fq r FRULE
593sm_fend
594nf = add nf 1
595end
596ret nf
597end