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

124
LINES

< > BotCompany Repo | #1021407 // Test Gazelle On Input [v2]

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

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

!7

set flag DynModule.

sclass Entry {
  //S originalRule, replacements, modifiedRule;
  S line;
  S conditions;
  S rule;
  S prediction;
  S judgement = "";
  S struct;
  transient RuleEngine2_MatchedRule mr;

  sS _fieldOrder = "line conditions prediction judgement struct";
}

cmodule TestRuleEngine2 > DynObjectTable<Entry> {
  S input, processedInput;
  transient ReliableSingleThread rstCalc = dm_rstWithPostDelay(this, r calc, 500);
  transient int maxResults = 500;
  transient bool skipBadPredictions = true;
  
  S switchableFields() { ret "skipBadPredictions maxResults"; }
  
  start {
    set withSearcher;
    set fieldsInOrder;
    hideFields = litset('rule, 'mr);
  }
  
  visualize {
    JComponent tf = dm_textField('input);
    onChangeAndNow(tf, rstCalc);
    ret northCenterAndSouthWithMargins(
      centerAndEastWithMargin(
        tf,
        jbutton("Make rule...", rThread { dm_gazelle_newRuleDialog(input, input) })),
      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();
      print("Selected: " + e);
      e.judgement = judgement;
      fireDataChanged();
      saveEntry(e);
    };
  }
  
  void calc {
    S input = this.input;
    final new RuleEngine2 engine;
    engine.addRules2(dm_allRulesFromRulesModuleWithCommentsAndIDs());
    
    // gather data for predictor
    MultiMap<S> statementsByRule = ai_gazelle_indexStatementsByRule(dm_gazelle_statementsFromAppliedRules());
    final Map<S, ai_gazelle_analyzeStatementsForRule_Data> dataByRule =
      mapValues ai_gazelle_analyzeStatementsForRule(multiMapToMap(statementsByRule));

    final new LinkedHashSet<S> queue;
    queue.add(input);
    final new Set<S> done;
    final new Set<S> lines;
    new L<Entry> list;

    bool changes = true;
    while (l(list) < maxResults && nempty(queue)) {
      S input2 = popFirst(queue);
      done.add(input2);
      
      L<RuleEngine2_MatchedRule> l = ai_ruleEngine2_rulesForInput_3(engine, input2);
      l = sortByMethodDesc qualitySum(l);
    
      new L<Entry> newList;
      for (RuleEngine2_MatchedRule r : l) {
        S modifiedRule = engine.formatForUser(r.applyMapping().asText());
        S line = r.applyMappingTo(r.rule.out);
        addIfNotInOtherSet(queue, done, line);
        
        ai_gazelle_analyzeStatementsForRule_Data data = dataByRule.get(r.rule.globalID);
        S prediction = data == null ? null : ai_gazelle_predictor1_onData(r, data);
        
        if (skipBadPredictions && eq(prediction, 'bad)) continue;
        
        newList.add(nu(Entry,
          +line,
          conditions := join(" | " , r.remainingConditions),
          +prediction,
          rule := modifiedRule,
          struct := struct(r),
          mr := r));
      }
      list.addAll(newList);
      
      for (Entry e : newList) {
        continue if e.mr == null;
        for (S line : ai_gazelle_makeIWantToKnows(e.mr)) {
          if (!lines.add(line)) continue;
          list.add(nu(Entry,
            +line,
            struct := "iwtk " + e.mr.rule.globalID)); // abusing the struct field
          addIfNotInOtherSet(queue, done, line);
        }
      }
    }

    setList(list);
    processedInput = input;
  }
  
  void saveEntry(Entry e) {
    dm_gazelle_saveAppliedRule(
      modifiedRule := e.rule,
      judgement := e.judgement,
      matchedRuleStruct := e.struct);
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1021407
Snippet name: Test Gazelle On Input [v2]
Eternal ID of this version: #1021407/65
Text MD5: 4567deaf1c5aea4a11e51863efdb62ed
Transpilation MD5: d36a3c90ba63a2ff27ce6b9d95dd4b86
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-14 15:33:46
Source code size: 3754 bytes / 124 lines
Pitched / IR pitched: No / No
Views / Downloads: 474 / 1335
Version history: 64 change(s)
Referenced in: #1021462 - Test Gazelle On Input, older version
#1021468 - Test Gazelle On Input v3 [with tree]