Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

133
LINES

< > BotCompany Repo | #1030822 // AGI Reactor 1 v2 [pattern + input => scenario]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 1059K of libraries. Click here for Pure Java version (24823L/133K).

!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<BPattern> pattern;
  new Ref<BInput> 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<BEAObject> 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 := "<company> delivers <product>");
  }
  
  afterVisualize {
    JConceptsTable<BMatch> 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)));
  }
}

Author comment

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: 196 / 839
Version history: 18 change(s)
Referenced in: