Warning: session_start(): open(/var/lib/php/sessions/sess_ocam6a1i1ul1i14m0uotnot5gj, 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 { time {
centerHigherConsole();
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 = 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));
bot();
}
answer {
U u = followRedirect(nicestClosestKey(wiki, new U(processKey(s))));
if (u != null) {
clearConsole();
print("== " + u + " ==");
print(wiki.get(u));
ret str(u);
}
}
sS followRedirect(S key) {
S next;
while ((next = processKey(wikipedia_getRedirect(wiki.get(key)))) != null)
key = next;
ret key;
}