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).

!752

sS suckerID = "#1004698", algoID = "#1004706";

static O sucker;

p {
  load("algoID");
  showTheForm();
}

svoid showTheForm {
  final JTextField tf = new JTextField(algoID);
  final JLabel score = jrightAlignedLabel();
  score.setFont(typeWriterFont(35));
  final JLabel len = jrightAlignedLabel();
  final JLabel cs = jrightAlignedLabel();
  Runnable start = r {
    algoID = trim(tf.getText());
    save("algoID");
    thread { wakeSucker(suckerID, algoID, score, len, cs); }
  };
  onEnter(tf, start);
  showForm(
    "Algorithm/strategy to feed (ID):", tf,
    "What we feed:", jlabel(suckerID + " - " + getSnippetTitle(suckerID)),
    "Score", score,
    "Text Size", len,
    "Code Size", cs,
    null, jbutton("Start", start));
}

static void wakeSucker(S suckerID, S algoID, JLabel scoreField, JLabel len, JLabel cs) {
  ping();
  
  scoreField.setText("Calculating...");

  if (sucker == null) {
    print("Waking...");
    sucker = run(suckerID);
  }
  
  print("Feeding...");
  
  S text = (S) callOpt(sucker, "getText");
  
  S lua = loadSnippet(algoID);
  
  Sandbox s = luaSandbox();
  evalLua(s, lua);
  LuaValue strategy = s.get("strategy");
  
  if (!strategy.isnil()) {
    assertNotNull(text);
    LuaValue result = strategy.call(text);
    assertTrue(result.isstring());
    lua = result.tojstring();
    print("CODE:\n" + indentx(lua));
  }

  cs.setText(n(l(lua), "Byte"));
  S desc = "L " + lua;
  O algo = makeLuaTextPredictAlgoFor(desc, sucker);
  
  O result = callOpt(sucker, "suck", desc, algo);
  double score = cast get(sucker, "lastScore");
  scoreField.setText(formatDouble(score, 2) + " %");
  len.setText(n(l(text), "Byte"));
  if (isTrue(result))
    print("NEW BEST!!!!!");
}

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: 511 / 642
Referenced in: [show references]