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: 582 / 1634
Referenced in: [show references]