Uses 911K of libraries. Click here for Pure Java version (19102L/111K).
1 | !7 |
2 | |
3 | set flag DynModule. |
4 | |
5 | cmodule ListeningComprehension > DynModule { |
6 | S processedInput, text; |
7 | transient ReliableSingleThread rstCalc = dm_rstWithPostDelay(this, r calc, 500); |
8 | transient int maxResults = 500; |
9 | transient bool skipBadPredictions = true; |
10 | transient JTree jTree; |
11 | transient GazelleTree root; |
12 | transient double qualityCutOff = -0.75; |
13 | transient JLabel lblInfo; |
14 | |
15 | S switchableFields() { ret "skipBadPredictions maxResults"; } |
16 | |
17 | enhanceFrame { internalFrameIcon(f, gazelle_frameIcon()); } |
18 | |
19 | start { |
20 | dm_vmBus_onMessage('gazelleRulesChanged, rstCalc); |
21 | } |
22 | |
23 | visualize { |
24 | jTree = jDynamicTree(null, func(GazelleTree tree) -> L<GazelleTree> { |
25 | dm_gazelle_getChildren(tree, +qualityCutOff, dialogHistory := tlft(text)) |
26 | }, makeChildrenIsFast := true); |
27 | onTreeSelectionChanged(jTree, r updateInfo); |
28 | |
29 | treePopupMenu(jTree, voidfunc(JPopupMenu menu, final GazelleTree e) { |
30 | addMenuItem(menu, "Copy line", rThread { copyTextToClipboard(e.line) }); |
31 | addMenuItem(menu, "Make rule...", rThread { |
32 | S s = e.line; |
33 | GazelleTree ee = e; |
34 | while ((ee = ee.parent) != null) |
35 | s = ee.line + "\n+ " + s; |
36 | dm_gazelle_newRuleDialog_3(s, "in = dialog"); |
37 | }); |
38 | addMenuItem(menu, "Mark good", rMark('good)); |
39 | addMenuItem(menu, "Mark bad", rMark('bad)); |
40 | addMenuItem(menu, "Mark funny", rMark('funny)); |
41 | addMenuItem(menu, "Enter", rThread { |
42 | LS history = e.history(); |
43 | /*if (oddLength(history)) |
44 | setField(input := popLast(history));*/ |
45 | setField(text := lines(history)); |
46 | }); |
47 | }); |
48 | |
49 | ret jvsplit(0.25, |
50 | withMargin(withTitle("Input Text", onChange(dm_textArea('text), rstCalc))), |
51 | northCenterAndSouthWithMargins( |
52 | rightAlignedButtons( |
53 | "Make rule...", rThread { dm_gazelle_newRuleDialog_2(firstLine(text)) }), |
54 | jscroll(jTree), |
55 | vstackWithSpacing( |
56 | rightAlignedButtons( |
57 | treeDependentButton(jTree, "Mark good", rMark('good)), |
58 | treeDependentButton(jTree, "Mark bad", rMark('bad)), |
59 | treeDependentButton(jTree, "Mark funny", rMark('funny)), |
60 | jPopDownButton_noText( |
61 | "Export Rule Engine", rThread exportEngine) |
62 | ), |
63 | lblInfo = jlabel() |
64 | ))); |
65 | } |
66 | |
67 | Runnable rMark(fS judgement) { |
68 | ret rThread { |
69 | GazelleTree e = selected(); |
70 | e.judgement = judgement; |
71 | jTree_fireUserObjectChanged(jTree, e); |
72 | saveEntry(e); |
73 | }; |
74 | } |
75 | |
76 | GazelleTree selected() { |
77 | ret (GazelleTree) jtree_selectedUserObject(jTree); |
78 | } |
79 | |
80 | void calc { |
81 | root = new GazelleTree(joinLinesWithBarOrPunctuation(text)); |
82 | jTree_setRootObject(jTree, root); |
83 | jtree_collapseAndOpenRootNode(jTree); |
84 | processedInput = text; |
85 | } |
86 | |
87 | void saveEntry(GazelleTree e) { |
88 | S modifiedRule = e.ctx.engine.formatForUser(e.mr.applyMapping().asText()); |
89 | dm_gazelle_saveAppliedRule( |
90 | +modifiedRule, |
91 | judgement := e.judgement, |
92 | matchedRuleStruct := struct(e.mr)); |
93 | } |
94 | |
95 | void updateInfo enter { |
96 | S s = " "; |
97 | GazelleTree e = selected(); |
98 | if (e != null && e.mr != null) { |
99 | RuleEngine2.Rule r = e.mr.rule; |
100 | s = "Rule: " + r.globalID + " (" + newLinesToSpaces_trim(r.text) + ")"; |
101 | } |
102 | setText(lblInfo, s); |
103 | } |
104 | |
105 | void exportEngine enter { |
106 | showText("Rule Engine", structWordWrap(root.ctx)); |
107 | } |
108 | } |
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1021559 |
Snippet name: | Listening Comprehension |
Eternal ID of this version: | #1021559/8 |
Text MD5: | e480b8f1d6474ff2dcd06c5e69b36ea8 |
Transpilation MD5: | a3960ede1ecccdddab8c8ee3675d18cd |
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-18 21:16:02 |
Source code size: | 3498 bytes / 108 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 288 / 1060 |
Version history: | 7 change(s) |
Referenced in: | [show references] |