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

18
LINES

< > BotCompany Repo | #1028149 // greedySplitIntoWordsCI_withChoices [dev.]

JavaX fragment (include)

1  
static WithChoices<LS> greedySplitIntoWordsCI_withChoices(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  
    int longest = l(longestPrefixInCISet(substring(s, i), wordsSet));
7  
    for (int j = l(s); j > i; j--)
8  
      if (contains(wordsSet, substring(s, i, j))) {
9  
        S word = prefixesInCISet(, wordsSet);
10  
    if (nempty(word)) {
11  
      addIfNempty(out, substring(s, last, i));
12  
      out.add(substring(s, i, i+l(word));
13  
      last = i = i+l(word);
14  
    } else ++i;
15  
  }
16  
  addIfNempty(out, substring(s, last, i));
17  
  ret out;
18  
}

Author comment

Began life as a copy of #1028147

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: #1028149
Snippet name: greedySplitIntoWordsCI_withChoices [dev.]
Eternal ID of this version: #1028149/1
Text MD5: e9e13080f56c1700c4766d807c17a270
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:42:44
Source code size: 612 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 206 / 218
Referenced in: [show references]