Libraryless. Click here for Pure Java version (2152L/14K/47K).
1 | !752 |
2 | |
3 | static new Map<S, S> map; |
4 | static S chatName = "Assoc Bot"; |
5 | |
6 | p { |
7 | readLocally("map"); |
8 | makeAndroid3("Simplest Assoc Bot at " + getComputerID() + "."); |
9 | if (chatName != null) |
10 | toChat(); |
11 | } |
12 | |
13 | static void toChat() { |
14 | while (true) { |
15 | pcall { |
16 | for (ChatLine l : suckHumans(chatName)) |
17 | sayInWebChat(chatName, answer(l.text)); |
18 | } |
19 | sleep(1000); |
20 | } |
21 | } |
22 | |
23 | static S lookup(S s) { |
24 | ret map.get(simplify(s)); |
25 | } |
26 | |
27 | // should simplify a sentence neatly |
28 | static S simplify(S s) { |
29 | S result = join(" ", codeTokensOnly(tokensToLowerCase(nlTok(s)))); |
30 | print(s); |
31 | print("=> " + result); |
32 | ret result; |
33 | } |
34 | |
35 | static synchronized S answer(S input) { |
36 | L<S> tok = nlTok(input); |
37 | int idx = tok.indexOf("="); |
38 | if (idx >= 0) { |
39 | S l = join(tok.subList(0, idx)).trim(); |
40 | S r = join(tok.subList(idx+1, l(tok))).trim(); |
41 | l = simplify(l); |
42 | S prev = map.get(l); |
43 | if (prev != null && eq(simplify(prev), simplify(r))) |
44 | ret "yup, i know"; |
45 | map.put(l, r); |
46 | saveLocally("map"); |
47 | ret prev == null ? "ok, new" : "ok, changed from: " + quote(prev); |
48 | } |
49 | |
50 | ret lookup(input); |
51 | } |
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: | 636 / 705 |
Referenced in: | [show references] |