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).

1  
!7
2  
3  
sclass BottomUpParser > DynSCPWithInput {
4  
  start {
5  
    dm_useLocallyCopiedMechLists(); set flag NoFancyMechParsing.
6  
  }
7  
  
8  
  void update(S s) {
9  
    temp enter();
10  
    if (!isShowing()) { inputChooser.forgetInput(); ret; }
11  
    
12  
    final new AI_BottomUpParser1 parser;
13  
    parser.parse(s);
14  
    AI_BottomUpParser1.Word w = parser.fullGroup();
15  
    print("Full group: " + w);
16  
    if (w == null) ret;
17  
    final L<WeightedProduction> productions = ai_buParser_parseWeightedProductions();
18  
    print("Have " + n2(productions, "production"));
19  
    
20  
    class ChooseCategory {
21  
      AI_BottomUpParser1.Word word;
22  
      L<S> categories;
23  
      
24  
      *(AI_BottomUpParser1.Word *word, L<S> *categories) {}
25  
26  
      toString { ret word.text() + " (" + n2(categories, "category", "categories") + ")"; }
27  
    }
28  
    
29  
    class HaveCategory {
30  
      AI_BottomUpParser1.Word word;
31  
      S category;
32  
      
33  
      *(AI_BottomUpParser1.Word *word, S *category) {}
34  
      
35  
      toString { ret quote(word.text()) + " as " + category; }
36  
    }
37  
    
38  
    class ChoosePart {
39  
      ai_Reconstructed reconstruction;
40  
      
41  
      *(ai_Reconstructed *reconstruction) {}
42  
      
43  
      toString { ret reconstruction.a.text() + " + " + reconstruction.b.text(); }
44  
    }
45  
    
46  
    ChooseCategory root = new(w, asList(w.classes));
47  
    
48  
    setComponent(jDynamicTree(root, func(fO e) -> L<O> {
49  
      if (e instanceof ChooseCategory)
50  
        ret map(((ChooseCategory) e).word.classes, func(S cat) { new HaveCategory(((ChooseCategory) e).word, cat) });
51  
      if (e instanceof HaveCategory) {
52  
        HaveCategory h = cast e;
53  
        L<ai_Reconstructed> l = ai_buParser1_reconstructedProductions(parser, productions, h.word, h.category);
54  
        ret map(l, func(ai_Reconstructed r) -> O {
55  
          r.production.b == null
56  
            ? new HaveCategory(r.a, r.production.a)
57  
            : new ChoosePart(r)
58  
        });
59  
      }
60  
      if (e instanceof ChoosePart) {
61  
        ai_Reconstructed r = ((ChoosePart) e).reconstruction;
62  
        ret (L) ll(new HaveCategory(r.a, r.production.a),
63  
          new HaveCategory(r.b, r.production.b));
64  
      }
65  
      null;
66  
    }));
67  
    print("Made tree");
68  
  }
69  
}

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: 283 / 472
Version history: 23 change(s)
Referenced in: [show references]