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

31
LINES

< > BotCompany Repo | #1017269 // 3 words in pattern, 5 in sentence Spike [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (6712L/47K).

1  
!7
2  
3  
p-exp {
4  
  S sentence = "Are atomic bombs powerful devices ?";
5  
  S pat = "Are <noun> <noun>?";
6  
  
7  
  L<S> tokPat = javaTokWithAngularBracketsC(pat);
8  
  L<S> tokS = javaTokWithAngularBracketsC(sentence);
9  
  
10  
  printStruct(tokPat);
11  
  printStruct(tokS);
12  
  
13  
  int extra = l(tokS)-l(tokPat);
14  
  L<Int> indices = indicesOfAngleBracketVars(tokPat);
15  
  if (extra <= 0 || empty(indices)) ret with print("Not applicable");
16  
17  
  for (L<Int> spread : allSpreads(extra, l(indices))) {
18  
    new L<S> tok;
19  
    int pos = 0, iSpread = 0;
20  
    for i over tokPat:
21  
      if (!isAngleBracketed(tokPat.get(i)))
22  
        tok.add(tokS.get(pos++));
23  
      else {
24  
        int take = spread.get(iSpread++);
25  
        tok.add(joinWithSpace(subList(tokS, pos, pos+take+1)));
26  
        pos += take+1;
27  
      }
28  
    printStruct(tok);
29  
    print(joinWithSpace(map curlyBraceOptIfMoreThanOneToken(tok)));
30  
  }
31  
}

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: #1017269
Snippet name: 3 words in pattern, 5 in sentence Spike [OK]
Eternal ID of this version: #1017269/18
Text MD5: 3136236e3168c5eedec507a14646eda9
Transpilation MD5: 310fbe555e7852d23aaa6dd9c51550e9
Author: stefan
Category: javax / parsing
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-16 14:24:06
Source code size: 892 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 388 / 1036
Version history: 17 change(s)
Referenced in: [show references]