Libraryless. Click here for Pure Java version (2653L/17K).
1 | static LS greedySplitIntoWordsCI(S s, Cl<S> words) { |
2 | TreeSet<S> wordsSet = asCISet(words); |
3 | int i = 0, last = 0; |
4 | new LS out; |
5 | while (i < l(s)) { |
6 | S word = longestPrefixInCISet(substring(s, i), wordsSet); |
7 | if (nempty(word)) { |
8 | addIfNempty(out, substring(s, last, i)); |
9 | out.add(substring(s, i, i+l(word)); |
10 | last = i = i+l(word); |
11 | } else ++i; |
12 | } |
13 | addIfNempty(out, substring(s, last, i)); |
14 | ret out; |
15 | } |
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1028147 |
Snippet name: | greedySplitIntoWordsCI |
Eternal ID of this version: | #1028147/5 |
Text MD5: | 3b119c2bddf0c31438b0ed1166ea2948 |
Transpilation MD5: | 719a9dec3dc545c5a38f78ca96f37a77 |
Author: | stefan |
Category: | javax / stefan's os / nlp |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-05-23 16:34:10 |
Source code size: | 443 bytes / 15 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 171 / 277 |
Version history: | 4 change(s) |
Referenced in: | [show references] |