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

65
LINES

< > BotCompany Repo | #1008607 // Sentences to subject [dev.]

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

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (8870L/61K).

!7

static SingleComponentPanel scp;
static int startIndex;

concept Sentence {
  S text;
  S action;
}

p-substance {
  unswing {
    db(); 
    indexConceptField(Sentence, "text");
    L<S> sentences = toLinesFullTrim(loadSnippet(#1008606));
    sentences = notStartingWith("\"", sentences);
    time { makeUniqueConcepts(Sentence, "text", sentences); }
  }
  showFrame(centerAndSouth(scp = new SingleComponentPanel,
    withTopMargin(20, jcenteredline(
      jbutton("Prev", r { makePanel(max(startIndex-10, 0)) }),
      jbutton("Next", r { if (startIndex+10 < countConcepts(Sentence)) makePanel(startIndex+10) }),
      jbutton("Random", r { makePanel(random(countConcepts(Sentence))/10*10) })))));
  makePanel(0);
}

svoid makePanel(int startIndex) {
  main.startIndex = startIndex;
  JPanel panel = gridLayoutPanel_trackWidth_evenlySpacedCols(2);
  panel.add(jlabel("Sentence"));
  panel.add(jlabel("Action"));
  for (final Sentence s : takeFirst(10, dropFirst(startIndex, list(Sentence)))) {
    final JTextField tfText = jtextfield_caretLeft(s.text);
    panel.add(tfText);
    new Matches m;
    if (jmatch("subject=* (*/*)", s.action, m)) pcall {
      int from = parseInt($2), len = parseInt($3);
      tfText.select(from, from+len);
    }
    
    bool hasAction = nempty(s.action);
    final JTextField tf = jtextfield(or2(s.action, "screw it"));
    final new Var<JButton> reviseBtn, okBtn;
    okBtn.set(jbutton("OK", r {
      cset(s, action := getTextTrim(tf));
      disableTextField(tf);
      replaceComponent(okBtn!, reviseBtn!);
    }));
    reviseBtn.set(jbutton("Revise", r {
      cset(s, action := null);
      enableTextField(tf);
      replaceComponent(reviseBtn!, okBtn!);
    }));
    if (hasAction) disableTextField(tf);
    panel.add(centerAndEast(tf, hasAction ? reviseBtn! : okBtn!));
    
    onCaret(tfText, r {
      int i = trimIndexRight(s.text, tfText.getSelectionStart());
      int j = trimIndexLeft(s.text, tfText.getSelectionEnd());
      if (j > i && s.action == null)
        tf.setText("subject=" + quote(substring(s.text, i, j)) + " (" + i + "/" + (j-i) + ")");
    });
  }
  scp.setComponent(jscroll(panel));
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1008607
Snippet name: Sentences to subject [dev.]
Eternal ID of this version: #1008607/60
Text MD5: f8f9fe90470a7c5fd663569a8f02aab3
Transpilation MD5: 3991358b1001f7da11da3d2ff7837c86
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-05-26 16:59:22
Source code size: 2224 bytes / 65 lines
Pitched / IR pitched: No / No
Views / Downloads: 656 / 2382
Version history: 59 change(s)
Referenced in: [show references]