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

27
LINES

< > BotCompany Repo | #1028730 // findOneArgumentPatterns

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3508L/22K).

/*
finds patterns with a single changing token occurring at least twice

inputs e.g. (with map splitAtSpaceTok(tlft(...))):
  kgopkgorkgorkogrkkkbla makes sense
  heldfdfdkfodkfodfkodlo makes sense
  but 12345! makes no sense
  but b1lubb makes no sense
  
will find:
  * makes sense [2]
  but * makes no sense [2]
*/

static MultiSet<S> findOneArgumentPatterns(LLS toks) {
  MultiSet<S> patterns = ciMultiSet();
  MultiMap<Int, LS> byLength = indexListsByLength(lambdaMap simpleSpacesAndTrim(toks));

  for (LLS toks2 : byLength.values()) {
    for (int i = 1; i < l(first(toks2))-1; i += 2) {
      int _i = i;
      MultiSet<S> set = mapToCIMultiSet(toks2, tok -> join(cloneListReplacingElementAtIndex(tok, _i, "*")));
      patterns.addAll(multiSetWithoutSingles(set));
    }
  }
  ret patterns;
}

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: #1028730
Snippet name: findOneArgumentPatterns
Eternal ID of this version: #1028730/2
Text MD5: 7e15a1b98e8715804089d7d160b67883
Transpilation MD5: 7a3b207fd6943659a94247f32d1a2297
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-06 16:23:34
Source code size: 827 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 189 / 266
Version history: 1 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1028731 - test_findOneArgumentPatterns