Warning: session_start(): open(/var/lib/php/sessions/sess_vdokgng912233r5e59cd7mg39a, 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
!7
sbool greetCookies, theoryOn;
static new L thoughtBots;
static long started;
static Class theoryModule;
static Lock theoryLock = lock();
static double delay = 0;
static S selectedWord;
static int myPort = 4678;
p {
started = sysNow();
db();
load('selectedWord);
autoRestart(5);
serveHttp(myPort);
typicalDownload();
bot("Smart Bot.");
loadPage_forcedTimeout = 70000;
thoughtBots.add(mc());
loadBots(#1010753, #1010821, #1010825, #1001951);
stefansChat_n_onChange(r {
clearTransientWebs();
addTransientWeb(webFromTriple("Latest chat line", "is", "Chat line " + stefansChat_n_value));
});
stefansChat_onLine_lookback = 2;
stefansChat_onLine_onHistoryRead.set(f onHistoryRead);
stefansChat_onLine_safe(voidfunc(S text) {
sleepSeconds(delay);
print("> " + text);
pcall {
int nr = toInt(mapGet(stefansChat_onLine_fullParams!, "nr"));
if (nr != 0) {
S x = "Chat line " + nr;
ai_postTriple(x, "is", quote(text));
ai_postTriple(x, "is", "recent");
stefansChat_n_notify(nr);
}
}
S answer = scanMultipleBots(thoughtBots, text);
if (nempty(answer))
postToStefansChat(answer);
});
//stefansChat_post("Smart Bot Upgraded! Boot took: " + formatDouble(fromMS(sysNow()-started), 1) + " s");
if (greetCookies) runInNewThread(#1010793); // Post on UAIP
loadTheory();
}
svoid loadTheory {
lock theoryLock;
cleanUp(theoryModule);
theoryModule = null;
if (!theoryOn) ret;
theoryModule = run(#1010963);
setOpt(theoryModule, 'onUpdate, r { call(theoryModule, 'react) });
call(theoryModule, 'react);
print("Theory module loaded.");
}
static int lineCount;
sbool authed() {
ret isTrue(mapGet(stefansChat_onLine_fullParams!, 'auth));
}
answer {
++lineCount;
bool authed = authed();
lock dbLock();
int safety = 0;
replaceloop: while (safety++ < 10) {
s = trim(s);
if (authed) {
if (lineCount >= stefansChat_onLine_lookback) {
if (eqic(s, "!restart")) { restart(); ret "Yo"; }
if (eqic(s, "!theory")) ret "OK" with loadTheory();
if (swic_trim(s, "!theory ", m))
ret callAnswerFunction(theoryModule, m.rest());
if (eqic(s, "!peep")) {
runAndCleanUp(#1010980);
ret "OK, got " + fileLength(ai_chatAnalysis_peepHoleFile()) + " bytes";
}
}
if "unlearn * *"
ret "OK, was: " + uniq(MatchLearner, pattern := $1).examples.put($2, 'rejected);
}
if "Are you online?" ret "Yes";
if (eqicOneOf(s, "!question", "!gac"))
ret random_gac36k();
if (swic_trim(s, "!word ", m)) {
selectedWord = $1;
save('selectedWord);
processSelectedWord();
ret "OK";
}
if (swic_trim(s, "!google ", m))
ret join(" - ", swapPair(first(quickGoogle($1))));
if (swic_trim(s, "!has-triple ", m)) {
Triple t = ai_parseArrowTriple(m.rest());
ret yn(ai_cache_hasTriple(t));
}
if (swic_trim(s, "!triple ", m) || swic_trim(s, "!triples ", m)) {
L elements = trimAll(splitAt(m.rest(), "->"));
if (l(elements) != 3) ret "3 parts please";
ret "[IMAGE] " + "http://ai1.lol/1007546?triples=" + urlencode(lines(elements));
}
if (swic_trim(s, "!web ", m)) {
S id = $1;
Web web = indexedWebWithGlobalID(id);
if (web == null) ret "Not found";
ret "[IMAGE] http://ai1.lol:" + myPort + "/diagram?id=" + id;
}
if (swic_trim(s, "!parse ", m))
ret ai_renderTriple(ai_tripelize(m.rest()));
if (eqic(s, "!uptime"))
ret n(secondsSinceSysTime(started), "second");
if (eqic(s, "!typical-set"))
ret sfu(diagramServer_typicalSet());
if (eqic(s, "!num-unverified"))
ret lstr(ai_unverifiedWebs());
if (swic_trim(s, "!store ", m))
ret postTripleFromInput(ai_tripelize(m.rest()), s);
if (swic_trim(s, "!store-triple ", m))
ret postTripleFromInput(ai_parseArrowTriple(m.rest()), s);
if (swic(s, "!nodes ", m)) {
if (dropSuffixTrim("...", m.rest(), m))
ret lstr(indexedNodesStartingWith(m.rest()));
ret lstr(indexedNodes(m.rest()));
}
if (eqic(s, "!webs"))
ret lstr(allIndexedWebs());
if (swic(s, "!webs ", m))
ret joinWithSpace(collect(indexedWebs($1), 'globalID));
if (swic(s, "!splitAtBaseFormVerb ", m))
ret sfu(splitAtBaseFormVerb($1));
if (swic(s, "!maxRunlengthOfRepeatingChars ", m))
ret str(maxRunlengthOfRepeatingChars($1));
if (swic(s, "!collapseWord ", m))
ret collapseWord($1);
if (swic(s, "!gac ", m))
ret or2(first(scoredSearch(m.get(0), keys(gac36k()))), "-");
if (swic_trim(s, "!macmillan ", m)) try {
Pair> p = macmillanDefinitions3(m.rest());
ret toUpper(p.a) + "\n" + lines(prependAll("-", p.b));
} catch e {
printShortException(e);
ret "Macmillan is quiet today.";
}
s = ai_dropLeadingAdditions(s);
if "cache size"
ret n(keys(cachedNodeIndex()), "different term")
+ ", " + n(web_countNodes(allWebs_cached()), "node")
+ ", " + n(allWebs_cached(), "web");
if "give me subtypes of ..."
ret ai_renderList(ai_subtypesOf(m.rest()));
if "give me a third person verb"
ret random(thirdPersonVerbs());
if (learnedFlexMatch("give me some *", s, m)) {
S query = singular($1);
ret ai_renderNodesList(concatLists(
ai_index_search_dollarX("$X", "is a", query),
ai_index_search_dollarX("$X", "is", a(query))));
}
if "authed?"
ret authed ? "You are authed." : "You are not authed.";
if "what is the singular of *"
ret or2(getSingularFromWordHippo($1), singular($1));
if (learnedFlexMatch("what is the relation between * and *", s, m)) {
L l = ai_getRelation($1, $2);
//ret ai_renderList(l);
if (nempty(l)) ret $1 + " " + first(l) + " " + $2;
}
if "what unix day is it"
ret str(unixDay());
if "show me the ..."
ret "What " + $1 + "?";
if (learnedFlexMatch("What do * have?", s, m))
ret ai_renderNodesList(ai_index_search_dollarX($1, "have", "$X"));
if (learnedFlexMatch("What does * do?", s, m))
ret ai_renderList(map(f web_nodePairToText, webs_search_dollarXY(webFromTriples($1, "$X", "$Y"), indexedWebs($1))));
if (learnedFlexMatch("What is *", s, m) | learnedFlexMatch("Who is *", s, m))
try answer ai_renderNodesList(ai_whatIs($1), "");
S sf = web_text(first(webs_search_dollarX(webFromTriples("$X", "implements", quote(s)), indexedWebs(quote(s)))));
if (startsWith(sf, "sf ", m))
ret str(makeAndCall($1));
if (learnedFlexMatch("* how many visitors *", s) || match("how many visitors", s))
ret str(ai1_cookiesToday_int());
// Once more with generated webs (replacing $ vars)
if (learnedFlexMatch("What is *", s, m)) {
L extendedWebs = indexedWebsAfterVariableSubstitution($1);
print("Have " + n(extendedWebs, "extended web") + " for " + quote($1));
ret ai_renderNodesList(webs_search_dollarX(webFromTriples($1, "is", "$X"), extendedWebs), "I don't know");
}
S match;
if (!ai_isQuestion_1(s) && learnedFlexMatch(match = "* is *", s, m))
ret postTripleFromInput(triple($1, "is", $2), s);
for (WebNode node : indexedNodes(s)) {
S x = web_operandText(node, "replace with");
if (x != null) {
print("Replacing with " + x);
s = x;
continue replaceloop;
}
}
break;
}
if (ai_isQuestion_1(s)) ret "No idea";
}
svoid loadBots(S... botIDs) {
for (S id : botIDs) pcall {
thoughtBots.add(runSubBot(id));
}
}
// s = uri
static O html(S s, SS params) {
if "thoughts"
ret serveHTML(html_thoughts());
if "diagram" {
S id = params.get("id");
Web web = indexedWebWithGlobalID(id);
ret serveJPEG(webToCAL(web).makeImage(600, 400));
}
if "log"
ret serveText_direct(printLog());
if "learners"
ret serveText_direct(renderConcepts(list(MatchLearner)));
// Serve Web With Global ID
s = dropPrefix("/", s);
if (possibleGlobalID(s)) {
L webs = allWebsByID().get(s);
if (nempty(webs)) {
ret h2_title("Web " + s)
+ pre(htmlencode(renderWeb_multiLine(first(webs))))
+ p(himg(ai_webImage_link(s), title := "Web " + s))
+ (l(webs) > 1 ? p("Warning: Multiple webs") : "");
}
if (theoryModule == null) ret serveHTML("Loading theory module");
Map map = (Map) getOpt(theoryModule, 'theoryForLineMap);
if (map.containsKey(toLower(s)))
ret serveHTML("A line in the chat.");
ret serveHTML("Unknown: " + s);
}
new Matches m;
if (swic(s, "e/", m)) {
S topic = urldecode(m.rest());
ret h1_title(htmlencode_noQuote("Topic: " + topic))
//+ p("Have " + n(indexedWebs(topic), "web")))
+ ai_html_wordThoughts(topic);
}
if (eqic(s, "alphabetical"))
ret html_alphabetical();
if (eqic(s, "latest-webs"))
ret html_latestWebs();
// Home Page
Collection keys = multiMapKeysByPopularity(cachedNodeIndex());
ret h1_title("Smart Bot's Encyclopedia :)")
+ p("Most occurring | "
+ ahref("/alphabetical", "Alphabetical") + " | "
+ ahref("/latest-webs", "Latest"))
+ ul(map(func(S s) {
ahref(smartBot_encyclopediaLink(s), htmlencode(or2(s, "-")))
+ " [" + l(indexedNodes(s)) + "]"
}, keys));
}
static S html_alphabetical() {
ret h1_title("Smart Bot's Encyclopedia :)")
+ ul(map(func(S s) {
ahref(smartBot_encyclopediaLink(s), htmlencode(or2(s, "-")))
}, keys(cachedNodeIndex())));
}
static S html_latestWebs() {
ret h1_title("Smart Bot's Encyclopedia - Latest Webs")
+ ul(map(func(Web web) { ai_html_linkedWeb(web) + htmlencode(" [" + web.created + " - " + renderGMTDate(web.created) + "] " + web.source + ": " + webToStringShort(web)) },
takeFirst(10, sortByFieldDesc('created, allWebsFromCachedNodeIndex()))));
}
sS html_thoughts() {
S html = /*hrefresh(5) +*/ hGoogleFontOswald();
ret html + wordThoughts();
/*
if (theoryModule == null)
ret html + "Loading theory module...";
S thoughts = (S) call(theoryModule, 'html_thoughts);
if (nempty(selectedWord))
ret html + tag('table, tr(td_top(thoughts, style := "background: #CCC") + td_top(wordThoughts(), style := "padding-left: 20px")));
ret html + thoughts;
*/
}
sS wordThoughts() {
try {
if (empty(selectedWord)) ret "";
ret html_addTargetBlank(ai_html_wordThoughts(selectedWord));
} catch e {
printStackTrace(e);
ret "Erreur";
}
}
sS postTripleFromInput(T3 triple, S input) {
if (ai_cache_hasTriple(triple))
ret "I know";
else {
Web web = webFromTriple(triple);
web.unverified = !authed();
postSoftwareMadeWeb(web, +input);
ret "OK, stored " + (web.unverified ? " (unverified)" : "") + ": " + ai_renderTriple(triple);
}
}
svoid processSelectedWord {
if (empty(selectedWord)) ret;
pcall {
ai_greetingRule1(selectedWord);
if (ai_hasTriple(selectedWord, "should be", "answered by me")
&& ai_postTriple(selectedWord, "was", "answered by me") != null) {
S text = firstQuoted(web_texts(ai_search_dollarX(selectedWord, "is", "$X")));
postToStefansChat((nempty(text) ? text + " << " : "") + "Greetings back to you!");
}
}
}
svoid makeChatLinesUnrecent {
new Matches m;
for (WebNode n : ai_search_dollarX("$X", "is", "recent"))
if (match("Chat line *", web_text(n), m)) pcall {
int n = parseInt($1);
if (n <= stefansChat_n_value-100) {
print("Unrecenting " + n);
ai_invalidateWeb(n.web);
}
}
}
svoid onHistoryRead {
lock dbLock();
print("History read.");
processSelectedWord();
pcall { makeChatLinesUnrecent(); }
}