Warning: session_start(): open(/var/lib/php/sessions/sess_k3spdmbnqq37tes26r34m8lep6, 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
static new TreeMap wiki; // title to text (stored as compressed strings)
sS processKey(S s) { ret toLower(s); }
p-subst { time {
centerHigherConsole();
consoleWordWrap();
File f = unpackSimpleWikipedia();
BufferedReader reader = utf8bufferedReader(f);
S line;
int lines = 0, pages = 0;
StringBuilder pageBuf = null;
while ((line = reader.readLine()) != null) {
/*if ((++lines % 100) == 0)
print("Lines: " + lines);*/
line = trim(line);
if (eq(line, ""))
pageBuf = new StringBuilder;
if (pageBuf != null)
pageBuf.append(line).append("\n");
if (eq(line, "")) {
//print("Page done. " + l(pageBuf) + " chars");
L tok = htmlTok(str(pageBuf));
S title = join(contentsOfContainerTag(tok, "title"));
S text = htmldecode(join(contentsOfContainerTag(tok, "text")));
if (empty(text)) {
// print("No text: " + title);
} else wiki.put(new U(processKey(title)), new U(text));
if ((++pages % 1000) == 0) {
fractionDone(pages/228400.0);
print("Pages: " + pages + " (" + title + ")");
sleep(1);
}
//print(title); // XXX - too much printing hangs AWT (investigate!)
pageBuf = null;
}
}
}
fractionDone(1);
// print a random entry
U n = random(keys(wiki));
print("== " + n + " ==");
print();
print(wiki.get(n));
botSleep();
}
answer {
U u = followRedirect(nicestClosestKey(wiki, new U(processKey(s))));
if (u != null) {
clearConsole();
consoleStatus(str(u));
print("== " + u + " ==");
print(wiki.get(u));
ret str(u);
}
}
static U followRedirect(U key) {
U next;
int count = 0;
while ((next = toU(processKey(wikipedia_getRedirect(str(wiki.get(key)))))) != null && ++count < 10)
key = next;
ret key;
}