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

89
LINES

< > BotCompany Repo | #1011308 // ai_html_wordThoughts (LIVE)

JavaX fragment (include)

1  
sbool ai_html_wordThoughts_showMem = true;
2  
static int ai_html_wordThoughts_searchMax = 100;
3  
static int ai_html_wordThoughts_nodesMax_default = 1000;
4  
static new ThreadLocal<Int> ai_html_wordThoughts_nodesMax;
5  
6  
static S ai_html_wordThoughts(S selectedWord) {
7  
  ret ai_html_wordThoughts(ll(selectedWord));
8  
}
9  
10  
static S ai_html_wordThoughts(L<S> selectedWords) {
11  
  lock aiLock();
12  
  int shrt = 80; // max length of entries shown
13  
  Int oldShrt = setThreadLocal(ai_html_shortenTextForDisplay_length, shrt);
14  
  try {
15  
    S t = ai_html_triangle();
16  
    S selectedWord = first(selectedWords);
17  
    S title = p(span(htmlencode(selectedWord), id := "title", style := "font-size: 25px") + " " + ahref(smartBot_matrixLink(selectedWord), "[Matrix]"));
18  
    
19  
    new Matches m;
20  
    if (swic_trim(selectedWord, "[search]", m)) {
21  
      int max = ai_html_wordThoughts_searchMax; 
22  
      L<S> l = indexedTerms_scoredSearch(m.rest(), max+1);
23  
      ret title
24  
        + p(l(l) > ai_html_wordThoughts_searchMax ? max + "+ search results" : n(l, "search result"))
25  
        + ul(map html_encyclopediaTopic(takeFirst(max, l)));
26  
    }
27  
    
28  
    new L<WebNode> nodes;
29  
    int max = or(ai_html_wordThoughts_nodesMax!, ai_html_wordThoughts_nodesMax_default);
30  
    Set<S> ignoredWebs = ai_ignoredWebs();
31  
    for (S word : selectedWords) {
32  
      nodes.addAll(web_nodesNotFromCertainWebs(ignoredWebs, indexedNodes(word)));
33  
      if (l(nodes) >= max) break;
34  
    }
35  
    int realN = l(nodes);
36  
    truncateList(nodes, max);
37  
      
38  
    L<WebRelation> rel1 = web_dropConfirmedPossibles(web_collectBackwardRelations(nodes));
39  
    L<WebRelation> rel2 = web_dropConfirmedPossibles(web_collectForwardRelations(nodes));
40  
  
41  
    final MultiMap<S> mm1 = orderedMultiMap(); // HTML -> web id
42  
    final MultiMap<S> mm2 = orderedMultiMap();
43  
    final MultiMap<S> mm3 = orderedMultiMap();
44  
45  
    for (bool invalid : ll(false, true)) {
46  
      for (WebRelation r : ai_sortRelationsByImportance(ai_filterInvalid(invalid, rel2)))
47  
        mm1.put(t + " " + ai_textHTML(r) + t + ai_renderNodeHTML(r.b), r.web.globalID());
48  
        
49  
      for (WebRelation r : ai_sortRelationsByImportance(ai_filterInvalid(invalid, rel1)))
50  
        mm2.put(ai_renderNodeHTML(r.a) + t + ai_textHTML(r) + t + ai_textHTML(r.b), r.web.globalID());
51  
      
52  
      if (!invalid)
53  
        for (WebNode n : nodes)
54  
          if (n instanceof WebRelation)
55  
            mm3.put(ai_renderNodeHTML(n/WebRelation.a) + t + ai_textHTML(n) + t + ai_textHTML(n/WebRelation.b), n.web.globalID());
56  
    }
57  
        
58  
    // l1 is for web stuff
59  
    L<S> l1 = ll();
60  
    Web web = ai_getWebFromTerm(selectedWord);
61  
    if (web != null) {
62  
      S link = ai_html_webLink(web.globalID());
63  
      bool inv = ai_isInvalidWeb(web);
64  
      l1.add(inv ? "is an " + ahref(link, "invalid web") : "is a " + ahref(link, "web"));
65  
    }
66  
    
67  
    new L<S> lists;
68  
    if (nempty(l1)) lists.add(ul(l1));
69  
    for (final MultiMap<S> mm : ll(mm1, mm2, mm3))
70  
      lists.add(ul(map html_linkURLs(
71  
        allToString(
72  
          map(multiMapKeysByPopularity(mm), func(S s) {
73  
            L<S> webIDs = mm.get(s);
74  
            ret s + " [" + joinWithComma(map ai_html_linkedWebWithThumbs(webIDs)) + "]";
75  
          })
76  
      ))));
77  
    
78  
    //long nVirtual = ai_numberOfVirtualWebs();
79  
    long mem = ai_html_wordThoughts_showMem ? memoryUsedAfterLastGC() : 0;
80  
    ret title
81  
      + (realN > max ? p("List truncated (" +  n(realN, "total node") + ")") : "")
82  
      + lines(lists)
83  
      + p(n(nodes, "node") + " out of " + ahref(smartBotOfficialURL(), nWebs(ai_allWebsCount())) + (loading() ? " (LOADING)": "")
84  
        //+ (nVirtual == 0 ? "" : " + " + formatWithThousandsSeparator(nVirtual) + " virtual")
85  
        + (mem == 0 ? "" : ". " + toMB(mem) + " MB used. " + toM(freeSystemMemory()) + " MB free");
86  
  } finally {
87  
    ai_html_shortenTextForDisplay_length.set(oldShrt);
88  
  }
89  
}

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: #1011308
Snippet name: ai_html_wordThoughts (LIVE)
Eternal ID of this version: #1011308/83
Text MD5: 2cc6b1dbe5422e9e8a8373f16a229181
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-01-02 01:18:23
Source code size: 3911 bytes / 89 lines
Pitched / IR pitched: No / No
Views / Downloads: 521 / 549
Version history: 82 change(s)
Referenced in: [show references]