static double ai_gc_scan_maxDistance_reached; static S ai_gc_scan(S root) { ai_gc_clear(); ai_startBuffering(); Map<S, Double> distances; try { time "GC Scan" { ai_postTriple(root, "has GC distance", "0"); distances = litcimap(root, 0.0); LinkedList<S> queue = litLinkedList(root); S word; while ping ((word = queue.poll()) != null) { double d = distances.get(word); for (WebNode node : indexedNodes(word)) { for (WebRelation r : web_forwardRelations(node)) { double dist = ai_gc_distanceFunction(web_text(r), true); if (!isNaN(dist)) ai_gc_scan_update(distances, queue, r.b, d+dist); } for (WebRelation r : web_backwardRelations(node)) { double dist = ai_gc_distanceFunction(web_text(r), false); if (!isNaN(dist)) ai_gc_scan_update(distances, queue, r.a, d+dist); } } } Collection<S> keys = keys(distances); if (ai_inTestMode()) keys = keysSortedByValueDesc(distances); ai_gc_scan_maxDistance_reached = 0; for (S key : keys) { double d = distances.get(key); if (d > ai_gc_scan_maxDistance_reached) ai_gc_scan_maxDistance_reached = d; ai_postTriple(key, "has GC distance", formatDouble(d, 1)); } } } finally { ai_stopBuffering(); } ret print(l(distances) + "/" + l(indexedTerms()) + " terms were reached in " + toS(lastTiming(), 1) + " s GC scan from " + quote(root) + ". Max distance: " + formatDouble(ai_gc_scan_maxDistance_reached, 1)); } static void ai_gc_scan_update(Map<S, Double> distances, L<S> queue, WebNode n, double d) { //S text = ai_shortenForIndex(web_text(n)); S text = web_text(n); Double od = distances.get(text); if (od == null || d < od) { distances.put(text, d); queue.add(text); } }
Began life as a copy of #1011796
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1011799 |
Snippet name: | ai_gc_scan - TODO: order by smallest distance; then maybe we never overwrite any values? |
Eternal ID of this version: | #1011799/23 |
Text MD5: | 634dc0369ab9e99b608842b9c40b48a3 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-11-05 18:43:31 |
Source code size: | 1957 bytes / 54 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 428 / 463 |
Version history: | 22 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) |