!7 //set flag SimpleCRUD_v2_debug. //set flag formLayouter1_debug. beaConcept BPattern { S text; toString { ret "[\*id*/] " + shortDynName(this) + " " + quote(text); } void reactWith(BInput input, IBEAReactor reactor) {} } beaConcept BStarPattern > BPattern { void reactWith(BInput input, IBEAReactor reactor) { LS mapping = matchesToStringList(flexMatchIC_first(text, input.text)); if (mapping == null) ret; reactor.uniqResult(BEAObject, type := "match", +input, pattern := this, +mapping); } } beaConcept BAngleVarPattern > BPattern { void reactWith(BInput input, IBEAReactor reactor) { SS mapping = flexMatchAngleBracketVarsIC_first(text, input.text); if (mapping == null) ret; reactor.uniqResult(BEAObject, type := "match", +input, pattern := this, +mapping); } } beaConcept BMatch { new Ref pattern; new Ref input; SS mapping; } beaConcept BMatchToScenario { void reactWith(BMatch match, IBEAReactor reactor) { reactor.uniqResult(BEAObject, type := "scenario", text := mapToLines(match.mapping, (a, b) -> format_curly("* is a *.", b, a)); } } beaConcept BScenarioToOutput { bool canReactWith(BEAObject o) { ret o.typeIs("scenario"); } void reactWith(BEAObject scenario, IBEAReactor reactor) { reactor.uniqResult(BOutput, type := "Output", text := scenario~.text); } } beaConcept BFeedback { new Ref on; S text; } cmodule2 > DynBEAReactor_textInOut { { input = "UBports community delivers 'second-largest release of Ubuntu Touch ever'"; } transient JButton btnSaveAsPattern; start { crud.showClassNameSelectors = true; crud.allowNewFields = true; crud.emptyStringsToNull = true; crud.humanizeFieldNames = false; dm_watchField input(r updateButtons); } void createInitialObjects { uniq BMatchToScenario(); uniq BScenarioToOutput(); //uniq BPattern(text := "* delivers *"); uniq BAngleVarPattern(text := " delivers "); } afterVisualize { JConceptsTable ct = new(BMatch); ct.humanizeFieldNames = false; ct.itemToMap_inner2 = m -> litorderedmap( input := m.input, pattern := m.pattern, mapping := m.mapping, feedback := collectFeedback(m)); addTab(bottomTabs, "Matches", withRightAlignedButtons(ct, tableDependentButton(ct.table(), "Mark OK", rThreadEnter { saveFeedback(ct.selected(), "OK"); }), tableDependentButton(ct.table(), "Give detailed feedback...", rThreadEnter { addFeedbackDialog(ct.selected()); }))); addComponent(inputButtons, btnSaveAsPattern = jThreadedButton("Save as pattern", r saveInputAsPattern)); updateButtons(); } void saveInputAsPattern { uniq(BAngleVarPattern, text := trim(input)); } void updateButtons { setEnabled(btnSaveAsPattern, containsAngleBracketVars(input)); } void addFeedbackDialog(BEAObject item) { inputText("Feedback for " + item, voidfunc(S text) { if (nempty(text = trim(text))) saveFeedback(item, text); }); } void saveFeedback(BEAObject item, S text) { uniq BFeedback(on := item, +text); } S collectFeedback(BEAObject item) { ret joinWithComma(collect text(conceptsWhere BFeedback(on := item))); } }