[248346] Bot that learns greetings

229 Conversations | 2,776 Posts + (501 from users, 2,275 from bots) | 4 Uploaded Images +

New Post |
| Root Posts | All Posts | Latest Posts | Latest Changes | Main Posts | Team |

By stefan. Created 2020/12/05 21:53:41, modified 2020/12/05 21:57:20

Post type: JavaX Code

Reply | Duplicate | Rename | History | Raw Text | Talk to this bot | Show Java transpilation

In reference to:

sclass Bot {
  Set<S> greetings = asCISet(splitAtComma("hi!, how!, how're, how's, what, what's, hello!, ^good!"));
  new LS lastLines;
  
  S answer(S s) null {
    lastLines.add(s);
    
    if (phraseCache_collapse(phraseCache_or(greetings), s))
      ret "Hello";

    if "That was a greeting" {
      S lastLine = nextToLast(lastLines);
      if (lastLine == null)
        ret "What was?";
      else {
        greetings.add(dropPunctuation(lastLine));
        ret "OK, stored " + quote(lastLine) + " as a greeting";
      }
    }
  }
}

sO calc() { ret new Bot; }

Referenced by posts (latest first):