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

51
LINES

< > BotCompany Repo | #1001581 // Simplest Assoc Bot (pure map, works)

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

Libraryless. Click here for Pure Java version (2152L/14K/47K).

!752

static new Map<S, S> map;
static S chatName = "Assoc Bot";

p {
  readLocally("map");
  makeAndroid3("Simplest Assoc Bot at " + getComputerID() + ".");
  if (chatName != null)
    toChat();
}

static void toChat() {
  while (true) {
    pcall {
      for (ChatLine l : suckHumans(chatName))
        sayInWebChat(chatName, answer(l.text));
    }
    sleep(1000);
  }
}

static S lookup(S s) {
  ret map.get(simplify(s));
}

// should simplify a sentence neatly
static S simplify(S s) {
  S result = join(" ", codeTokensOnly(tokensToLowerCase(nlTok(s))));
  print(s);
  print("=> " + result);
  ret result;
}

static synchronized S answer(S input) {
  L<S> tok = nlTok(input);
  int idx = tok.indexOf("=");
  if (idx >= 0) {
    S l = join(tok.subList(0, idx)).trim();
    S r = join(tok.subList(idx+1, l(tok))).trim();
    l = simplify(l);
    S prev = map.get(l);
    if (prev != null && eq(simplify(prev), simplify(r)))
      ret "yup, i know";
    map.put(l, r);
    saveLocally("map");
    ret prev == null ? "ok, new" : "ok, changed from: " + quote(prev);
  }
  
  ret lookup(input);
}

Author comment

Began life as a copy of #1001294

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: #1001581
Snippet name: Simplest Assoc Bot (pure map, works)
Eternal ID of this version: #1001581/1
Text MD5: 888eedeca25161c161c3ae516d665113
Transpilation MD5: 216b2bf70eb45e7ee7d4b851c11a99f7
Author: stefan
Category: leopold
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-01 01:14:21
Source code size: 1147 bytes / 51 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 557 / 584
Referenced in: [show references]