!7 static double aiConceptsCacheInterval = 60; concept Search { S q, ip; } p { db(); } html { print("Wiki URI: " + uri); uri = dropSuffix("/", uri); uri = dropPrefix("/", uri); if (eq(uri, "sleep")) { sleepSeconds(5); ret "Slept 5, just for you."; } S q = trim(params.get("q")); if (nempty(q)) cset(uniq(Search, +q, ip := getClientIP()), lastSeen := now()); if (eq(uri, "import")) { triggerStandardAIImport(); ret "OK"; } if (eq(uri, "searches")) { ret htitle_h2("Latest Searches") + htable(map(func(Search s) { litorderedmap(Query := dynamize(s.q), IP := dynamize(s.ip)) }, takeLast(10, sortedByFieldDesc("lastSeen", list(Search)))), false); } aiConceptsMap_clearCache(aiConceptsCacheInterval); final Map map = aiConceptsMap_cached(); if (possibleGlobalID(uri)) { // Serve concept final AIConcept c = map.get(toLower(uri)); if (c == null) ret "Concept not found: " + toLower(uri); S html = htitle(c.name + " [" + (nempty(c.comment) ? c.comment + " / " : "") + c.globalID + "]") + h2(htmlencode(aiConceptToString(c))); /*html += ul( "Image MD5: " + htmlencode(c.imageMD5) );*/ if (nempty(c.imageMD5) && imageServerHas(c.imageMD5)) html += p(himg(imageServerLink(c.imageMD5))); //L statements = [S s : trueStatements_cached() | containsIgnoreCase(s, c.globalID)]; L statements = [Statement s : loadTruth_cached() | containsIgnoreCase(s.text, c.globalID)]; if (nempty(statements)) html += h3("Statements about this") + ul(map(f statementToHTML, statements)); html += p(ahref("http://ai1.lol/wiki", "[All Concepts]")); ret html; } S results = ""; if (nempty(q)) { L l = imSearch(q); if (empty(l)) results = h3("No search results for " + quote(q)); else results = h3("Search results for " + quote(q)) + ul(map(f aiConceptToHTML, l)); } L l = sortedByFieldDesc(values(map), "imported"); S search = p("Search (coming up)") + hform(htextinput("q", "", autofocus := 1, style := "text-align: center") + " " + hsubmit("Search")); S line = ""; if (empty(results)) line = "See " + ahref("https://www.youtube.com/watch?v=gTlgZkc95IU", "Video") + "." + (webAuthed() ? " " + ahref("/wiki/import", "Import.") : ""); S concepts = ul(map(f aiConceptToHTML, l)); S relations = ul(map(f statementToHTML, reversed(loadTruth_cached()))); ret htitle("Intelligence Machine") + hcenter2( p(ahref("http://ai1.lol/wiki", hTBImage(#1007526, "title", "Intelligence Machine"))) + search) + results + (empty(line) ? "" : p(line)) + htableRaw_valignTop(ll(ll( h3("Concepts") + concepts, h3("Relations") + relations)), "border", "0"); } static S aiConceptToHTML(AIConcept c) { ret dynamize(c.globalID) + " - " + htmlencode(aiConceptToString2(c)); } static S statementToHTML(Statement s) { ret dynamize(or2(s.possibleEnglishTranslation, "?") + " - " + s.text); }