Warning: session_start(): open(/var/lib/php/sessions/sess_ohhp8f32v1tdfl0i9rig3pppgp, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
set flag DynModule.
sclass GazelleTree {
L children;
GazelleTree parent;
double weight = 1, totalWeight;
S line, lineType;
S prediction, judgement;
RuleEngine2_MatchedRule mr;
transient EvalContext ctx;
*() {}
*(S *line) {}
toString {
new LS l;
if (mr != null)
for (S s : unnull(mr.remainingConditions))
l.add("if: " + s);
addIfNempty(l, prediction);
if (mr != null)
l.add(mr.qualitySum() + " / " + formatDouble(mr.relativeQuality(), 2));
ret line + appendSquareBracketed(joinWithComma(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);
}
}
sclass EvalContext {
RuleEngine2 engine;
Map dataByRule;
}
cmodule TestRuleEngine2 > DynSCP {
S input, processedInput, dialogHistory;
transient ReliableSingleThread rstCalc = dm_rstWithPostDelay(this, r calc, 500);
transient int maxResults = 500;
transient bool skipBadPredictions = true;
transient JTree jTree;
transient GazelleTree root;
transient double qualityCutOff = -0.75;
transient JLabel lblInfo;
S switchableFields() { ret "skipBadPredictions maxResults"; }
enhanceFrame { internalFrameIcon(f, gazelle_frameIcon()); }
start {
dm_vmBus_onMessage('gazelleRulesChanged, rstCalc);
}
visualize {
jTree = jDynamicTree(null, func(GazelleTree tree) -> L { gt_getChildren(tree) }, makeChildrenIsFast := true);
onTreeSelectionChanged(jTree, r updateInfo);
treePopupMenu(jTree, voidfunc(JPopupMenu menu, final GazelleTree e) {
addMenuItem(menu, "Copy line", rThread { copyTextToClipboard(e.line) });
addMenuItem(menu, "Make rule...", rThread {
S s = e.line;
GazelleTree ee = e;
while ((ee = ee.parent) != null)
s = ee.line + "\n+ " + s;
dm_gazelle_newRuleDialog_3(s, "in = dialog");
});
addMenuItem(menu, "Enter", rThread {
LS history = e.history();
/*if (oddLength(history))
setField(input := popLast(history));*/
setField(dialogHistory := lines(history));
});
});
JComponent tf = dm_textField('input);
onChangeAndNow(tf, rstCalc);
ret jvsplit(0.25,
withMargin(withTitle("Dialog History", onChange(dm_textArea('dialogHistory), rstCalc))),
northCenterAndSouthWithMargins(
centerAndEastWithMargin(
tf,
jbutton("Make rule...", rThread { dm_gazelle_newRuleDialog_2(input) })),
super.visualize(),
vstackWithSpacing(
rightAlignedButtons(
treeDependentButton(jTree, "Mark good", rMark('good)),
treeDependentButton(jTree, "Mark bad", rMark('bad)),
treeDependentButton(jTree, "Mark funny", rMark('funny))
),
lblInfo = jlabel()
)));
}
visualize2 {
ret jscroll(jTree);
}
Runnable rMark(fS judgement) {
ret rThread {
GazelleTree e = selected();
e.judgement = judgement;
jTree_fireUserObjectChanged(jTree, e);
saveEntry(e);
};
}
GazelleTree selected() {
ret (GazelleTree) jtree_selectedUserObject(jTree);
}
void calc {
S input = this.input;
root = new GazelleTree(input);
jTree_setRootObject(jTree, root);
jtree_collapseAndOpenRootNode(jTree);
processedInput = input;
}
L gt_getChildren(GazelleTree tree) {
if (tree == null) null;
if (tree.children != null) ret tree.children;
// make rule engine etc.
if (tree.ctx == null) {
new EvalContext ctx;
tree.ctx = ctx;
ctx.engine = new RuleEngine2;
ctx.engine.addRules2(dm_allRulesFromRulesModuleWithCommentsAndIDs());
// gather data for predictor
MultiMap statementsByRule = ai_gazelle_indexStatementsByRule(dm_gazelle_statementsFromAppliedRules());
ctx.dataByRule = mapValues ai_gazelle_analyzeStatementsForRule(multiMapToMap(statementsByRule));
}
EvalContext ctx = tree.ctx;
new L children;
SS inputMap = litmap(standard := tree.line);
LS history = concatLists(tlft(dialogHistory), tree.history());
for (int i = 0; i < l(history); i++)
inputMap.put("dialog-" + (l(history)-i), history.get(i));
L l = sortByMethodDesc qualitySum(ai_ruleEngine2_rulesForInput_5_allConditions(tree.ctx.engine, inputMap, debug := false));
print("Got rules: " + l(l));
for (RuleEngine2_MatchedRule r : l) {
if (r.relativeQuality() < qualityCutOff) continue;
S line = r.applyMappingTo(r.rule.out);
GazelleTree child = new(line);
child.parent = tree;
child.ctx = tree.ctx;
child.mr = r;
ai_gazelle_analyzeStatementsForRule_Data data = ctx.dataByRule.get(r.rule.globalID);
child.prediction = data == null ? null : ai_gazelle_predictor1_onData(r, data);
children.add(child);
}
sortByCalculatedFieldDesc(children, func(GazelleTree c) -> int { ai_goodBadToInt(c.prediction) });
ret tree.children = children;
}
void saveEntry(GazelleTree e) {
S modifiedRule = e.ctx.engine.formatForUser(e.mr.applyMapping().asText());
dm_gazelle_saveAppliedRule(
+modifiedRule,
judgement := e.judgement,
matchedRuleStruct := struct(e.mr));
}
void updateInfo enter {
S s = " ";
GazelleTree e = selected();
if (e != null && e.mr != null)
s = "Rule: " + e.mr.rule.globalID;
setText(lblInfo, s);
}
}