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).

1  
!7
2  
3  
sclass DialogTree > DynModule {
4  
  new Node root;
5  
  transient JTree tree;
6  
  transient JTextField tfSearch;
7  
8  
  class Node {
9  
    LS text;
10  
    new LinkedHashMap<LS, Node> children;
11  
    
12  
    // flag
13  
    final static int
14  
      funny = 1,
15  
      correctSentence = 2,
16  
      probablyMine = 4;
17  
    
18  
    int flags;
19  
    S language;
20  
    S correctIf;
21  
    
22  
    *() {}
23  
    *(LS *text) {}
24  
    
25  
    toString {
26  
      ret text == null ? "<ROOT>" : joinWithSpace(text);
27  
    }
28  
    
29  
    Node getOrCreate(LS text) {
30  
      ret pairA(getOrCreate2(text));
31  
    }
32  
    
33  
    Pair<Node, Bool> getOrCreate2(LS text) {
34  
      temp enter();
35  
      Node n = children.get(text);
36  
      bool isNew = n == null;
37  
      if (isNew) {
38  
        children.put(text, n = new Node(text));
39  
        change();
40  
      }
41  
      ret pair(n, isNew);
42  
    }
43  
  }
44  
  
45  
  void start {
46  
    addCatLogToRoot();
47  
    onSpeechRecognized_withoutMyUtterances(voidfunc(fS s) {
48  
      swing {
49  
        Pair<Node, Bool> child = root.getOrCreate2(words(s));
50  
        if (child.b) // it's a new child
51  
          jDynamicTree_addToNodeAndScroll(tree, root, child.a);
52  
      }
53  
    });
54  
  }
55  
  
56  
  JComponent visualize() {
57  
    tree = jDynTree(root, func(Node n) -> L<Node> {
58  
      temp enter();
59  
      ret valuesList(n.children);
60  
    });
61  
    ret northAndCenterWithMargin(withLabel("Search:", tfSearch = jtextfield()), tree);
62  
  }
63  
  
64  
  void addCatLogToRoot {
65  
    for (LS text : catLog_wordLists())
66  
      root.getOrCreate(text);
67  
  }
68  
}

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: 415 / 498
Version history: 1 change(s)
Referenced in: [show references]