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

71
LINES

< > BotCompany Repo | #1004707 // Text Learning [Swing]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 5262K of libraries. Click here for Pure Java version (3572L/24K/82K).

1  
!752
2  
3  
sS suckerID = "#1004698", algoID = "#1004706";
4  
5  
static O sucker;
6  
7  
p {
8  
  load("algoID");
9  
  showTheForm();
10  
}
11  
12  
svoid showTheForm {
13  
  final JTextField tf = new JTextField(algoID);
14  
  final JLabel score = jrightAlignedLabel();
15  
  score.setFont(typeWriterFont(35));
16  
  final JLabel len = jrightAlignedLabel();
17  
  final JLabel cs = jrightAlignedLabel();
18  
  Runnable start = r {
19  
    algoID = trim(tf.getText());
20  
    save("algoID");
21  
    thread { wakeSucker(suckerID, algoID, score, len, cs); }
22  
  };
23  
  onEnter(tf, start);
24  
  showForm(
25  
    "Algorithm/strategy to feed (ID):", tf,
26  
    "What we feed:", jlabel(suckerID + " - " + getSnippetTitle(suckerID)),
27  
    "Score", score,
28  
    "Text Size", len,
29  
    "Code Size", cs,
30  
    null, jbutton("Start", start));
31  
}
32  
33  
static void wakeSucker(S suckerID, S algoID, JLabel scoreField, JLabel len, JLabel cs) {
34  
  ping();
35  
  
36  
  scoreField.setText("Calculating...");
37  
38  
  if (sucker == null) {
39  
    print("Waking...");
40  
    sucker = run(suckerID);
41  
  }
42  
  
43  
  print("Feeding...");
44  
  
45  
  S text = (S) callOpt(sucker, "getText");
46  
  
47  
  S lua = loadSnippet(algoID);
48  
  
49  
  Sandbox s = luaSandbox();
50  
  evalLua(s, lua);
51  
  LuaValue strategy = s.get("strategy");
52  
  
53  
  if (!strategy.isnil()) {
54  
    assertNotNull(text);
55  
    LuaValue result = strategy.call(text);
56  
    assertTrue(result.isstring());
57  
    lua = result.tojstring();
58  
    print("CODE:\n" + indentx(lua));
59  
  }
60  
61  
  cs.setText(n(l(lua), "Byte"));
62  
  S desc = "L " + lua;
63  
  O algo = makeLuaTextPredictAlgoFor(desc, sucker);
64  
  
65  
  O result = callOpt(sucker, "suck", desc, algo);
66  
  double score = cast get(sucker, "lastScore");
67  
  scoreField.setText(formatDouble(score, 2) + " %");
68  
  len.setText(n(l(text), "Byte"));
69  
  if (isTrue(result))
70  
    print("NEW BEST!!!!!");
71  
}

Author comment

Began life as a copy of #1004701

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xinetxnxrdbb

No comments. add comment

Snippet ID: #1004707
Snippet name: Text Learning [Swing]
Eternal ID of this version: #1004707/1
Text MD5: 7439421aa34d3c524db720017c13e2fa
Transpilation MD5: c0eb1cb599ddc70f8cab61c7371b6062
Author: stefan
Category: javax / a.i.
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-27 23:40:00
Source code size: 1791 bytes / 71 lines
Pitched / IR pitched: No / No
Views / Downloads: 576 / 728
Referenced in: [show references]