!759 static double aiCacheInterval = 30; static new ThreadLocal white; static new ThreadLocal ctc; sS searchQueriesUniverse = "crefwbbhvngkmicy"; concept Search { S q, ip; } concept CookieToConcept { S cookie, concept; *() { if (!_loading()) concept = aGlobalID(); } } p { db(); //loadAIConcepts_alwaysFromDisk = true; aiConceptsMap_fastLoad = loadTruth_fastLoad = true; startAIConceptsHere(); startTruthTableHere(); } html { long time = sysNow(); white.set(false); // !oneIn(10)); S cookie = cookieFromUser(); CookieToConcept ctc = null; if (nempty(cookie)) { ctc = uniq(CookieToConcept, +cookie); if (!hasAIConcept(ctc.concept)) createAIConcept_listed(ctc.concept, "-> an anonymous cookie", "created automatically", searchQueriesUniverse); } main.ctc.set(ctc); S s = hmobilefix() + hcommentSafe("Cookie: " + cookie + (ctc != null ? ", concept: " + ctc.concept : "")) + (white! ? "" : hcss("a:link, a:visited, a:hover, a:active { color: white; }")) + hbody(htmlImpl(uri, params), style := white! ? "background: white" : "color: white; background-image: url(\"" + snippetImageGIFURL(#1007679) + "\"); background-repeat: no-repeat; background-position: 50% 0; background-color: #262626"); 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); processActions(params); if (eq(uri, "sleep")) { sleepSeconds(5); ret "Slept 5, just for you."; } S q = trim(params.get("q")); S qname = q, qcomment = ""; new Matches m; if (flexMatch("* [*]", q, m)) { qname = $1; qcomment = $2; } if (nempty(q)) { cset(uniq(Search, +q, ip := getClientIP()), lastSeen := now()); if (findAIConceptByNameAndCommentIC(qname, qcomment) == null) { createAIConcept(qname, qcomment, 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 question = ""; pcall { question = makeQuestion(); question = toUpper(conceptLanguageToEnglish_xyz_noquote(question)); } S search = p("Search term, question or statement:", style := "margin-top: 40px") + hform( htextinput("q", q, autofocus := 1, style := "text-align: center") + " " + hsubmit("Go"), "accept-charset" := "UTF-8"); 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, 25); S concepts = ul(map(f aiConceptToHTML, conceptsToShow)); L allStatements = reversed(loadTruth_cached()); bool allRelations = nempty(params.get("allrelations")); L statements = allRelations ? allStatements : takeFirst(30, allStatements); S relations = ul(map(f statementToHTML, statements)); BigInteger[] ints = extractIntsFromString(vis); BigInteger today = getBigInt(ints, 0), yesterday = getBigInt(ints, 2); S load = formatDoubleFull(systemLoad(), 1); S drive = iceil(userDirDriveFullness()) + "%"; S s = ""; S userConcept = ctc! != null ? ctc->concept : ""; if (nempty(userConcept)) s = "You are: " + dynamize(userConcept) + " / "; s += today + " : " + yesterday + " / " + load + " / " + drive; S exp = "Visitors today: " + today + ", yesterday: " + yesterday + ", system load: " + load + ", drive use: " + drive; S visBox = hdiv(hsmall(s), style := "position:absolute; top: 2px; right: 2px", title := exp); S latest = ""; int nLatest = parseIntOpt(params.get("latest")); if (nLatest != 0) nLatest = min(nLatest, 1000); else nLatest = 3; if (!all) { L ll = takeFirst(nLatest, sortedByFieldDesc(values(map), "created")); latest = h3("Latest concepts " + (nLatest < 100 ? ahref("?latest=100", "(more)") : "")) + ul(map(f aiConceptToHTML, ll)); } S slogan = p(span(l(l) + " Concepts", style := "font-size: 40px") + "
" + hsmall(b(ahref("http://ai1.lol/", b("THE MACHINE")) + " " + ahref(progLink(#1007674), "understands Fibonacci numbers") + ", " + ahref(progLink(#1007649), "letters to mom") + " and " + ahref(progLink(#1007814), "Scandinavian breakfast") + " :-)") + "

" + "We're working on reducing the insanity. " + ahref("mailto:info@ai1.lol", "Info.") + " " + ahref("https://www.meetup.com/Artificial-Intelligence-Meetup/", "Hamburg.") + " " + ahref("https://slides.com/stefanreich/magnus_carlsens_breakfast", "New presentation.") // + b(ahref("http://tinybrain.de/1007649", "Demo 1.") + " " // + ahref("http://tinybrain.de/1007674", "Demo 2.")) ); ret htitle("Intelligence Machine") + visBox + hdiv(visitorsChart(""), style := "position:absolute; left: 2px; right: 2px; width: 150px; height: 110px;", title := "Visitors Chart") + hcenter2( (white! ? "" : slogan) + (white! ? p(ahref("http://ai1.lol/", hTBImage(white! ? #1007526 : #1002549, "title", "Intelligence Machine"))) : "") + (white! ? slogan : "") + p(dynamize(question)) + search) + (empty(line) ? "" : p(line)) + results //+ hcenter2(latestDrawing() + randomDrawing()) + hcenter2(htableRaw_valignTop(ll(ll(latestDrawing(), randomDrawing())), "cellspacing", 20)) + "
" + htableRaw_valignTop(ll(ll( latest + h3( (all ? "Concepts (" + lstr(l) : "Random concepts (" + l(conceptsToShow) + " of " + ahref("?all=1", l(l))) + ")") + concepts, hdiv(_defaultAd(), style := "float: right; margin: 10px") + h3(allRelations ? "All Relations (" + l(statements) + ")" : "Latest Relations (" + l(statements) + " of " + ahref("?allrelations=1", l(allStatements)) + ") - We really need to clean them up ^^") + relations)), "border", "0") ; } static S aiConceptToHTML(AIConcept c) { ret (nempty(c.imageMD5) ? "[w/image] " : hasSuggestedImage(c) ? "[w/sugg. image] " : "") + dynamize(c.globalID) + " - " + dynamize(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(dynamize(aiConceptToString(c))); html += ul( //"Image MD5: " + htmlencode(c.imageMD5) "Created: " + formatDateAndTime(c.created), "Touched: " + formatDateAndTime(c.touched), c.imported != 0 || nempty(c.importedFrom) ? "Imported: " + formatDateAndTime(c.imported) + " from " + dynamize(c.importedFrom) : null ); if (nempty(c.imageMD5) && imageServerHas(c.imageMD5)) html += p(himg(imageServerJPEGLink(c.imageMD5))); if (c.suggestedImage.has()) { print("PNG path: " + c.suggestedImage->pngPath); BufferedImage img = c.suggestedImage->getImage(); if (img != null) { uploadToImageServerIfNotThere(img, aiConceptToString(c)); if (empty(c.suggestedImageMD5)) c.suggestedImageMD5 = imageMD5(img); } } if (nempty(c.suggestedImageMD5)) html += h3("Suggested image (from Google search)") + p(himg(imageServerJPEGLink(c.suggestedImageMD5)); L statements = [Statement s : loadTruth_cached() | containsIgnoreCase(s.text, c.globalID)]; if (nempty(statements)) html += h3("Statements about this") + ul(map(f statementToHTML, statements)); Map nodes = allNodes(); html += h3("Add forward relation") + hform( hhidden(action := "addRelation") + hhidden(concept1 := c.globalID) + htableRaw_valignTop(ll( ll("Relation Concept", hselectNode(map, "pggfeqzkqnezzfto", name := "rel")), ll("Concept 2", hselectNode(nodes, name := "concept2", allowEmpty := true)), ll("", hsubmit("Create relation")) ))); html += p(ahref("http://ai1.lol/wiki", "[Home]")); ret html; } sS hselectNode(Map map, O... params) { ret hselect(orderMapByValue(mapValues(f nodeToString, map)), params); } 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), st.imported != 0 || nempty(st.importedFrom) ? "Imported: " + formatDateAndTime(st.imported) + " from " + dynamize(st.importedFrom) : null) + (!hasTranslation ? "" : p(ahref("?retranslate=1", "Request retranslation"))); html += p(ahref("http://ai1.lol/wiki", "[Home]")); ret html; } svoid processActions(SS params) { S action = params.get("action"); if (eq(action, "addRelation")) { S id1 = params.get("concept1"); S id2 = params.get("concept2"); S rel = params.get("rel"); if (nempty(id1) && nempty(rel)) createStatement(conceptQuote(rel) + " " + conceptQuote(id1) + " " + conceptQuoteOpt(id2)); } } static S latestDrawing() { L metas = getDrawings(); ret empty(metas) ? "" : h3("Latest Drawing") + renderDrawing(first(metas)); } sS renderDrawing(O meta) { ret p(renderMeta(meta) + "
" + hsmall(ahref(progLink(#1007609), "Make your own.") + " " + ahref("http://ai1.lol/images", "More drawings."))); } static S randomDrawing() { O meta = random(dropFirst(getDrawings())); if (meta == null) ret ""; ret h3("Random Drawing") + renderDrawing(meta); } static L getDrawings() { pcall { O imageServer = getBot(#1004590); L metas = cast call(get(imageServer, "mainConcepts"), "list", "ImageMeta"); metas = [O meta : metas | startsWithIC(getString(meta, "name"), "Drawing ")]; metas = sortedByFieldDesc(metas, "created"); ret metas; } ret ll(); } static S renderMeta(O meta) { S md5 = getString(meta, "md5"); S jpg = imageServerJPEGLink(md5); ret ahref(jpg, himg(jpg, //style := "zoom: 50%" // works only on Chrome onload := "this.width *= 0.7; this.onload=null;" )); } !include #1007812 // Question Maker