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

80
LINES

< > BotCompany Repo | #1030776 // AGI Reactor 1 [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 (24236L/129K).

!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;
  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);
  }
}

cmodule2 > DynBEAReactor_textInOut {
  { input = "UBports community delivers 'second-largest release of Ubuntu Touch ever'"; }
  
  start {
    crud.showClassNameSelectors = true;
    crud.allowNewFields = true;
    crud.emptyStringsToNull = true;
    crud.humanizeFieldNames = false;
  }

  void createInitialObjects {
    uniq BMatchToScenario();
    uniq BScenarioToOutput();
    //uniq BPattern(text := "* delivers *");
    uniq BAngleVarPattern(text := "<company> delivers <product>");
  }
}

Author comment

Began life as a copy of #1030762

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030776
Snippet name: AGI Reactor 1 [pattern + input => scenario]
Eternal ID of this version: #1030776/18
Text MD5: 004c0c1ed8d28d6f07386e07925ac78f
Transpilation MD5: 9aa465511c4e65ef297a1fa49fb58f2f
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-29 14:06:42
Source code size: 2006 bytes / 80 lines
Pitched / IR pitched: No / No
Views / Downloads: 257 / 1071
Version history: 17 change(s)
Referenced in: [show references]