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

sclass GazelleTree {
  L<GazelleTree> children;
  GazelleTree parent;
  double weight = 1, totalWeight;
  S line, lineType;
  S prediction, judgement;
  RuleEngine2_MatchedRule mr;
  bool isSplitNode;
  long created = now();
  
  transient GazelleEvalContext ctx;

  *() {}
  *(S *line) {}
  *(GazelleEvalContext *ctx, S *line) {}
  
  // e.g. for rendering tree
  toString {
    ret (isSplitNode ? "[split] " : "") + line + appendSquareBracketed(joinWithComma(listPlusNempties(renderQualityElements(), ruleID())));
  }
  
  LS renderQualityElements() {
    new LS l;
    addIfNempty(l, prediction);
    if (mr != null) {
      l.add(mr.qualitySum() + " / " + formatDouble(mr.relativeQuality(), 2));
      if (mr.moreConditions())
        l.add("unsatisfied");
    }
    ret l;
  }
  
  // includes this node
  LS history() {
    new LS l;
    GazelleTree e = this;
    while (e != null) {
      l.add(e.line);
      e = e.parent;
    }
    ret reversed(l);
  }
  
  void add(GazelleTree child) {
    if (children == null) children = new L;
    child.parent = this;
    child.setContext(ctx);
    children.add(child);
  }
  
  void setContext(GazelleEvalContext ctx) {
    this.ctx = ctx;
    pcallFAll(ctx.onNewNode, this);
    _add(ctx.linesSet, line);
  }
  
  RuleEngine2.Rule rule() {
    ret mr == null ? null : mr.rule;
  }
  
  S ruleID() { ret rule() == null ? null : rule().globalID; }
  
  SS varMap() {
    ret mr == null ? null : mr.map;
  }
  
  void flush() {
    if (mr != null) {
      mr.flush();
      line = mr.outText();
    }
  }
  
  Collection<S> ruleComments() {
    RuleEngine2.Rule rule = rule();
    ret rule == null ? null : rule.comments;
  }
}

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: 411 / 1015
Version history: 25 change(s)
Referenced in: [show references]