!747 m { static new MultiMap map; static boolean fancyOpening = true; static float mirrorChance = 0.0f; // 0.1f; !include #1001296 // MultiMap p { readLocally("map"); makeAndroid3("Leo Bot at " + getComputerID() + "."); } static S lookup(S s) { L results = map.get(s); if (results.isEmpty()) return s; return new Random().nextFloat() <= mirrorChance ? s : oneOf(results); } static synchronized S answer(S input, L history) { if (input.startsWith("!")) { history = (L) unstructure(input.substring(1)); input = history.get(history.size()-1); } if (history.size() == 1) { // ignore contents of first line actually S output = "hallo"; if (fancyOpening) output = lookup(output); return output; } else { S ninput = normalize(input); S lastInput = history.size() >= 3 ? normalize(history.get(history.size()-3)) : null; S lastOutput = normalize(history.get(history.size()-2)); // inner/cross learning algorithm map.put(lastOutput, ninput); if (lastInput != null && !lastInput.equals(lastOutput)) map.put(lastInput, ninput); saveLocally("map"); return lookup(input); } } static S normalize(S s) { //L tok = dropPunctuation(javaTok(s)); // TODO return s.intern(); } }