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

19
LINES

< > BotCompany Repo | #1000814 // dropPunctuation

JavaX fragment (include)

static L<S> dropPunctuation_keep = ll("*", "<", ">");

static L<S> dropPunctuation(L<S> tok) {
  tok = new ArrayList<S>(tok);
  for (int i = 1; i < tok.size(); i += 2) {
    S t = tok.get(i);
    if (t.length() == 1 && !Character.isLetter(t.charAt(0)) && !Character.isDigit(t.charAt(0)) && !dropPunctuation_keep.contains(t)) {
      tok.set(i-1, tok.get(i-1) + tok.get(i+1));
      tok.remove(i);
      tok.remove(i);
      i -= 2;
    }
  }
  return tok;
}

static S dropPunctuation(S s) {
  ret join(dropPunctuation(nlTok(s)));
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000814
Snippet name: dropPunctuation
Eternal ID of this version: #1000814/2
Text MD5: 3a7b382cc003e763b3b4aa108e2cc03a
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-15 20:33:11
Source code size: 549 bytes / 19 lines
Pitched / IR pitched: No / No
Views / Downloads: 795 / 7659
Version history: 1 change(s)
Referenced in: #1002427 - Accellerating 629 (SPIKE)
#1002702 - dropPunctuationExcept
#1003078 - dropPunctuation2 - uses nlTok2
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1008344 - dropPunctuationAtEnd
#1024521 - dropPunctuation3 [experimental]
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)