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

54
LINES

< > BotCompany Repo | #1002165 // Switch first/second person

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1674L/11K/37K).

!752

static L<S> themap = litlist(
  "mine", "yours",
  "my", "your",
  "you are", "i am",
  "are you", "am i",
  "for me", "for you",
  "against me", "against you",
  "with me", "with you",
  "without me", "without you",
  "i", "you",
  "me", "you"
);

p {
  makeBot("Switcheroo");
}

answer {
  if (matchStart("switcheroo", s, m)) {
    S rest = m.rest();
    ret switcheroo(rest);
  }
}

static S switcheroo(S s) {
  L<S> tok = javaTok(s);
  for (int i = 1; i < l(tok); i += 2) {
    for (int j = 0; j < l(themap); j += 2) {
      S x = themap.get(j), y = themap.get(j+1);
      L<S> tokx = javaTok(x), toky = javaTok(y);
      matchReplace(tok, i, tokx, toky);
      matchReplace(tok, i, toky, tokx);
    }
  }
  ret join(tok);
}

static void matchReplace(L<S> tok, int i, L<S> tokx, L<S> toky) {
  //printFormat("Matching * * *", i, get(tok, i), tokx);
  if (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 boolean 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;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002165
Snippet name: Switch first/second person
Eternal ID of this version: #1002165/1
Text MD5: 42bc554505461090bec34066caa4a1a7
Transpilation MD5: c2611c559f1584feaa0f6aee33a0f928
Author: stefan
Category: nl
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-23 00:16:41
Source code size: 1270 bytes / 54 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 650 / 1727
Referenced in: #1002187 - Everything to present tense ("topresent"/"pt")
#1009569 - switcheroo - switch first/second person - synonym of switcheroo_youToI
#3000169 - Answer for stefanreich
#3000174 - Answer for stefanreich
#3000175 - Answer for stefanreich
#3000176 - Answer for stefanreich
#3000177 - Answer for stefanreich
#3000179 - Answer for stefanreich
#3000180 - Answer for stefanreich
#3000181 - Answer for stefanreich
#3000182 - Answer for stefanreich
#3000184 - Answer for stefanreich
#3000185 - Answer for stefanreich
#3000202 - Answer for stefanreich (>> T conversion bot)
#3000203 - Answer for stefanreich (>> timing hello bot)
#3000208 - Answer for bgrgndz (>> list sub bots)
#3000209 - Answer for bgrgndz (>> list sub bots)
#3000238 - Answer for stefanreich (>> t power bot)
#3000369 - Answer for Stefan (>> list sub bots)
#3000376 - Answer for stefanreich (>> list sub bots)
#3000377 - Answer for stefanreich (>> timing eleu?)
#3000380 - Answer for stefanreich (>> list sub bots)
#3000381 - Answer for speedforce (>> list sub bots)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)