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

68
LINES

< > BotCompany Repo | #1016843 // Dialog Tree v2 with search [Dyn Module, dev.]

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

Uses 408K of libraries. Click here for Pure Java version (15481L/108K).

!7

sclass DialogTree > DynModule {
  new Node root;
  transient JTree tree;
  transient JTextField tfSearch;

  class Node {
    LS text;
    new LinkedHashMap<LS, Node> children;
    
    // flag
    final static int
      funny = 1,
      correctSentence = 2,
      probablyMine = 4;
    
    int flags;
    S language;
    S correctIf;
    
    *() {}
    *(LS *text) {}
    
    toString {
      ret text == null ? "<ROOT>" : joinWithSpace(text);
    }
    
    Node getOrCreate(LS text) {
      ret pairA(getOrCreate2(text));
    }
    
    Pair<Node, Bool> getOrCreate2(LS text) {
      temp enter();
      Node n = children.get(text);
      bool isNew = n == null;
      if (isNew) {
        children.put(text, n = new Node(text));
        change();
      }
      ret pair(n, isNew);
    }
  }
  
  void start {
    addCatLogToRoot();
    onSpeechRecognized_withoutMyUtterances(voidfunc(fS s) {
      swing {
        Pair<Node, Bool> child = root.getOrCreate2(words(s));
        if (child.b) // it's a new child
          jDynamicTree_addToNodeAndScroll(tree, root, child.a);
      }
    });
  }
  
  JComponent visualize() {
    tree = jDynTree(root, func(Node n) -> L<Node> {
      temp enter();
      ret valuesList(n.children);
    });
    ret northAndCenterWithMargin(withLabel("Search:", tfSearch = jtextfield()), tree);
  }
  
  void addCatLogToRoot {
    for (LS text : catLog_wordLists())
      root.getOrCreate(text);
  }
}

Author comment

Began life as a copy of #1016799

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1016843
Snippet name: Dialog Tree v2 with search [Dyn Module, dev.]
Eternal ID of this version: #1016843/2
Text MD5: 16250d00997348fc7887701065bf78c0
Transpilation MD5: 6cf10c0d51d6cc3bb0f810c38b3e0812
Author: stefan
Category: javax / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-05 13:52:00
Source code size: 1508 bytes / 68 lines
Pitched / IR pitched: No / No
Views / Downloads: 347 / 409
Version history: 1 change(s)
Referenced in: [show references]