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

67
LINES

< > BotCompany Repo | #1021556 // gazelle_getChildren

JavaX fragment (include)

1  
static L<GazelleTree> gazelle_getChildren(GazelleTree tree, O... _) {
2  
  if (tree == null) null;
3  
  if (tree.children != null) ret tree.children;
4  
  
5  
  tree.children = new L;
6  
  
7  
  double qualityCutOff = optPar qualityCutOff(_, -0.75);
8  
  LS dialogHistory = cast optPar dialogHistory(_);
9  
  bool debug = boolPar debug(_);
10  
  
11  
  // make rule engine etc.
12  
  if (tree.ctx == null)
13  
    tree.setContext(assertNotNull('evalContext, (GazelleEvalContext) callF(assertNotNull('makeEvalContext, (O) optPar makeEvalContext(_)))));
14  
  GazelleEvalContext ctx = tree.ctx;
15  
  RuleEngine2 engine = ctx.engine;
16  
  
17  
  SS inputMap = gazelle_inputMapFromLineAndHistory(tree.line, 
18  
    concatLists(dialogHistory, tree.history()));
19  
  if (boolPar respondingToHuman(_)) inputMap.put("_respondingToHuman" := "true");
20  
  if (debug) print("inputMap=" + sfu(asTreeMap(inputMap)));
21  
22  
  // Splitters
23  
  
24  
  if (!boolPar skipSplitters(_)) for (RuleEngine2.SimplifyWithRule rule : engine.splitterRules()) pcall {
25  
    Collection<S> out = gazelle_executeSplitterRule(engine, rule, tree.line);
26  
    if (empty(out)) continue;
27  
28  
    GazelleTree child = new(joinWithVBar(out));
29  
    child.ctx = ctx;
30  
    child.isSplitNode = true;
31  
    tree.add(child);
32  
    
33  
    for (S line : out)
34  
      child.add(GazelleTree(line));
35  
  }
36  
  
37  
  // Other rules
38  
    
39  
  bool firstConditionOnly = boolPar firstConditionOnly(_);
40  
  O[] params = litobjectarray(debug := optPar debug(_), +tree);
41  
  L<RuleEngine2_MatchedRule> l = sortByMethodDesc qualitySum(
42  
    firstConditionOnly
43  
      ? ai_ruleEngine2_rulesForInput_5(engine, inputMap, params)
44  
      : ai_ruleEngine2_rulesForInput_5_allConditions(engine, inputMap, params));
45  
  //print("Got rules: " + l(l));
46  
  
47  
  for (RuleEngine2_MatchedRule r : l) {
48  
    double quality = r.relativeQuality();
49  
    double cutOff = qualityCutOff;
50  
    if (r.rule != null && r.rule.qualityCutOff != null) cutOff = r.rule.qualityCutOff;
51  
    if (quality < cutOff && boolPar skipBad(_, true)) {
52  
      if (debug) print("Match under quality (" + quality + "/" + qualityCutOff + "): " + r);
53  
      continue;
54  
    }
55  
    S line = r.outText();
56  
    
57  
    GazelleTree child = new(line);
58  
    child.ctx = ctx;
59  
    child.mr = r;
60  
    if (r.rule != null) child.lineType = r.rule.outType(); // TODO: there can be multiple out types
61  
    
62  
    gazelle_addPredictionToTreeNode(child);
63  
    tree.add(child);
64  
  }
65  
  gazelle_sortChildren(tree);
66  
  ret tree.children;
67  
}

Author comment

Began life as a copy of #1021522

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: #1021556
Snippet name: gazelle_getChildren
Eternal ID of this version: #1021556/51
Text MD5: 29bdb3cd568053db7267cef32792e1b2
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-22 15:50:42
Source code size: 2450 bytes / 67 lines
Pitched / IR pitched: No / No
Views / Downloads: 451 / 569
Version history: 50 change(s)
Referenced in: [show references]