Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

91
LINES

< > BotCompany Repo | #1020415 // Train Interaction [dev.]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (15441L/112K).

1  
!7
2  
3  
srecord Line (
4  
  S type, // 'user, 'suggestion, 'bot, 'eval, 'evalResult, 'metaComment
5  
  S text
6  
) {}
7  
8  
concept Interaction {
9  
  new L<Line> lines;
10  
  bool current;
11  
  
12  
  void addLine(Line line) {
13  
    lines.add(line);
14  
    change();
15  
  }
16  
}
17  
18  
sS lineToString(Line line) {
19  
  ret lpad(10, firstToUpper(replaceCompleteValue(line.type, 'metaComment, 'comment))) + ": " + line.text;
20  
}
21  
22  
module TrainInteraction {
23  
  bool watchEvals;
24  
  
25  
  transient S imageID = #1101205;
26  
  transient JTextArea taInteraction;
27  
  transient S log;
28  
  transient JTextField tfInput, tfToSay, tfMeta;
29  
  transient JLabel lblOutput;
30  
  transient Interaction current;
31  
32  
  start {
33  
    db();
34  
    current = uniq_sync(Interaction, current := true);
35  
    log = lines(map lineToString(current.lines));
36  
    
37  
    dm_vmBus_onMessage('javaEval_starting, voidfunc(S code, bool realEval) {
38  
      if (watchEvals)
39  
        addLine(Line('eval, code));
40  
    });
41  
    
42  
    for (S msg : ll('javaEval_OK, 'javaEval_error))
43  
      dm_vmBus_onMessage(msg, voidfunc(S code, O result) {
44  
        if (watchEvals)
45  
          addLine(Line('evalResult, shorten(str(result), 1024)));
46  
      });
47  
  }
48  
49  
  visualize {
50  
    onEnter(tfInput = jTextField(), r {
51  
      addLine(Line('user, gtt(tfInput)))
52  
    });
53  
    onEnter(tfToSay = jTextField(), r {
54  
      addLine(Line('suggestion, gtt(tfToSay)))
55  
    });
56  
    onEnter(tfMeta = jTextField(), r {
57  
      addLine(Line('metaComment, gtt(tfMeta)))
58  
    });
59  
    taInteraction = dm_fieldTextArea('log);
60  
    ret centerAndSouth(
61  
      centerAndSouthWithMargins(
62  
        westAndCenterWithMargin(jimage(imageID), taInteraction),
63  
        northAndCenterWithMargin(
64  
          fontSize(20, lblOutput = jCenteredBoldLabel(" ")),
65  
          makeForm3(
66  
            "Your input:", focusOnShow(fontSize(16, tfInput)),
67  
            "Make me say:", fontSize(16, tfToSay),
68  
            "Make a meta-comment:", fontSize(16, tfMeta))
69  
          )),
70  
      westAndCenterWithMargins(
71  
        dm_fieldCheckBox('watchEvals),
72  
        rightAlignedButtons("Start Over", rThread {
73  
          if (empty(current.lines) || confirmOKCancel("Sure?")) {
74  
            cset(current, lines := new L);
75  
            setField(log := "");
76  
          }
77  
        },
78  
        "Save Interaction", rThread {
79  
          dm_call(dm_makeOrShowModule("#1020418/TrainedInteractions"), 'addInteraction, current);
80  
          cset(current, current := false);
81  
          current = uniq_sync(Interaction, current := true);
82  
          setField(log := "");
83  
        })));
84  
  }
85  
  
86  
  Line addLine(Line line) {
87  
    current.addLine(line);
88  
    setField(log := log + lineToString(line) + "\n");
89  
    ret line;
90  
  }
91  
}

Author comment

Began life as a copy of #1019675

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020415
Snippet name: Train Interaction [dev.]
Eternal ID of this version: #1020415/34
Text MD5: a71b0ae535446de1819307ca20e5482c
Transpilation MD5: 13ef5401984c10f0bd58cde5e83739a1
Author: stefan
Category: javax / stefan's os / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-20 22:03:28
Source code size: 2679 bytes / 91 lines
Pitched / IR pitched: No / No
Views / Downloads: 317 / 1563
Version history: 33 change(s)
Referenced in: [show references]