Libraryless. Click here for Pure Java version (2302L/15K/50K).
!752 m { static new MultiMap<S, S> map; static S name = "Multi Assoc Bot"; static boolean chatEnabled = true; p { readLocally("map"); makeAndroid3(name + " at " + getComputerID() + "."); if (chatEnabled) toChat(); } static void toChat() { while (true) { pcall { for (ChatLine l : suckHumans(name)) sayInWebChat(name, answer(l.text)); } sleep(1000); } } static L<S> lookup(S s) { ret map.get(simplify(s)); } // should simplify a sentence neatly static S simplify(S s) { // TODO: probably leave case of quoted strings intact 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); L<S> values = map.get(l); int i = indexOfSentence(values, r); // standard case (new value) if (i < 0) { map.put(l, r); saveLocally("map"); ret "ok, added"; } // already latest value if (i == values.size()-1) ret "yup, i know :)"; // reordering case values.add(r); values.remove(i); saveLocally("map"); ret "ok, moving value to end"; } L<S> values = lookup(input); if (values.isEmpty()) ret null; ret input + "=" + join(", ", values); } static int indexOfSentence(L<S> l, S sentence) { sentence = simplify(sentence); for (int i = 0; i < l(l); i++) if (eq(simplify(l.get(i)), sentence)) ret i; ret -1; } }
Began life as a copy of #1001581
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment