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

81
LINES

< > BotCompany Repo | #1021462 // Test Gazelle On Input, older version

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

Uses 911K of libraries. Click here for Pure Java version (14839L/83K).

!7

set flag DynModule.

sclass Entry {
  //S originalRule, replacements, modifiedRule;
  S rule;
  S judgement = "";
  S struct;

  sS _fieldOrder = "rule judgement struct";
}

cmodule TestRuleEngine2 > DynObjectTable<Entry> {
  S input, processedInput;
  transient ReliableSingleThread rstCalc = dm_rstWithPostDelay(this, r calc, 500);
  
  start {
    set fieldsInOrder;
    //hideFields = litset('struct);
  }
  
  visualize {
    JComponent tf = dm_textField('input);
    onChangeAndNow(tf, rstCalc);
    ret northCenterAndSouthWithMargins(
      centerAndEastWithMargin(
        tf,
        jbutton("Make rule...", rThread makeRule)),
      super.visualize(),
      rightAlignedButtons(
        tableDependentButton(table(), "Mark good", rMark('good)),
        tableDependentButton(table(), "Mark bad", rMark('bad)),
        tableDependentButton(table(), "Mark funny", rMark('funny))
      ));
  }
  
  Runnable rMark(fS judgement) {
    ret rThread {
      Entry e = selected();
      e.judgement = judgement;
      fireDataChanged();
      saveEntry(e);
    };
  }
  
  void calc {
    S input = this.input;
    final new RuleEngine2 engine;
    engine.addRules2(dm_allRulesFromRulesModuleWithCommentsAndIDs());
    L<RuleEngine2_MatchedRule> l = ai_ruleEngine2_rulesForInput_3(engine, input);
    l = sortByMethodDesc qualitySum(l);
    setList(map(l, func(RuleEngine2_MatchedRule r) -> Entry {
      S modifiedRule = engine.formatForUser(r.applyMapping().asText());
      ret nu(Entry,
        rule := modifiedRule,
        struct := struct(r));
    }));
    processedInput = input;
  }
  
  void saveEntry(Entry e) {
    dm_requireAndCall("#1021413/AppliedRules", 'uniqConcept,
      litobjarrayAsObject(
        modifiedRule := e.rule,
        judgement := e.judgement,
        matchedRuleStruct := e.struct));
  }
  
  void makeRule {
    final JTextField tf1 = jtextfield(input);
    final JTextField tf2 = jtextfield(input);
    showFormTitled("Make a rule",
      "When", tf1,
      "Then", tf2,
      r {
        Pair<S, Bool> p = dm_gazelle_addRule(gtt(tf1), gtt(tf2));
        infoBox(p.b ? "Rule " + p.a + " added" : "Rule already there: " + p.a);
      });
  }
}

Author comment

Began life as a copy of #1021407

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

-
Snippet ID: #1021462
Snippet name: Test Gazelle On Input, older version
Eternal ID of this version: #1021462/1
Text MD5: ae47cbacafcf2f67e1a79a58974ed78a
Transpilation MD5: c668b0563b34c229983c71b13950ee98
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: 2019-02-13 17:12:22
Source code size: 2263 bytes / 81 lines
Pitched / IR pitched: No / No
Views / Downloads: 266 / 342
Referenced in: