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

53
LINES

< > BotCompany Repo | #1001294 // Leo Bot

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

Libraryless. Click here for Pure Java version (1883L/12K/42K).

!747

m {
  static new MultiMap<S, S> 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<S> results = map.get(s);
    if (results.isEmpty()) return s;
    return new Random().nextFloat() <= mirrorChance ? s : oneOf(results);
  }
  
  static synchronized S answer(S input, L<S> 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<S> tok = dropPunctuation(javaTok(s));
    // TODO
    return s.intern();
  }
}

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

Comments [hide]

ID Author/Program Comment Date
1117 stefan TODO: improve interaction on console 2015-10-07 01:36:09

add comment

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: 778 / 1115
Referenced in: #1001248 - Public Comm Bot with forwarding (LIVE)
#1001581 - Simplest Assoc Bot (pure map, works)
#3000195 - Answer for stefanreich (>> y)
#3000196 - Answer for stefanreich (>> y)
#3000197 - Answer for stefanreich (>> program data sizes)
#3000198 - Answer for stefanreich (>> program data sizes)
#3000199 - Answer for stefanreich (>> program data sizes)
#3000200 - Answer for stefanreich (>> program data sizes)
#3000201 - Answer for stefanreich (>> list all files)
#3000202 - Answer for stefanreich (>> T conversion bot)
#3000238 - Answer for stefanreich (>> t power bot)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)