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

43
LINES

< > BotCompany Repo | #1017523 // switcheroo_noMech - switch first/second person (old version without mech list)

JavaX fragment (include)

static L<S> switcheroo_themap = ll(
  "mine", "yours",
  "my", "your",
  "you are", "i am",
  "are you", "am i",
  "you're", "i'm",
  "you've", "i've",
  "me", "you",
  "i", "you",
);

static S switcheroo_noMech(S s) {
  L<S> tok = nlTok5(s);
  for (int i = 1; i < l(tok); i += 2) {
    for (int j = 0; j < l(switcheroo_themap); j += 2) {
      S x = switcheroo_themap.get(j), y = switcheroo_themap.get(j+1);
      L<S> tokx = nlTok5(x), toky = nlTok5(y);
      switcheroo_matchReplace(tok, i, tokx, toky);
      switcheroo_matchReplace(tok, i, toky, tokx);
    }
  }
  ret join(map(f switcheroo_dropAsterisk, tok));
}

sS switcheroo_dropAsterisk(S t) {
  ret startsWith(t, "*") && l(t) > 1 ? substring(t, 1) : t;
}

static void switcheroo_matchReplace(L<S> tok, int i, L<S> tokx, L<S> toky) {
  //printFormat("Matching * * *", i, get(tok, i), tokx);
  if (switcheroo_tokRegionMatch(tok, i, tokx)) {
    //printFormat("Replacing * *", tokx, toky);
    for (int j = 0; j*2+1 < l(tokx); j++)
      tok.set(i+j*2, "*" + toky.get(1+j*2));
  }
}

static bool switcheroo_tokRegionMatch(L<S> tok, int i, L<S> tokx) {
  for (int j = 0; j*2+1 < l(tokx); j++)
    if (!eqic(get(tok, i+j*2), get(tokx, 1+j*2)))
      ret false;
  ret true;
}

Author comment

Began life as a copy of #1009569

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1017523
Snippet name: switcheroo_noMech - switch first/second person (old version without mech list)
Eternal ID of this version: #1017523/1
Text MD5: 47194fc97ed9ec4e206bb1fa6f053da1
Author: stefan
Category: nl
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-25 16:46:19
Source code size: 1272 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 326 / 340
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)