Uses 1059K of libraries. Click here for Pure Java version (24823L/133K).
1 | !7 |
2 | |
3 | //set flag SimpleCRUD_v2_debug. |
4 | //set flag formLayouter1_debug. |
5 | |
6 | beaConcept BPattern { |
7 | S text; |
8 | |
9 | toString { ret "[\*id*/] " + shortDynName(this) + " " + quote(text); } |
10 | |
11 | void reactWith(BInput input, IBEAReactor reactor) {} |
12 | } |
13 | |
14 | beaConcept BStarPattern > BPattern { |
15 | void reactWith(BInput input, IBEAReactor reactor) { |
16 | LS mapping = matchesToStringList(flexMatchIC_first(text, input.text)); |
17 | if (mapping == null) ret; |
18 | reactor.uniqResult(BEAObject, |
19 | type := "match", |
20 | +input, |
21 | pattern := this, |
22 | +mapping); |
23 | } |
24 | } |
25 | |
26 | beaConcept BAngleVarPattern > BPattern { |
27 | void reactWith(BInput input, IBEAReactor reactor) { |
28 | SS mapping = flexMatchAngleBracketVarsIC_first(text, input.text); |
29 | if (mapping == null) ret; |
30 | reactor.uniqResult(BEAObject, |
31 | type := "match", |
32 | +input, |
33 | pattern := this, |
34 | +mapping); |
35 | } |
36 | } |
37 | |
38 | beaConcept BMatch { |
39 | new Ref<BPattern> pattern; |
40 | new Ref<BInput> input; |
41 | SS mapping; |
42 | } |
43 | |
44 | beaConcept BMatchToScenario { |
45 | void reactWith(BMatch match, IBEAReactor reactor) { |
46 | reactor.uniqResult(BEAObject, |
47 | type := "scenario", |
48 | text := mapToLines(match.mapping, |
49 | (a, b) -> format_curly("* is a *.", b, a)); |
50 | } |
51 | } |
52 | |
53 | beaConcept BScenarioToOutput { |
54 | bool canReactWith(BEAObject o) { |
55 | ret o.typeIs("scenario"); |
56 | } |
57 | |
58 | void reactWith(BEAObject scenario, IBEAReactor reactor) { |
59 | reactor.uniqResult(BOutput, |
60 | type := "Output", |
61 | text := scenario~.text); |
62 | } |
63 | } |
64 | |
65 | beaConcept BFeedback { |
66 | new Ref<BEAObject> on; |
67 | S text; |
68 | } |
69 | |
70 | cmodule2 > DynBEAReactor_textInOut { |
71 | { input = "UBports community delivers 'second-largest release of Ubuntu Touch ever'"; } |
72 | |
73 | transient JButton btnSaveAsPattern; |
74 | |
75 | start { |
76 | crud.showClassNameSelectors = true; |
77 | crud.allowNewFields = true; |
78 | crud.emptyStringsToNull = true; |
79 | crud.humanizeFieldNames = false; |
80 | |
81 | dm_watchField input(r updateButtons); |
82 | } |
83 | |
84 | void createInitialObjects { |
85 | uniq BMatchToScenario(); |
86 | uniq BScenarioToOutput(); |
87 | //uniq BPattern(text := "* delivers *"); |
88 | uniq BAngleVarPattern(text := "<company> delivers <product>"); |
89 | } |
90 | |
91 | afterVisualize { |
92 | JConceptsTable<BMatch> ct = new(BMatch); |
93 | ct.humanizeFieldNames = false; |
94 | ct.itemToMap_inner2 = m -> litorderedmap( |
95 | input := m.input, |
96 | pattern := m.pattern, |
97 | mapping := m.mapping, |
98 | feedback := collectFeedback(m)); |
99 | addTab(bottomTabs, "Matches", withRightAlignedButtons(ct, |
100 | tableDependentButton(ct.table(), "Mark OK", rThreadEnter { |
101 | saveFeedback(ct.selected(), "OK"); |
102 | }), |
103 | tableDependentButton(ct.table(), "Give detailed feedback...", rThreadEnter { |
104 | addFeedbackDialog(ct.selected()); |
105 | }))); |
106 | |
107 | addComponent(inputButtons, btnSaveAsPattern = jThreadedButton("Save as pattern", r saveInputAsPattern)); |
108 | updateButtons(); |
109 | } |
110 | |
111 | void saveInputAsPattern { |
112 | uniq(BAngleVarPattern, text := trim(input)); |
113 | } |
114 | |
115 | void updateButtons { |
116 | setEnabled(btnSaveAsPattern, containsAngleBracketVars(input)); |
117 | } |
118 | |
119 | void addFeedbackDialog(BEAObject item) { |
120 | inputText("Feedback for " + item, voidfunc(S text) { |
121 | if (nempty(text = trim(text))) |
122 | saveFeedback(item, text); |
123 | }); |
124 | } |
125 | |
126 | void saveFeedback(BEAObject item, S text) { |
127 | uniq BFeedback(on := item, +text); |
128 | } |
129 | |
130 | S collectFeedback(BEAObject item) { |
131 | ret joinWithComma(collect text(conceptsWhere BFeedback(on := item))); |
132 | } |
133 | } |
Began life as a copy of #1030776
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030822 |
Snippet name: | AGI Reactor 1 v2 [pattern + input => scenario] |
Eternal ID of this version: | #1030822/19 |
Text MD5: | 703304a375f9047a4d93d96221cfb223 |
Transpilation MD5: | d6af15b7d06bd40cc9837c67ddb57c59 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-03-31 16:00:56 |
Source code size: | 3534 bytes / 133 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 197 / 840 |
Version history: | 18 change(s) |
Referenced in: | [show references] |