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

69
LINES

< > BotCompany Repo | #1017392 // English Parse Tree [OK!]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (18760L/136K).

!7

sclass BottomUpParser > DynSCPWithInput {
  start {
    dm_useLocallyCopiedMechLists(); set flag NoFancyMechParsing.
  }
  
  void update(S s) {
    temp enter();
    if (!isShowing()) { inputChooser.forgetInput(); ret; }
    
    final new AI_BottomUpParser1 parser;
    parser.parse(s);
    AI_BottomUpParser1.Word w = parser.fullGroup();
    print("Full group: " + w);
    if (w == null) ret;
    final L<WeightedProduction> productions = ai_buParser_parseWeightedProductions();
    print("Have " + n2(productions, "production"));
    
    class ChooseCategory {
      AI_BottomUpParser1.Word word;
      L<S> categories;
      
      *(AI_BottomUpParser1.Word *word, L<S> *categories) {}

      toString { ret word.text() + " (" + n2(categories, "category", "categories") + ")"; }
    }
    
    class HaveCategory {
      AI_BottomUpParser1.Word word;
      S category;
      
      *(AI_BottomUpParser1.Word *word, S *category) {}
      
      toString { ret quote(word.text()) + " as " + category; }
    }
    
    class ChoosePart {
      ai_Reconstructed reconstruction;
      
      *(ai_Reconstructed *reconstruction) {}
      
      toString { ret reconstruction.a.text() + " + " + reconstruction.b.text(); }
    }
    
    ChooseCategory root = new(w, asList(w.classes));
    
    setComponent(jDynamicTree(root, func(fO e) -> L<O> {
      if (e instanceof ChooseCategory)
        ret map(((ChooseCategory) e).word.classes, func(S cat) { new HaveCategory(((ChooseCategory) e).word, cat) });
      if (e instanceof HaveCategory) {
        HaveCategory h = cast e;
        L<ai_Reconstructed> l = ai_buParser1_reconstructedProductions(parser, productions, h.word, h.category);
        ret map(l, func(ai_Reconstructed r) -> O {
          r.production.b == null
            ? new HaveCategory(r.a, r.production.a)
            : new ChoosePart(r)
        });
      }
      if (e instanceof ChoosePart) {
        ai_Reconstructed r = ((ChoosePart) e).reconstruction;
        ret (L) ll(new HaveCategory(r.a, r.production.a),
          new HaveCategory(r.b, r.production.b));
      }
      null;
    }));
    print("Made tree");
  }
}

Author comment

Began life as a copy of #1017376

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: #1017392
Snippet name: English Parse Tree [OK!]
Eternal ID of this version: #1017392/24
Text MD5: 15bc6485a2e60998bf72817a6eca6e64
Transpilation MD5: 77a016788cb135eedf02b3ef6eefad1d
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-19 18:24:21
Source code size: 2213 bytes / 69 lines
Pitched / IR pitched: No / No
Views / Downloads: 355 / 546
Version history: 23 change(s)
Referenced in: [show references]