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

27
LINES

< > BotCompany Repo | #1017396 // ai_parseTree_getChildren - makes them too

JavaX fragment (include)

1  
static L<PTElement> ai_parseTree_getChildren(AI_BottomUpParser1 parser, L<WeightedProduction> productions, PTElement e) {
2  
  if (e.children == null) {
3  
    e.children = ai_parseTree_makeChildren(parser, productions, e);
4  
    for (PTElement child : unnull(e.children)) child.parent = e;
5  
  }
6  
  ret e.children;
7  
}
8  
9  
static L<PTElement> ai_parseTree_makeChildren(AI_BottomUpParser1 parser, L<WeightedProduction> productions, final PTElement e) {
10  
  if (e instanceof ChooseCategory)
11  
    ret map(((ChooseCategory) e).categories, func(S cat) -> PTElement { new HaveCategory(((ChooseCategory) e).word, cat) });
12  
  if (e instanceof HaveCategory) {
13  
    final HaveCategory h = cast e;
14  
    L<ai_Reconstructed> l = ai_buParser1_reconstructedProductions(parser, productions, h.word, h.category);
15  
    ret map(l, func(ai_Reconstructed r) -> PTElement {
16  
      r.production.b == null
17  
        ? new HaveCategory(r.a, r.production.a, r)
18  
        : new ChoosePart(h.word, r)
19  
    });
20  
  }
21  
  if (e instanceof ChoosePart) {
22  
    ai_Reconstructed r = ((ChoosePart) e).reconstruction;
23  
    ret (L) ll(new HaveCategory(r.a, r.production.a),
24  
      new HaveCategory(r.b, r.production.b));
25  
  }
26  
  null;
27  
}

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: #1017396
Snippet name: ai_parseTree_getChildren - makes them too
Eternal ID of this version: #1017396/17
Text MD5: cfedef6e80217009b0d2e8c0d5f3035e
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-09-27 12:54:44
Source code size: 1188 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 465 / 529
Version history: 16 change(s)
Referenced in: [show references]