Uses 911K of libraries. Click here for Pure Java version (14839L/83K).
1 | !7 |
2 | |
3 | set flag DynModule. |
4 | |
5 | sclass Entry { |
6 | //S originalRule, replacements, modifiedRule; |
7 | S rule; |
8 | S judgement = ""; |
9 | S struct; |
10 | |
11 | sS _fieldOrder = "rule judgement struct"; |
12 | } |
13 | |
14 | cmodule TestRuleEngine2 > DynObjectTable<Entry> { |
15 | S input, processedInput; |
16 | transient ReliableSingleThread rstCalc = dm_rstWithPostDelay(this, r calc, 500); |
17 | |
18 | start { |
19 | set fieldsInOrder; |
20 | //hideFields = litset('struct); |
21 | } |
22 | |
23 | visualize { |
24 | JComponent tf = dm_textField('input); |
25 | onChangeAndNow(tf, rstCalc); |
26 | ret northCenterAndSouthWithMargins( |
27 | centerAndEastWithMargin( |
28 | tf, |
29 | jbutton("Make rule...", rThread makeRule)), |
30 | super.visualize(), |
31 | rightAlignedButtons( |
32 | tableDependentButton(table(), "Mark good", rMark('good)), |
33 | tableDependentButton(table(), "Mark bad", rMark('bad)), |
34 | tableDependentButton(table(), "Mark funny", rMark('funny)) |
35 | )); |
36 | } |
37 | |
38 | Runnable rMark(fS judgement) { |
39 | ret rThread { |
40 | Entry e = selected(); |
41 | e.judgement = judgement; |
42 | fireDataChanged(); |
43 | saveEntry(e); |
44 | }; |
45 | } |
46 | |
47 | void calc { |
48 | S input = this.input; |
49 | final new RuleEngine2 engine; |
50 | engine.addRules2(dm_allRulesFromRulesModuleWithCommentsAndIDs()); |
51 | L<RuleEngine2_MatchedRule> l = ai_ruleEngine2_rulesForInput_3(engine, input); |
52 | l = sortByMethodDesc qualitySum(l); |
53 | setList(map(l, func(RuleEngine2_MatchedRule r) -> Entry { |
54 | S modifiedRule = engine.formatForUser(r.applyMapping().asText()); |
55 | ret nu(Entry, |
56 | rule := modifiedRule, |
57 | struct := struct(r)); |
58 | })); |
59 | processedInput = input; |
60 | } |
61 | |
62 | void saveEntry(Entry e) { |
63 | dm_requireAndCall("#1021413/AppliedRules", 'uniqConcept, |
64 | litobjarrayAsObject( |
65 | modifiedRule := e.rule, |
66 | judgement := e.judgement, |
67 | matchedRuleStruct := e.struct)); |
68 | } |
69 | |
70 | void makeRule { |
71 | final JTextField tf1 = jtextfield(input); |
72 | final JTextField tf2 = jtextfield(input); |
73 | showFormTitled("Make a rule", |
74 | "When", tf1, |
75 | "Then", tf2, |
76 | r { |
77 | Pair<S, Bool> p = dm_gazelle_addRule(gtt(tf1), gtt(tf2)); |
78 | infoBox(p.b ? "Rule " + p.a + " added" : "Rule already there: " + p.a); |
79 | }); |
80 | } |
81 | } |
Began life as a copy of #1021407
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: | #1021462 |
Snippet name: | Test Gazelle On Input, older version |
Eternal ID of this version: | #1021462/1 |
Text MD5: | ae47cbacafcf2f67e1a79a58974ed78a |
Transpilation MD5: | c668b0563b34c229983c71b13950ee98 |
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-02-13 17:12:22 |
Source code size: | 2263 bytes / 81 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 283 / 365 |
Referenced in: | [show references] |