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

1  
!7
2  
3  
static SingleComponentPanel scp;
4  
static int startIndex;
5  
6  
concept Sentence {
7  
  S text;
8  
  S action;
9  
}
10  
11  
p-substance {
12  
  unswing {
13  
    db(); 
14  
    indexConceptField(Sentence, "text");
15  
    L<S> sentences = toLinesFullTrim(loadSnippet(#1008606));
16  
    sentences = notStartingWith("\"", sentences);
17  
    time { makeUniqueConcepts(Sentence, "text", sentences); }
18  
  }
19  
  showFrame(centerAndSouth(scp = new SingleComponentPanel,
20  
    withTopMargin(20, jcenteredline(
21  
      jbutton("Prev", r { makePanel(max(startIndex-10, 0)) }),
22  
      jbutton("Next", r { if (startIndex+10 < countConcepts(Sentence)) makePanel(startIndex+10) }),
23  
      jbutton("Random", r { makePanel(random(countConcepts(Sentence))/10*10) })))));
24  
  makePanel(0);
25  
}
26  
27  
svoid makePanel(int startIndex) {
28  
  main.startIndex = startIndex;
29  
  JPanel panel = gridLayoutPanel_trackWidth_evenlySpacedCols(2);
30  
  panel.add(jlabel("Sentence"));
31  
  panel.add(jlabel("Action"));
32  
  for (final Sentence s : takeFirst(10, dropFirst(startIndex, list(Sentence)))) {
33  
    final JTextField tfText = jtextfield_caretLeft(s.text);
34  
    panel.add(tfText);
35  
    new Matches m;
36  
    if (jmatch("subject=* (*/*)", s.action, m)) pcall {
37  
      int from = parseInt($2), len = parseInt($3);
38  
      tfText.select(from, from+len);
39  
    }
40  
    
41  
    bool hasAction = nempty(s.action);
42  
    final JTextField tf = jtextfield(or2(s.action, "screw it"));
43  
    final new Var<JButton> reviseBtn, okBtn;
44  
    okBtn.set(jbutton("OK", r {
45  
      cset(s, action := getTextTrim(tf));
46  
      disableTextField(tf);
47  
      replaceComponent(okBtn!, reviseBtn!);
48  
    }));
49  
    reviseBtn.set(jbutton("Revise", r {
50  
      cset(s, action := null);
51  
      enableTextField(tf);
52  
      replaceComponent(reviseBtn!, okBtn!);
53  
    }));
54  
    if (hasAction) disableTextField(tf);
55  
    panel.add(centerAndEast(tf, hasAction ? reviseBtn! : okBtn!));
56  
    
57  
    onCaret(tfText, r {
58  
      int i = trimIndexRight(s.text, tfText.getSelectionStart());
59  
      int j = trimIndexLeft(s.text, tfText.getSelectionEnd());
60  
      if (j > i && s.action == null)
61  
        tf.setText("subject=" + quote(substring(s.text, i, j)) + " (" + i + "/" + (j-i) + ")");
62  
    });
63  
  }
64  
  scp.setComponent(jscroll(panel));
65  
}

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: 668 / 2396
Version history: 59 change(s)
Referenced in: [show references]