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

62
LINES

< > BotCompany Repo | #1018254 // Test Bot v2 [Dyn Module, with rules selection, OK]

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

Libraryless. Compilation Failed (23592L/178K).

!7

sclass Suggestion {
  RuleWithParams rule;
  S output;
  S facts;
  S newInput;
  
  *() {}
  *(RuleWithParams *rule, S *output, S *facts, S *newInput) {}
}

sclass TestBot extends DynObjectTable<RuleWithParams> {
  InputChooser inputChooser = new(this);
  S source;
  S inputAs = "Input:"; // "Input:" or "Fact:"
  
  start { inputChooser.delay = 1000; }
  
  visualize {
    ret withMargin(northAndCenter(vstackWithSpacing(
      westAndCenter(dm_fieldComboBox('inputAs,
        ll("Input:", "Fact:")),
        wrap(inputChooser)),
      withLabel("Rules mech list (empty for default rules&facts):",
        onEnter(dm_fieldTextField('source), rThread { update(inputChooser.input()) }))),
      super.visualize()));
  }
  
  void update { if (inputChooser.update()) update(inputChooser.input()); }
  
  void update(S input) {
    temp enter();
    new NLLogicChecker_v3 c;
    bool inputAsFact = cic(inputAs, 'fact);
    if (!inputAsFact) c.input = input;
    Pair<L<IfThen>, LS> rulesAndFacts;
    if (empty(trim(source)))
      rulesAndFacts = ai_activeRulesAndFacts();
    else
      rulesAndFacts = pair(ai_parseRulesWithMacros(mL_raw(trim(source))), emptyList(S));
    c.facts = reversed(rulesAndFacts.b);
    if (inputAsFact) c.facts = concatLists(ll(input), c.facts);
    c.rules = reversed(rulesAndFacts.a); // latest rules first!
    if (!inputAsFact)
      c.rules = [IfThen r : c.rules | ai_ruleAccessesInput(r)];
    c.rules = nlLogic_safeLHSEvalsOnly_verbose(c.rules);
    print("Have " + n2(rulesAndFacts.a, "rule"));
    c.useIterate = true;
    c.staticVerbose = true;
    new L<RuleWithParams> battleSpace;
    nlLogic_fillBattleSpace(c, battleSpace, false);
    //print("l=" + l(battleSpace));
    setData(map(battleSpace, func(RuleWithParams r) -> Suggestion {
      L<Exp> l = nlLogic_unrollAndApplyRuleWithParams(r);
      ret Suggestion(r,
        nullIfEmpty(join("|", nlLogic_certainOperatorArgs(l, 'output, 'say))),
        nullIfEmpty(join("|", nlLogic_certainOperatorArgs(l, 'fact))),
        nullIfEmpty(join("|", nlLogic_certainOperatorArgs(l, 'input))));
    }));
  }
}

Author comment

Began life as a copy of #1018152

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1018254
Snippet name: Test Bot v2 [Dyn Module, with rules selection, OK]
Eternal ID of this version: #1018254/22
Text MD5: c6ba36e6b0b02009fa90667060782a0e
Transpilation MD5: 6d2b343ea9f61bb431fe2e1278385bf8
Author: stefan
Category: javax / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-09-13 14:20:37
Source code size: 2166 bytes / 62 lines
Pitched / IR pitched: No / No
Views / Downloads: 362 / 564
Version history: 21 change(s)
Referenced in: [show references]