Warning: session_start(): open(/var/lib/php/sessions/sess_bhc46i664ergrdaif9ckfk3v4q, 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
sclass AICDemo {
settable S snippetID = #1034022;
swappable S makeInputText() { ret loadSnippet_cached(snippetID); }
settable S inputText;
settable S compressedText;
settable S decompressedText;
AdaptiveIdentifierCompression aicComp;
AdaptiveIdentifierCompression aicDecomp;
bool decompressedOK;
S compress() {
if (inputText == null) inputText = makeInputText();
aicComp = new AdaptiveIdentifierCompression;
adapt(aicComp);
new StringBuilder buf;
for (t : javaTok(inputText))
buf.append(aicComp.encode(t));
compressedText = str(buf);
print("Compressed " + nChars(inputText) + " => " + nChars(compressedText) + " = " + doubleRatio(l(compressedText), l(inputText)));
ret compressedText;
}
S decompress() {
aicDecomp = new AdaptiveIdentifierCompression;
adapt(aicDecomp);
new StringBuilder buf;
for (t : javaTok(compressedText))
buf.append(aicDecomp.decode(t));
decompressedText = str(buf);
print("Deompressed " + nChars(compressedText) + " => " + nChars(decompressedText));
if (inputText != null) {
int correct = lCommonPrefix(inputText, decompressedText);
print("Decompressed text correct for " + nChars(correct) + " out of " + nChars(inputText));
decompressedOK = correct == l(inputText) && correct == l(decompressedText));
if (decompressedOK)
print("Decompressed OK");
else
print("First wrong words:\n" +
" " + shorten(substring(inputText, correct)) + "\n" +
" vs " + shorten(substring(decompressedText, correct)));
}
ret decompressedText;
}
swappable void adapt(AdaptiveIdentifierCompression aic) {}
}