!759 static double aiCacheInterval = 30; sS searchQueriesUniverse = "crefwbbhvngkmicy"; concept Search { S q, ip; } p { db(); //loadAIConcepts_alwaysFromDisk = true; startAIConceptsHere(); startTruthTableHere(); } html { long time = sysNow(); S s = hmobilefix() + htmlImpl(uri, params); ret s + p(hsmall((sysNow()-time) + " ms", style := "color: #EEEEEE"), style := "text-align: right"); } static O htmlImpl(S uri, final SS params) { print("Wiki URI: " + uri); S vis = registerVisitor(); 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 (findAIConceptByNameIC(q) == null) { createAIConcept(q, searchQueriesUniverse); //if (!loadAIConcepts_alwaysFromDisk) clearAICaches(); } } if (eq(uri, "import")) { triggerStandardAIImport(); ret "OK" + hrefresh(1, "/wiki/"); } if (eq(uri, "export")) { triggerStandardAIExport(); ret "OK" + hrefresh(1, "/wiki/"); } if (eq(uri, "searches")) { ret htitle_h2("Latest Searches") + htable(map(func(Search s) { litorderedmap(Query := dynamize(s.q), IP := dynamize(s.ip)) }, takeFirst(10, sortedByFieldDesc("lastSeen", list(Search)))), false); } clearAICaches(aiCacheInterval); final Map map = aiConceptsMap_cached(); if (possibleGlobalID(uri)) ret renderConcept(uri, params); // Serve main page S results = ""; if (nempty(q)) { L l = imSearch(q); if (empty(l)) results = h3("No search results for " + htmlencode(quote(q))); else results = h3("Search results for " + htmlencode(quote(q))) + ul(map(f aiConceptToHTML, l)); } L l = sortedByFieldDesc(values(map), "touched"); S search = p("Search term, question or statement:", style := "margin-top: 40px") + hform(htextinput("q", q, autofocus := 1, style := "text-align: center") + " " + hsubmit("Go")); S auth = ""; if (webAuthed()) auth = " " + ahref("/wiki/import", "Import.") + " " + getExportSnippetID(aiConceptsProgram()) + "/" + getExportSnippetID(truthTableProgram()) + ". " + ahref("/wiki/export", "Export."); S line = "See " + ahref("https://www.youtube.com/watch?v=gTlgZkc95IU", "Video") + ". " + ahref("http://ai1.lol/new", htmlencode("More videos & articles")) + "." + auth; bool all = nempty(params.get("all")); L conceptsToShow = all ? l : selectRandomUpTo(l, 100); S concepts = ul(map(f aiConceptToHTML, conceptsToShow)); L statements = reversed(loadTruth_cached()); S relations = ul(map(f statementToHTML, statements)); BigInteger[] ints = extractIntsFromString(vis); S visBox = ""; if (nempty(ints)) { BigInteger today = get(ints, 0), yesterday = get(ints, 2); visBox = hdiv(hsmall(today + " : " + yesterday), style := "position:absolute; top: 2px; right: 2px", title := "Visitors today: " + today + ", yesterday: " + yesterday); } S latest = ""; if (!all) { L ll = takeFirst(3, sortedByFieldDesc(values(map), "created")); latest = h3("Latest concepts") + ul(map(f aiConceptToHTML, ll)); } ret htitle("Intelligence Machine") + visBox + hcenter2( p(ahref("http://ai1.lol/", hTBImage(#1007526, "title", "Intelligence Machine"))) + p(hsmall(b("The Machine") + " will do useful things really soon :-) " + targetBlank("http://tinybrain.de/1007510", "Source."))) + search) + (empty(line) ? "" : p(line)) + results + htableRaw_valignTop(ll(ll( latest + h3( (all ? "Concepts (" + lstr(l) : "Random concepts (" + l(conceptsToShow) + " of " + ahref("?all=1", l(l))) + ")") + concepts, h3("Relations (" + l(statements) + ")") + relations)), "border", "0") ; } static S aiConceptToHTML(AIConcept c) { ret (nempty(c.imageMD5) ? "[w/image] " : hasSuggestedImage(c) ? "[w/sugg. image] " : "") + dynamize(c.globalID) + " - " + htmlencode(aiConceptToString2(c)); } static S statementToHTML(Statement s) { ret ahref("http://ai1.lol/" + s.globalID, "*") + " " + dynamize(or2(s.possibleEnglishTranslation, "?") + " - " + s.text); } sS renderConcept(S uri, SS params) { // Serve concept final Map map = aiConceptsMap_cached(); final AIConcept c = map.get(toLower(uri)); Statement st = findWhere(loadTruth_cached(), globalID := toLower(uri)); if (st != null) ret renderStatement(c, st, params); 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) "Touched: " + formatDateAndTime(c.touched), "Imported: " + formatDateAndTime(c.imported) ); if (nempty(c.imageMD5) && imageServerHas(c.imageMD5)) html += p(himg(imageServerJPEGLink(c.imageMD5))); if (hasSuggestedImage(c)) { BufferedImage img = c.suggestedImage->getImage(); uploadToImageServerIfNotThere(img, aiConceptToString(c)); html += h3("Suggested image (from Google search)") + p(himg(imageServerJPEGLink(imageMD5(img)))); } //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", "[Home]")); ret html; } sS renderStatement(AIConcept c, Statement st, SS params) { if (nempty(params.get("retranslate"))) { RemoteDB db = new RemoteDB(truthTableProgram()); db.xset(db.rc(st.id), possibleEnglishTranslation := null); db.close(); st.possibleEnglishTranslation = null; } bool hasTranslation = nempty(st.possibleEnglishTranslation); S html = htitle_h2("Statement " + st.globalID) + ul( "English (machine-generated): " + dynamize(or2(st.possibleEnglishTranslation, "?")), "Computer Language: " + dynamize(st.text), (c != null ? "also a concept" : null)) + (!hasTranslation ? "" : p(ahref("?retranslate=1", "Request retranslation"))); html += p(ahref("http://ai1.lol/wiki", "[Home]")); ret html; }