Libraryless. Click here for Pure Java version (1883L/12K/42K).
1 | !747 |
2 | |
3 | m { |
4 | static new MultiMap<S, S> map; |
5 | static boolean fancyOpening = true; |
6 | static float mirrorChance = 0.0f; // 0.1f; |
7 | |
8 | !include #1001296 // MultiMap |
9 | |
10 | p { |
11 | readLocally("map"); |
12 | makeAndroid3("Leo Bot at " + getComputerID() + "."); |
13 | } |
14 | |
15 | static S lookup(S s) { |
16 | L<S> results = map.get(s); |
17 | if (results.isEmpty()) return s; |
18 | return new Random().nextFloat() <= mirrorChance ? s : oneOf(results); |
19 | } |
20 | |
21 | static synchronized S answer(S input, L<S> history) { |
22 | if (input.startsWith("!")) { |
23 | history = (L) unstructure(input.substring(1)); |
24 | input = history.get(history.size()-1); |
25 | } |
26 | |
27 | if (history.size() == 1) { // ignore contents of first line actually |
28 | S output = "hallo"; |
29 | if (fancyOpening) |
30 | output = lookup(output); |
31 | return output; |
32 | } else { |
33 | S ninput = normalize(input); |
34 | S lastInput = history.size() >= 3 ? normalize(history.get(history.size()-3)) : null; |
35 | S lastOutput = normalize(history.get(history.size()-2)); |
36 | |
37 | // inner/cross learning algorithm |
38 | |
39 | map.put(lastOutput, ninput); |
40 | if (lastInput != null && !lastInput.equals(lastOutput)) |
41 | map.put(lastInput, ninput); |
42 | |
43 | saveLocally("map"); |
44 | return lookup(input); |
45 | } |
46 | } |
47 | |
48 | static S normalize(S s) { |
49 | //L<S> tok = dropPunctuation(javaTok(s)); |
50 | // TODO |
51 | return s.intern(); |
52 | } |
53 | } |
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
ID | Author/Program | Comment | Date |
---|---|---|---|
1117 | stefan | TODO: improve interaction on console | 2015-10-07 01:36:09 |
Snippet ID: | #1001294 |
Snippet name: | Leo Bot |
Eternal ID of this version: | #1001294/1 |
Text MD5: | 3754fd26461d2856015fac61b128832d |
Transpilation MD5: | 534156241c1fa8ad3c3778a4910e9801 |
Author: | stefan |
Category: | leopold |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-11-13 18:06:20 |
Source code size: | 1434 bytes / 53 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 914 / 1257 |
Referenced in: | [show references] |