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

1  
!7
2  
3  
set flag DynModule.
4  
5  
sclass Entry {
6  
  //S originalRule, replacements, modifiedRule;
7  
  S line;
8  
  S conditions;
9  
  S rule;
10  
  S prediction;
11  
  S judgement = "";
12  
  S struct;
13  
  transient RuleEngine2_MatchedRule mr;
14  
15  
  sS _fieldOrder = "line conditions prediction judgement struct";
16  
}
17  
18  
cmodule TestRuleEngine2 > DynObjectTable<Entry> {
19  
  S input, processedInput;
20  
  transient ReliableSingleThread rstCalc = dm_rstWithPostDelay(this, r calc, 500);
21  
  transient int maxResults = 500;
22  
  transient bool skipBadPredictions = true;
23  
  
24  
  S switchableFields() { ret "skipBadPredictions maxResults"; }
25  
  
26  
  start {
27  
    set withSearcher;
28  
    set fieldsInOrder;
29  
    hideFields = litset('rule, 'mr);
30  
  }
31  
  
32  
  visualize {
33  
    JComponent tf = dm_textField('input);
34  
    onChangeAndNow(tf, rstCalc);
35  
    ret northCenterAndSouthWithMargins(
36  
      centerAndEastWithMargin(
37  
        tf,
38  
        jbutton("Make rule...", rThread { dm_gazelle_newRuleDialog(input, input) })),
39  
      super.visualize(),
40  
      rightAlignedButtons(
41  
        tableDependentButton(table(), "Mark good", rMark('good)),
42  
        tableDependentButton(table(), "Mark bad", rMark('bad)),
43  
        tableDependentButton(table(), "Mark funny", rMark('funny))
44  
      ));
45  
  }
46  
  
47  
  Runnable rMark(fS judgement) {
48  
    ret rThread {
49  
      Entry e = selected();
50  
      print("Selected: " + e);
51  
      e.judgement = judgement;
52  
      fireDataChanged();
53  
      saveEntry(e);
54  
    };
55  
  }
56  
  
57  
  void calc {
58  
    S input = this.input;
59  
    final new RuleEngine2 engine;
60  
    engine.addRules2(dm_allRulesFromRulesModuleWithCommentsAndIDs());
61  
    
62  
    // gather data for predictor
63  
    MultiMap<S> statementsByRule = ai_gazelle_indexStatementsByRule(dm_gazelle_statementsFromAppliedRules());
64  
    final Map<S, ai_gazelle_analyzeStatementsForRule_Data> dataByRule =
65  
      mapValues ai_gazelle_analyzeStatementsForRule(multiMapToMap(statementsByRule));
66  
67  
    final new LinkedHashSet<S> queue;
68  
    queue.add(input);
69  
    final new Set<S> done;
70  
    final new Set<S> lines;
71  
    new L<Entry> list;
72  
73  
    bool changes = true;
74  
    while (l(list) < maxResults && nempty(queue)) {
75  
      S input2 = popFirst(queue);
76  
      done.add(input2);
77  
      
78  
      L<RuleEngine2_MatchedRule> l = ai_ruleEngine2_rulesForInput_3(engine, input2);
79  
      l = sortByMethodDesc qualitySum(l);
80  
    
81  
      new L<Entry> newList;
82  
      for (RuleEngine2_MatchedRule r : l) {
83  
        S modifiedRule = engine.formatForUser(r.applyMapping().asText());
84  
        S line = r.applyMappingTo(r.rule.out);
85  
        addIfNotInOtherSet(queue, done, line);
86  
        
87  
        ai_gazelle_analyzeStatementsForRule_Data data = dataByRule.get(r.rule.globalID);
88  
        S prediction = data == null ? null : ai_gazelle_predictor1_onData(r, data);
89  
        
90  
        if (skipBadPredictions && eq(prediction, 'bad)) continue;
91  
        
92  
        newList.add(nu(Entry,
93  
          +line,
94  
          conditions := join(" | " , r.remainingConditions),
95  
          +prediction,
96  
          rule := modifiedRule,
97  
          struct := struct(r),
98  
          mr := r));
99  
      }
100  
      list.addAll(newList);
101  
      
102  
      for (Entry e : newList) {
103  
        continue if e.mr == null;
104  
        for (S line : ai_gazelle_makeIWantToKnows(e.mr)) {
105  
          if (!lines.add(line)) continue;
106  
          list.add(nu(Entry,
107  
            +line,
108  
            struct := "iwtk " + e.mr.rule.globalID)); // abusing the struct field
109  
          addIfNotInOtherSet(queue, done, line);
110  
        }
111  
      }
112  
    }
113  
114  
    setList(list);
115  
    processedInput = input;
116  
  }
117  
  
118  
  void saveEntry(Entry e) {
119  
    dm_gazelle_saveAppliedRule(
120  
      modifiedRule := e.rule,
121  
      judgement := e.judgement,
122  
      matchedRuleStruct := e.struct);
123  
  }
124  
}

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: 473 / 1335
Version history: 64 change(s)
Referenced in: [show references]