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

108
LINES

< > BotCompany Repo | #1021559 // Listening Comprehension

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (19102L/111K).

!7

set flag DynModule.

cmodule ListeningComprehension > DynModule {
  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;
  
  S switchableFields() { ret "skipBadPredictions maxResults"; }
  
  enhanceFrame { internalFrameIcon(f, gazelle_frameIcon()); }
  
  start {
    dm_vmBus_onMessage('gazelleRulesChanged, rstCalc);
  }
  
  visualize {
    jTree = jDynamicTree(null, func(GazelleTree tree) -> L<GazelleTree> {
      dm_gazelle_getChildren(tree, +qualityCutOff, dialogHistory := tlft(text))
    }, 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, "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)) }),
        jscroll(jTree),
        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 = selected();
      e.judgement = judgement;
      jTree_fireUserObjectChanged(jTree, e);
      saveEntry(e);
    };
  }
  
  GazelleTree selected() {
    ret (GazelleTree) jtree_selectedUserObject(jTree);
  }
  
  void calc {
    root = new GazelleTree(joinLinesWithBarOrPunctuation(text));
    jTree_setRootObject(jTree, root);
    jtree_collapseAndOpenRootNode(jTree);
    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 = selected();
    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));
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1021559
Snippet name: Listening Comprehension
Eternal ID of this version: #1021559/8
Text MD5: e480b8f1d6474ff2dcd06c5e69b36ea8
Transpilation MD5: a3960ede1ecccdddab8c8ee3675d18cd
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-18 21:16:02
Source code size: 3498 bytes / 108 lines
Pitched / IR pitched: No / No
Views / Downloads: 289 / 1060
Version history: 7 change(s)
Referenced in: #1021505 - Gazelle Tabs
#1021581 - Listening Comprehension v2 [dev.]