Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

54
LINES

< > BotCompany Repo | #1011799 // ai_gc_scan - TODO: order by smallest distance; then maybe we never overwrite any values?

JavaX fragment (include)

1  
static double ai_gc_scan_maxDistance_reached;
2  
3  
static S ai_gc_scan(S root) {
4  
  ai_gc_clear();
5  
  ai_startBuffering();
6  
  Map<S, Double> distances;
7  
  try {
8  
    time "GC Scan" {
9  
      ai_postTriple(root, "has GC distance", "0");
10  
      distances = litcimap(root, 0.0);
11  
      LinkedList<S> queue = litLinkedList(root);
12  
      S word;
13  
      while ping ((word = queue.poll()) != null) {
14  
        double d = distances.get(word);
15  
        for (WebNode node : indexedNodes(word)) {
16  
          for (WebRelation r : web_forwardRelations(node)) {
17  
            double dist = ai_gc_distanceFunction(web_text(r), true);
18  
            if (!isNaN(dist))
19  
              ai_gc_scan_update(distances, queue, r.b, d+dist);
20  
          }
21  
            
22  
          for (WebRelation r : web_backwardRelations(node)) {
23  
            double dist = ai_gc_distanceFunction(web_text(r), false);
24  
            if (!isNaN(dist))
25  
              ai_gc_scan_update(distances, queue, r.a, d+dist);
26  
          }
27  
        }
28  
      }
29  
      Collection<S> keys = keys(distances);
30  
      if (ai_inTestMode())
31  
        keys = keysSortedByValueDesc(distances);
32  
      ai_gc_scan_maxDistance_reached = 0;
33  
      for (S key : keys) {
34  
        double d = distances.get(key);
35  
        if (d > ai_gc_scan_maxDistance_reached) ai_gc_scan_maxDistance_reached = d;
36  
        ai_postTriple(key, "has GC distance", formatDouble(d, 1));
37  
      }
38  
    }
39  
  } finally {
40  
    ai_stopBuffering();
41  
  }
42  
  
43  
  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));
44  
}
45  
46  
static void ai_gc_scan_update(Map<S, Double> distances, L<S> queue, WebNode n, double d) {
47  
  //S text = ai_shortenForIndex(web_text(n));
48  
  S text = web_text(n);
49  
  Double od = distances.get(text);
50  
  if (od == null || d < od) {
51  
    distances.put(text, d);
52  
    queue.add(text);
53  
  }
54  
}

Author comment

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: 358 / 394
Version history: 22 change(s)
Referenced in: [show references]