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

126
LINES

< > BotCompany Repo | #1021581 // Listening Comprehension v2 [dev.]

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

Uses 911K of libraries. Click here for Pure Java version (19188L/111K).

1  
!7
2  
3  
set flag DynModule.
4  
5  
sclass Entry {
6  
  S line;
7  
  transient GazelleTree treeNode;
8  
}
9  
10  
cmodule ListeningComprehension > DynObjectTable<Entry> {
11  
  S processedInput, text;
12  
  transient ReliableSingleThread rstCalc = dm_rstWithPostDelay(this, r calc, 500);
13  
  transient int maxResults = 500;
14  
  transient bool skipBadPredictions = true;
15  
  transient JTree jTree;
16  
  transient GazelleTree root;
17  
  transient double qualityCutOff = -0.75;
18  
  transient JLabel lblInfo;
19  
  transient Set<S> linesSet;
20  
  
21  
  S switchableFields() { ret "skipBadPredictions maxResults"; }
22  
  
23  
  enhanceFrame { internalFrameIcon(f, gazelle_frameIcon()); }
24  
  
25  
  start {
26  
    hideFields('treeNode);
27  
    dm_vmBus_onMessage('gazelleRulesChanged, rstCalc);
28  
  }
29  
  
30  
  visualize {
31  
    jTree = jDynamicTree/*_concurrent*/(null, func(GazelleTree tree) -> L<GazelleTree> enter {
32  
      ret dm_gazelle_getChildren(tree, +qualityCutOff, dialogHistory := tlft(text));
33  
    }, makeChildrenIsFast := false);
34  
    onTreeSelectionChanged(jTree, r updateInfo);
35  
    
36  
    treePopupMenu(jTree, voidfunc(JPopupMenu menu, final GazelleTree e) {
37  
      addMenuItem(menu, "Copy line", rThread { copyTextToClipboard(e.line) });
38  
      addMenuItem(menu, "Make rule...", rThread {
39  
        S s = e.line;
40  
        GazelleTree ee = e;
41  
        while ((ee = ee.parent) != null)
42  
          s = ee.line + "\n+ " + s;
43  
        dm_gazelle_newRuleDialog_3(s, "in = dialog");
44  
      });
45  
      addMenuItem(menu, "Mark good", rMark('good));
46  
      addMenuItem(menu, "Mark bad", rMark('bad));
47  
      addMenuItem(menu, "Mark funny", rMark('funny));
48  
      addMenuItem(menu, "Enter", rThread {
49  
        LS history = e.history();
50  
        /*if (oddLength(history))
51  
          setField(input := popLast(history));*/
52  
        setField(text := lines(history));
53  
      });
54  
    });
55  
    
56  
    ret jvsplit(0.25,
57  
      withMargin(withTitle("Input Text", onChange(dm_textArea('text), rstCalc))),
58  
      northCenterAndSouthWithMargins(
59  
        rightAlignedButtons(
60  
          "Make rule...", rThread { dm_gazelle_newRuleDialog_2(firstLine(text)) }),
61  
        jhsplit(
62  
          withTitle("Gazelle Tree", jTree),
63  
          withTitle("Generated Lines", super.visualize())),
64  
        vstackWithSpacing(
65  
          rightAlignedButtons(
66  
            treeDependentButton(jTree, "Mark good", rMark('good)),
67  
            treeDependentButton(jTree, "Mark bad", rMark('bad)),
68  
            treeDependentButton(jTree, "Mark funny", rMark('funny)),
69  
            jPopDownButton_noText(
70  
              "Export Rule Engine", rThread exportEngine)
71  
          ),
72  
          lblInfo = jlabel()
73  
        )));
74  
  }
75  
  
76  
  Runnable rMark(fS judgement) {
77  
    ret rThread {
78  
      GazelleTree e = selectedNode();
79  
      e.judgement = judgement;
80  
      jTree_fireUserObjectChanged(jTree, e);
81  
      saveEntry(e);
82  
    };
83  
  }
84  
  
85  
  GazelleTree selectedNode() {
86  
    ret (GazelleTree) jtree_selectedUserObject(jTree);
87  
  }
88  
  
89  
  void calc {
90  
    linesSet = syncLinkedHashSet();
91  
    root = new GazelleTree(joinLinesWithBarOrPunctuation(text));
92  
    GazelleEvalContext ctx = dm_gazelle_stdEvalContext();
93  
    clear();
94  
    ctx.onNewNode = addListener(ctx.onNewNode, voidfunc(GazelleTree t) {
95  
      if (linesSet.add(t.line))
96  
        add(nu Entry(line := t.line, treeNode := t));
97  
    });
98  
    root.setContext(ctx);
99  
    jTree_setRootObject(jTree, root);
100  
    jtree_collapseAndOpenRootNode(jTree);
101  
    dm_gazelle_expandTree(root);
102  
    processedInput = text;
103  
  }
104  
  
105  
  void saveEntry(GazelleTree e) {
106  
    S modifiedRule = e.ctx.engine.formatForUser(e.mr.applyMapping().asText());
107  
    dm_gazelle_saveAppliedRule(
108  
      +modifiedRule,
109  
      judgement := e.judgement,
110  
      matchedRuleStruct := struct(e.mr));
111  
  }
112  
  
113  
  void updateInfo enter {
114  
    S s = " ";
115  
    GazelleTree e = selectedNode();
116  
    if (e != null && e.mr != null) {
117  
      RuleEngine2.Rule r = e.mr.rule;
118  
      s = "Rule: " + r.globalID + " (" + newLinesToSpaces_trim(r.text) + ")";
119  
    }
120  
    setText(lblInfo, s);
121  
  }
122  
  
123  
  void exportEngine enter {
124  
    showText("Rule Engine", structWordWrap(root.ctx));
125  
  }
126  
}

Author comment

Began life as a copy of #1021559

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1021581
Snippet name: Listening Comprehension v2 [dev.]
Eternal ID of this version: #1021581/16
Text MD5: f173d7e364b56a8b6ac1f111f40cdea5
Transpilation MD5: 25449ff4b45dfc6c399c115e9d9a91eb
Author: stefan
Category: javax / stefan's os / gazelle
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-02-19 17:09:00
Source code size: 4115 bytes / 126 lines
Pitched / IR pitched: No / No
Views / Downloads: 382 / 1070
Version history: 15 change(s)
Referenced in: [show references]