!752 static bool compileLua = true; static JTextArea ta1, ta2; static bool needUpdate = true; static O sucker; static S desc; static double score; // abusing this for pre-making and caching a single instance static TimedCache trainedAlgo = new TimedCache(0); // no expire p { sucker = run("#1004698"); desc = (S) call(sucker, "highestDesc"); score = (double) call(sucker, "highestScore"); JFrame frame = showFrame("\*programTitle()*/ (Score: \*formatDouble(score, 1)*/%)", vgrid(ta1 = new JTextArea, ta2 = new JTextArea)); addMenu(frame, "Stuff", "Show original text", r { showOriginalText() }); onUpdate(ta1, r { needUpdate = true; }); final new SingleThread st; installTimer(ta2, 100, r { if (needUpdate && !st.running()) { needUpdate = false; st.go(r { luaCompile(compileLua); Algorithm algo = getTrainedAlgo(); trainedAlgo.clear(); final S t = ta1.getText(); final S text = autoPredict(t, algo, 100); awt { ta2.setText(t + text); ta2.setCaretPosition(0); } getTrainedAlgo(); // make new one for next time }); } }); } static void feedText(S text, Algorithm algo) { int n = l(text); for (int pos = 0; pos < n; ) { S s = algo.predict(n-pos); if (empty(s)) s = " "; // We're lenient int j = min(pos+l(s), n); algo.feed(substring(text, pos, j)); pos = j; } } static Algorithm getTrainedAlgo() { ret trainedAlgo.get(func { makeTrainedAlgo() }); } static S autoPredict(S text, Algorithm algo, int max) { feedText(text, algo); new StringBuilder buf; int pos = 0; S s = null; while (pos < max) { if (s != null) algo.feed(s); s = algo.predict(max-pos); if (empty(s)) s = " "; // We're lenient s = substring(s, 0, max-pos); buf.append(s); pos += l(s); } ret str(buf); } static Algorithm makeTrainedAlgo() { Algorithm algo = makeLuaTextPredictAlgo(desc); Class intrface = _getClass(sucker, "main$Algorithm"); assertNotNull("main$Algorithm", intrface); O proxy = proxy(intrface, algo); call(sucker, "scoreAlgorithm", proxy); // train ret algo; } svoid showOriginalText { showText("Original Text", (S) getOpt(sucker, "text")); }