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

66
LINES

< > BotCompany Repo | #1016799 // Dialog Tree v1 [Dyn Module]

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

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

!7

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

  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() {
    ret tree = jDynTree(root, func(Node n) -> L<Node> {
      temp enter();
      ret valuesList(n.children);
    });
  }
  
  void addCatLogToRoot {
    for (LS text : catLog_wordLists())
      root.getOrCreate(text);
  }
}

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: #1016799
Snippet name: Dialog Tree v1 [Dyn Module]
Eternal ID of this version: #1016799/22
Text MD5: f7fa6718e3fd22bda82521127e8f1d5b
Transpilation MD5: 38cc1e184144e3d4d5867b6408c6a498
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:37:27
Source code size: 1390 bytes / 66 lines
Pitched / IR pitched: No / No
Views / Downloads: 549 / 1690
Version history: 21 change(s)
Referenced in: [show references]