Uses 911K of libraries. Click here for Pure Java version (19188L/111K).
!7 set flag DynModule. sclass Entry { S line; transient GazelleTree treeNode; } cmodule ListeningComprehension > DynObjectTable<Entry> { S processedInput, text; 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; transient Set<S> linesSet; S switchableFields() { ret "skipBadPredictions maxResults"; } enhanceFrame { internalFrameIcon(f, gazelle_frameIcon()); } start { hideFields('treeNode); dm_vmBus_onMessage('gazelleRulesChanged, rstCalc); } visualize { jTree = jDynamicTree/*_concurrent*/(null, func(GazelleTree tree) -> L<GazelleTree> enter { ret dm_gazelle_getChildren(tree, +qualityCutOff, dialogHistory := tlft(text)); }, makeChildrenIsFast := false); 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, "Mark good", rMark('good)); addMenuItem(menu, "Mark bad", rMark('bad)); addMenuItem(menu, "Mark funny", rMark('funny)); addMenuItem(menu, "Enter", rThread { LS history = e.history(); /*if (oddLength(history)) setField(input := popLast(history));*/ setField(text := lines(history)); }); }); ret jvsplit(0.25, withMargin(withTitle("Input Text", onChange(dm_textArea('text), rstCalc))), northCenterAndSouthWithMargins( rightAlignedButtons( "Make rule...", rThread { dm_gazelle_newRuleDialog_2(firstLine(text)) }), jhsplit( withTitle("Gazelle Tree", jTree), withTitle("Generated Lines", super.visualize())), vstackWithSpacing( rightAlignedButtons( treeDependentButton(jTree, "Mark good", rMark('good)), treeDependentButton(jTree, "Mark bad", rMark('bad)), treeDependentButton(jTree, "Mark funny", rMark('funny)), jPopDownButton_noText( "Export Rule Engine", rThread exportEngine) ), lblInfo = jlabel() ))); } Runnable rMark(fS judgement) { ret rThread { GazelleTree e = selectedNode(); e.judgement = judgement; jTree_fireUserObjectChanged(jTree, e); saveEntry(e); }; } GazelleTree selectedNode() { ret (GazelleTree) jtree_selectedUserObject(jTree); } void calc { linesSet = syncLinkedHashSet(); root = new GazelleTree(joinLinesWithBarOrPunctuation(text)); GazelleEvalContext ctx = dm_gazelle_stdEvalContext(); clear(); ctx.onNewNode = addListener(ctx.onNewNode, voidfunc(GazelleTree t) { if (linesSet.add(t.line)) add(nu Entry(line := t.line, treeNode := t)); }); root.setContext(ctx); jTree_setRootObject(jTree, root); jtree_collapseAndOpenRootNode(jTree); dm_gazelle_expandTree(root); processedInput = text; } 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 = selectedNode(); if (e != null && e.mr != null) { RuleEngine2.Rule r = e.mr.rule; s = "Rule: " + r.globalID + " (" + newLinesToSpaces_trim(r.text) + ")"; } setText(lblInfo, s); } void exportEngine enter { showText("Rule Engine", structWordWrap(root.ctx)); } }
Began life as a copy of #1021559
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: | #1021581 |
Snippet name: | Listening Comprehension v2 [dev.] |
Eternal ID of this version: | #1021581/16 |
Text MD5: | f173d7e364b56a8b6ac1f111f40cdea5 |
Transpilation MD5: | 25449ff4b45dfc6c399c115e9d9a91eb |
Author: | stefan |
Category: | javax / stefan's os / gazelle |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-02-19 17:09:00 |
Source code size: | 4115 bytes / 126 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 380 / 1066 |
Version history: | 15 change(s) |
Referenced in: | [show references] |