Uses 911K of libraries. Click here for Pure Java version (19235L/111K).
1 | !7 |
2 | |
3 | set flag DynModule. |
4 | |
5 | cmodule TestRuleEngine2 > DynSCP { |
6 | S input, processedInput, dialogHistory; |
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(dialogHistory)) |
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, "Enter", rThread { |
39 | LS history = e.history(); |
40 | /*if (oddLength(history)) |
41 | setField(input := popLast(history));*/ |
42 | setField(dialogHistory := lines(history)); |
43 | }); |
44 | }); |
45 | |
46 | JComponent tf = dm_textField('input); |
47 | onChangeAndNow(tf, rstCalc); |
48 | ret jvsplit(0.25, |
49 | withMargin(withTitle("Dialog History", onChange(dm_textArea('dialogHistory), rstCalc))), |
50 | northCenterAndSouthWithMargins( |
51 | centerAndEastWithMargin( |
52 | tf, |
53 | jbutton("Make rule...", rThread { dm_gazelle_newRuleDialog_2(input) })), |
54 | super.visualize(), |
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 | visualize2 { |
68 | ret jscroll(jTree); |
69 | } |
70 | |
71 | Runnable rMark(fS judgement) { |
72 | ret rThread { |
73 | GazelleTree e = selected(); |
74 | e.judgement = judgement; |
75 | jTree_fireUserObjectChanged(jTree, e); |
76 | saveEntry(e); |
77 | }; |
78 | } |
79 | |
80 | GazelleTree selected() { |
81 | ret (GazelleTree) jtree_selectedUserObject(jTree); |
82 | } |
83 | |
84 | void calc { |
85 | S input = this.input; |
86 | root = new GazelleTree(input); |
87 | jTree_setRootObject(jTree, root); |
88 | jtree_collapseAndOpenRootNode(jTree); |
89 | processedInput = input; |
90 | } |
91 | |
92 | void saveEntry(GazelleTree e) { |
93 | S modifiedRule = e.mr.applyMapping().asText(); |
94 | dm_gazelle_saveAppliedRule( |
95 | +modifiedRule, |
96 | judgement := e.judgement, |
97 | matchedRuleStruct := struct(e.mr)); |
98 | } |
99 | |
100 | void updateInfo enter { |
101 | S s = " "; |
102 | GazelleTree e = selected(); |
103 | if (e != null && e.mr != null) { |
104 | RuleEngine2.Rule r = e.mr.rule; |
105 | s = "Rule: " + r.globalID + " (" + newLinesToSpaces_trim(r.text) + ")"; |
106 | } |
107 | setText(lblInfo, s); |
108 | } |
109 | |
110 | void exportEngine enter { |
111 | showText("Rule Engine", structWordWrap(root.ctx)); |
112 | } |
113 | } |
Began life as a copy of #1021468
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: | #1021492 |
Snippet name: | Test Gazelle On Input v4 [with line types & dialog history] |
Eternal ID of this version: | #1021492/35 |
Text MD5: | 1010843ac1398a4be71b3097312ec3c3 |
Transpilation MD5: | a9f28013538d7e88d644fdbc737660af |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-03-01 23:00:48 |
Source code size: | 3494 bytes / 113 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 493 / 1777 |
Version history: | 34 change(s) |
Referenced in: | [show references] |