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

78
LINES

< > BotCompany Repo | #1021520 // GazelleTree

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (14611L/79K).

1  
sclass GazelleTree {
2  
  L<GazelleTree> children;
3  
  GazelleTree parent;
4  
  double weight = 1, totalWeight;
5  
  S line, lineType;
6  
  S prediction, judgement;
7  
  RuleEngine2_MatchedRule mr;
8  
  bool isSplitNode;
9  
  long created = now();
10  
  
11  
  transient GazelleEvalContext ctx;
12  
13  
  *() {}
14  
  *(S *line) {}
15  
  *(GazelleEvalContext *ctx, S *line) {}
16  
  
17  
  // e.g. for rendering tree
18  
  toString {
19  
    ret (isSplitNode ? "[split] " : "") + line + appendSquareBracketed(joinWithComma(listPlusNempties(renderQualityElements(), ruleID())));
20  
  }
21  
  
22  
  LS renderQualityElements() {
23  
    new LS l;
24  
    addIfNempty(l, prediction);
25  
    if (mr != null) {
26  
      l.add(mr.qualitySum() + " / " + formatDouble(mr.relativeQuality(), 2));
27  
      if (mr.moreConditions())
28  
        l.add("unsatisfied");
29  
    }
30  
    ret l;
31  
  }
32  
  
33  
  // includes this node
34  
  LS history() {
35  
    new LS l;
36  
    GazelleTree e = this;
37  
    while (e != null) {
38  
      l.add(e.line);
39  
      e = e.parent;
40  
    }
41  
    ret reversed(l);
42  
  }
43  
  
44  
  void add(GazelleTree child) {
45  
    if (children == null) children = new L;
46  
    child.parent = this;
47  
    child.setContext(ctx);
48  
    children.add(child);
49  
  }
50  
  
51  
  void setContext(GazelleEvalContext ctx) {
52  
    this.ctx = ctx;
53  
    pcallFAll(ctx.onNewNode, this);
54  
    _add(ctx.linesSet, line);
55  
  }
56  
  
57  
  RuleEngine2.Rule rule() {
58  
    ret mr == null ? null : mr.rule;
59  
  }
60  
  
61  
  S ruleID() { ret rule() == null ? null : rule().globalID; }
62  
  
63  
  SS varMap() {
64  
    ret mr == null ? null : mr.map;
65  
  }
66  
  
67  
  void flush() {
68  
    if (mr != null) {
69  
      mr.flush();
70  
      line = mr.outText();
71  
    }
72  
  }
73  
  
74  
  Collection<S> ruleComments() {
75  
    RuleEngine2.Rule rule = rule();
76  
    ret rule == null ? null : rule.comments;
77  
  }
78  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1021520
Snippet name: GazelleTree
Eternal ID of this version: #1021520/26
Text MD5: cec4cd95ee764107975c26ab3027e292
Transpilation MD5: 24ff09deeb6476da09e3210faa5dc0b0
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-23 04:37:43
Source code size: 1751 bytes / 78 lines
Pitched / IR pitched: No / No
Views / Downloads: 390 / 994
Version history: 25 change(s)
Referenced in: [show references]