Warning: session_start(): open(/var/lib/php/sessions/sess_eihjce1j9pqh6ob0u438pp1evr, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!759
static double aiCacheInterval = 30;
static new ThreadLocal white;
sS searchQueriesUniverse = "crefwbbhvngkmicy";
concept Search {
S q, ip;
}
p {
db();
//loadAIConcepts_alwaysFromDisk = true;
aiConceptsMap_fastLoad = loadTruth_fastLoad = true;
startAIConceptsHere();
startTruthTableHere();
}
html {
long time = sysNow();
white.set(true); // !oneIn(10));
S s = hmobilefix() +
hbody(htmlImpl(uri, params), style := white! ? "background: white" : "background: black; color: white");
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 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, 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, statements);
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);
S load = formatDoubleFull(systemLoad(), 1);
S drive = iceil(userDirDriveFullness()) + "%";
S s = today + " : " + yesterday + " / " + load + " / " + drive;
S exp = "Visitors today: " + today + ", yesterday: " + yesterday + ", system load: " + load + ", drive use: " + drive;
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 " + ahref("?latest=100", "(more)"))
+ ul(map(f aiConceptToHTML, ll));
}
S slogan = p(hsmall(b("The Machine") + " will do useful things really soon :-) " + targetBlank("http://tinybrain.de/1007510", "Source."));
ret htitle("Intelligence Machine")
+ visBox
+ hcenter2(
(white! ? "" : slogan)
+ p(ahref("http://ai1.lol/", hTBImage(white! ? #1007526 : #1002549, "title", "Intelligence Machine")))
+ (white! ? slogan : "")
+ 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(allRelations ? "All Relations (" + l(statements) + ")"
: "Latest Relations (" + l(statements) + " of " + ahref("?allrelations=1", l(allStatements)) + ")")
+ 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)
"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));
}
}