Libraryless. Click here for Pure Java version (2653L/17K).
static LS greedySplitIntoWordsCI(S s, Cl<S> words) { TreeSet<S> wordsSet = asCISet(words); int i = 0, last = 0; new LS out; while (i < l(s)) { S word = longestPrefixInCISet(substring(s, i), wordsSet); if (nempty(word)) { addIfNempty(out, substring(s, last, i)); out.add(substring(s, i, i+l(word)); last = i = i+l(word); } else ++i; } addIfNempty(out, substring(s, last, i)); ret out; }
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: | 172 / 277 |
Version history: | 4 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1028149 - greedySplitIntoWordsCI_withChoices [dev.] #1028153 - greedySplitIntoWordsCI with choices Spike [OK] |