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

48
LINES

< > BotCompany Repo | #1017394 // Parse Tree Classes [Include]

JavaX fragment (include)

sclass PTElement {
  AI_BottomUpParser1.Word word;
  double weight = 1, totalWeight;
  L<PTElement> children;
  PTElement parent;
  
  S plusWeight(S s) {
    if (weight == 1 && totalWeight == 1) ret s;
    S a = formatDouble(weight, 2), b = formatDouble(totalWeight, 2);
    ret s + " [" + a + (eq(a, b) ? "" : ", total " + b) + "]";
  }
  
  S text() { ret word == null ? null : word.text(); }
  S category() { null; }
}

sclass ChooseCategory extends PTElement {
  L<S> categories;
  
  *(AI_BottomUpParser1.Word *word, L<S> *categories) {}

  toString { ret plusWeight(word.text() + " (" + n2(categories, "category", "categories") + ")"); }
}

sclass HaveCategory extends PTElement {
  S category;
  ai_Reconstructed reconstruction; // optional
  
  *(AI_BottomUpParser1.Word *word, S *category) {}
  *(AI_BottomUpParser1.Word *word, S *category, ai_Reconstructed *reconstruction) {}
  
  toString { ret plusWeight(quote(word.text()) + " as " + category); }
  S category() { ret category; }
}

sclass ChoosePart extends PTElement {
  ai_Reconstructed reconstruction;
  
  *(AI_BottomUpParser1.Word *word, ai_Reconstructed *reconstruction) {}
  
  toString {
    S hint = reconstruction.production.simplificationHint;
    ret plusWeight(
      reconstruction.a.text() + " + " + reconstruction.b.text()
        + " [" + reconstruction.production + "]");
  }
  S category() { ret reconstruction.production.c; }
}

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: #1017394
Snippet name: Parse Tree Classes [Include]
Eternal ID of this version: #1017394/24
Text MD5: 4f1ce3a5ac75aa8f3c470499a2922b11
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-23 23:00:17
Source code size: 1462 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 452 / 1094
Version history: 23 change(s)
Referenced in: [show references]