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

36
LINES

< > BotCompany Repo | #1017412 // ai_parseTree_simplifiedTexts v2 (working on)

JavaX fragment (include)

1  
static LinkedHashSet<S> ai_parseTree_simplifiedTexts(PTElement e) {
2  
  new LinkedHashSet<S> out;
3  
  ai_parseTree_simplifiedTexts_collect(e, out);
4  
  ret out;
5  
}
6  
7  
svoid ai_parseTree_simplifiedTexts_collect(PTElement e, LinkedHashSet<S> out) {
8  
  if (e == null) ret;
9  
  if (e instanceof ChoosePart) {
10  
    ai_Reconstructed r = e/ChoosePart.reconstruction;
11  
    WeightedProduction prod = r.production;
12  
    //print("Hint: " + prod.simplificationHint + " in prod: " + sfu(prod));
13  
    //if (eq(prod.simplificationHint, "L")) out.add(r.a.text());
14  
    //else if (eq(prod.simplificationHint, "R")) out.add(r.b.text());
15  
    
16  
    PTElement e1 = first(e.children), e2 = second(e.children);
17  
    L<S> a = asList(ai_parseTree_simplifiedTexts(e1));
18  
    L<S> b = asList(ai_parseTree_simplifiedTexts(e2));
19  
    
20  
    S hint = prod.simplificationHint;
21  
    if (eqOneOf(hint, "L", "B")) insertFirst(b, "");
22  
    else if (eqOneOf(hint, "R", "B")) insertFirst(a, "");
23  
    
24  
    //print("L " + className(e1) + " " + className(ai_parseTree_descendToComposite(e1)) + " " + r.a.text() + " => " + a);
25  
    //print("R " + className(e2) + " " + className(ai_parseTree_descendToComposite(e2)) + " " + r.b.text() + " => " + b);
26  
    
27  
    for (S aa : a)
28  
      for (S bb : b)
29  
        out.add(trim(aa + " " + bb));
30  
  } else
31  
    for (PTElement child : unnull(e.children))
32  
      ai_parseTree_simplifiedTexts_collect(child, out);
33  
  
34  
  // Add full text too
35  
  out.add(e.text());
36  
}

Author comment

Began life as a copy of #1017408

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: #1017412
Snippet name: ai_parseTree_simplifiedTexts v2 (working on)
Eternal ID of this version: #1017412/1
Text MD5: e0c73c6afb0285a3a38c1f3da9d8b182
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-19 21:42:00
Source code size: 1461 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 267 / 307
Referenced in: [show references]