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

41
LINES

< > BotCompany Repo | #1017199 // Match Input With Pattern v2 [Dyn Module, dev.]

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

Libraryless. Click here for Pure Java version (18227L/129K).

1  
!7
2  
3  
sclass MatchInput > DynPrintLogWithInput {
4  
  start {
5  
    dm_requireModule("#1016073/MechLists");
6  
    useLocalMechListCopies(true);
7  
    set serverMechList_raw_fresh_verbose;
8  
  }
9  
  
10  
  void update(S s) {
11  
    print("\n> " + s);
12  
    L<S> pats = mL("English sentence patterns");
13  
    L<S> tok = javaTokWithAngleBracketsC(s);
14  
    printStruct(tok);
15  
    PlanInMotion<S> plan = new(pats);
16  
    //L<Pair<S, L<Pair<S>>>> results = new L; // pattern + match
17  
    PriorityQueue<Pair<S, L<Pair<S>>>> results = new PriorityQueue<Pair<S, L<Pair<S>>>>(new Comparator<Pair<S, L<Pair<S>>>>() {
18  
      public int compare(Pair<S, L<Pair<S>>> a, Pair<S, L<Pair<S>>> b) {
19  
        //print("cmp " + l(a.b) + " " + l(b.b));
20  
        ret cmp(l(a.b), l(b.b));
21  
      }
22  
    });
23  
    for (S pat : plan.master()) {
24  
      L<S> tokPat;
25  
      tokPat = javaTokWithAngleBracketsC(pat);
26  
      L<Pair<S>> match = uniquify(dropTwinPairsIC(zipTwoListsToPairs_ifSameLength(tokPat, tok)));
27  
      if (match != null) {
28  
        print("  Result: Choose pattern " + quote(pat) + " for input "  + quote(s) + " if match: " + sfu(match));
29  
        results.add(pair(pat, match));
30  
      }
31  
    }
32  
    
33  
    pnlStruct(mapPairB(f l, priorityQueueToList(results));
34  
    
35  
    for (Pair<S, L<Pair<S>>> p : priorityQueueToList(results)) {
36  
      L<S> match = antiFilter(f parsing_checkMatchPairUsingMechList, p.b);
37  
      if (l(match) < l(p.b))  
38  
        print("  Reduced match to: " + sfu(match));
39  
    }
40  
  }
41  
}

Author comment

Began life as a copy of #1017192

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1017199
Snippet name: Match Input With Pattern v2 [Dyn Module, dev.]
Eternal ID of this version: #1017199/16
Text MD5: 76391812336f8bed7c6548e26c64e47c
Transpilation MD5: cfb86847f3d0847771d8c8dcb6379863
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-13 20:26:52
Source code size: 1481 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 352 / 479
Version history: 15 change(s)
Referenced in: [show references]