Uses 911K of libraries. Click here for Pure Java version (16421L/91K).
!7 cmodule TrainableBot > DynSockPuppetConvo { delegate Post to JChatConvo. LS suggestions; S functions; transient SingleComponentPanel scpSuggestions; transient FunctionsLoader loader; transient Thread playThread; start { onPostAdded.add(post -> startPlaying()); loadIfNotLoaded(); } visual jvsplit(super, withMargin(jhsplit( jCenteredSection("Suggestions", scpSuggestions = singleComponentPanel(renderSuggestions())), northAndCenterWithMargin( jrightaligned(jbutton("Load", rThreadEnter loadFunctions)), dm_textAreaAsSection functions())))); JComponent renderSuggestions() { ret ele_renderSuggestions(null, suggestions, sayAction := (IVF1<S>) s -> { addPost(s, true); dm_say(s); }, submitAction := (IVF1<S>) s -> { addPost(s, false); dm_say(s); }); } void showSuggestions(Cl<S> suggestions) { setField(suggestions := asList(suggestions)); showSuggestions(); } void showSuggestions { scpSuggestions?.setComponent(renderSuggestions()); } void loadFunctions { dispose loader; loader = new FunctionsLoader(filter isStandardFunction(tlftj(functions))); loader.loadFunctionsParams = litparams(header := "set flag NoGenericFunctions."); loader.onLoaded(r startPlaying); loader.loadInBackground(); } void startPlaying enter { if (loader == null) loadFunctions(); cancelThread(playThread); playThread = null; playThread = startThread(rEnter play); } void play { //showSuggestions(ll("test " + now())); new LinkedHashSet<S> l; S input = lastInput(); for ping (S f : loader.functions) { addIfInstanceOf(l, S, callBlobFunction(f)); ping(); if (nempty(input)) addIfInstanceOf(l, S, callBlobFunction(f, input)); } showSuggestions(l); } // API void loadIfNotLoaded() { if (loader == null) loadFunctions(); } Set<S> loadedFunctions() { ret loader.functions; } S maxNum() { ret firstIntegerString(tlftj(functions)); } O blob() { ret loader.blob; } O callBlobFunction(S fname, O... args) { if (canCallWithVarargs(module(), fname, args)) ret callWithVarargs(module(), fname ,args); else ret callOpt(loader.blob, fname, args); } LPairS userBotPairs() { ret chatConvo_userBotPairs(posts); } LS rawLines() { ret collect html(posts); } S firstLine() { ret getString html(first(posts)); } int numLines() { ret l(posts); } void suggest(S s) { showSuggestions(ll(s)); } }
Began life as a copy of #1026808
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1026824 |
Snippet name: | Parrot 1.2 [with API] |
Eternal ID of this version: | #1026824/16 |
Text MD5: | 07874683d6681f8c3c3d654377c88043 |
Transpilation MD5: | 559f691a0719d3fc177e7b5d0ad49bce |
Author: | stefan |
Category: | javax / stefan's os |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-01-26 15:58:52 |
Source code size: | 2616 bytes / 87 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 266 / 5195 |
Version history: | 15 change(s) |
Referenced in: | -