sbool ai_html_wordThoughts_showMem;
static int ai_html_wordThoughts_searchMax = 100;
static S ai_html_wordThoughts(S selectedWord) {
S t = ai_html_triangle();
S title = h3(htmlencode(selectedWord));
new Matches m;
if (swic_trim(selectedWord, "[search]", m)) {
int max = ai_html_wordThoughts_searchMax;
L l = indexedTerms_scoredSearch(m.rest(), max);
ret title
+ p(l(l) > ai_html_wordThoughts_searchMax ? max + "+ search results" : n(l, "search result"))
+ ul(map html_encyclopediaTopic(takeFirst(max, l)));
}
Set ignoredWebs = ai_ignoredWebs();
L nodes = web_nodesNotFromCertainWebs(ignoredWebs, indexedNodes(selectedWord));
L rel1 = web_collectBackwardRelations(nodes);
L rel2 = web_collectForwardRelations(nodes);
//L is = ai_whatIs(selectedWord);
final MultiMap mm = orderedMultiMap(); // HTML -> web id
for (WebRelation r : rel2)
mm.put(ai_textHTML(r) + t + ai_renderNodeHTML(r.b), r.web.globalID);
for (WebRelation r : rel1)
mm.put(ai_renderNodeHTML(r.a) + t + ai_textHTML(r) + t + ai_textHTML(r.b), r.web.globalID);
for (WebNode n : nodes)
if (n instanceof WebRelation)
mm.put(ai_renderNodeHTML(n/WebRelation.a) + t + ai_textHTML(n) + t + ai_textHTML(n/WebRelation.b), n.web.globalID);
L l1 = ll();
Web web = possibleGlobalID(selectedWord) ? ai_getWeb(selectedWord) : null;
if (web != null) {
S link = ai_html_webLink(web.globalID);
bool inv = ai_isInvalidWeb(web);
l1.add(inv ? "is an " + ahref(link, "invalid web") : "is a " + ahref(link, "web"));
}
long nVirtual = ai_numberOfVirtualWebs();
long mem = ai_html_wordThoughts_showMem ? memoryUsedAfterLastGC() : 0;
ret title
+ ul(concatLists(l1, map html_linkURLs_targetBlank(
allToString(
map(multiMapKeysByPopularity(mm), func(S s) {
s + " [" + joinWithComma(map ai_html_linkedWeb(mm.get(s))) + "]"
})
))))
+ p(n(nodes, "node") + " out of " + ahref(smartBotURL(), nWebs(keys(allWebsByID())))
+ (nVirtual == 0 ? "" : " + " + formatWithThousandsSeparator(nVirtual) + " virtual")
+ (mem == 0 ? "" : ". " + toMB(mem) + " MB used"));
}