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)

static LinkedHashSet<S> ai_parseTree_simplifiedTexts(PTElement e) {
  new LinkedHashSet<S> out;
  ai_parseTree_simplifiedTexts_collect(e, out);
  ret out;
}

svoid ai_parseTree_simplifiedTexts_collect(PTElement e, LinkedHashSet<S> out) {
  if (e == null) ret;
  if (e instanceof ChoosePart) {
    ai_Reconstructed r = e/ChoosePart.reconstruction;
    WeightedProduction prod = r.production;
    //print("Hint: " + prod.simplificationHint + " in prod: " + sfu(prod));
    //if (eq(prod.simplificationHint, "L")) out.add(r.a.text());
    //else if (eq(prod.simplificationHint, "R")) out.add(r.b.text());
    
    PTElement e1 = first(e.children), e2 = second(e.children);
    L<S> a = asList(ai_parseTree_simplifiedTexts(e1));
    L<S> b = asList(ai_parseTree_simplifiedTexts(e2));
    
    S hint = prod.simplificationHint;
    if (eqOneOf(hint, "L", "B")) insertFirst(b, "");
    else if (eqOneOf(hint, "R", "B")) insertFirst(a, "");
    
    //print("L " + className(e1) + " " + className(ai_parseTree_descendToComposite(e1)) + " " + r.a.text() + " => " + a);
    //print("R " + className(e2) + " " + className(ai_parseTree_descendToComposite(e2)) + " " + r.b.text() + " => " + b);
    
    for (S aa : a)
      for (S bb : b)
        out.add(trim(aa + " " + bb));
  } else
    for (PTElement child : unnull(e.children))
      ai_parseTree_simplifiedTexts_collect(child, out);
  
  // Add full text too
  out.add(e.text());
}

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: 265 / 304
Referenced in: [show references]