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

51
LINES

< > BotCompany Repo | #1008579 // Find multi-word verbs in sentence [WORKS]

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

Libraryless. Click here for Pure Java version (3599L/24K/79K).

1  
!7
2  
3  
static L<S> verbs = toLinesFullTrim([[
4  
  kow towed
5  
  made
6  
  started
7  
  want
8  
]]);
9  
10  
static new StringTree1 tree;
11  
12  
p {
13  
  tree = multiWordMap_lower(verbs);
14  
  testAnswerFunction([[
15  
    he kow towed before them
16  
    i want stuff
17  
    kow
18  
    towed
19  
    I WANT YOU
20  
  ]]);
21  
  botSleep();
22  
}
23  
24  
static L<S> parse(S s) {
25  
  ret codeTokens(nlTok4(lower(s)));
26  
}
27  
28  
static StringTree1 multiWordMap_lower(L<S> items) {
29  
  new StringTree1 tree;
30  
  for (S s : items) {
31  
    L<S> tok = parse(s);
32  
    addToStringTree(tree, tok);
33  
  }
34  
  ret tree;
35  
}
36  
37  
sS answer(S s) {
38  
  L<S> tok = parse(s);
39  
  new L<S> verbs;
40  
  for i over tok: {
41  
    StringTree1 tree = main.tree;
42  
    int j = i;
43  
    while (tree != null && j < l(tok)) {
44  
      if (tree.leaf)
45  
        verbs.add(joinWithSpace(subList(tok, i, j)));
46  
      tree = tree.children.get(tok.get(j));
47  
      ++j;
48  
    }
49  
  }
50  
  ret join(", ", verbs);
51  
}

Author comment

Began life as a copy of #1008567

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1008579
Snippet name: Find multi-word verbs in sentence [WORKS]
Eternal ID of this version: #1008579/9
Text MD5: 6ebdf78cfd011ef36f00e9c53a67ed86
Transpilation MD5: 7075f63e83b7d3725b251fb4473ac3b2
Author: stefan
Category: javax / a.i.
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-05-26 19:28:56
Source code size: 904 bytes / 51 lines
Pitched / IR pitched: No / No
Views / Downloads: 342 / 451
Version history: 8 change(s)
Referenced in: [show references]