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).

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  
  SS mapping;
41  
}
42  
43  
beaConcept BMatchToScenario {
44  
  void reactWith(BMatch match, IBEAReactor reactor) {
45  
    reactor.uniqResult(BEAObject,
46  
      type := "scenario",
47  
      text := mapToLines(match.mapping,
48  
        (a, b) -> format_curly("* is a *.", b, a));
49  
  }
50  
}
51  
52  
beaConcept BScenarioToOutput {
53  
  bool canReactWith(BEAObject o) {
54  
    ret o.typeIs("scenario");
55  
  }
56  
  
57  
  void reactWith(BEAObject scenario, IBEAReactor reactor) {
58  
    reactor.uniqResult(BOutput,
59  
      type := "Output",
60  
      text := scenario~.text);
61  
  }
62  
}
63  
64  
cmodule2 > DynBEAReactor_textInOut {
65  
  { input = "UBports community delivers 'second-largest release of Ubuntu Touch ever'"; }
66  
  
67  
  start {
68  
    crud.showClassNameSelectors = true;
69  
    crud.allowNewFields = true;
70  
    crud.emptyStringsToNull = true;
71  
    crud.humanizeFieldNames = false;
72  
  }
73  
74  
  void createInitialObjects {
75  
    uniq BMatchToScenario();
76  
    uniq BScenarioToOutput();
77  
    //uniq BPattern(text := "* delivers *");
78  
    uniq BAngleVarPattern(text := "<company> delivers <product>");
79  
  }
80  
}

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: 324 / 1165
Version history: 17 change(s)
Referenced in: [show references]