"""Type lines as the player and see the discourse acts Jev produces. python -m sidecar.repl python -m sidecar.repl "Trip, you are so controlling" Talks to Jev directly, so the server does not need to be running. """ import sys from .classify import Utterance, classify from .config import load_settings from .jev_client import JevClient, JevError def show(text, client, settings): try: result = classify(Utterance(text=text), client, settings) except JevError as error: print(" error: %s" % error) return for act in result.acts: params = ", ".join(p for p in act.param_names if p) print(" %-24s id=%-3d char=%-2d params=(%d, %d, %d) %s p %.2f" % ( act.name, act.da_id, act.char_id, act.param1, act.param2, act.param3, "[" + params + "]" if params else "", act.probability)) top = result.answers["act"] ranked = sorted(top.probabilities.items(), key=lambda kv: -kv[1])[:3] print(" act distribution: " + " ".join("%s %.2f" % kv for kv in ranked)) def main(): settings = load_settings() client = JevClient.from_settings(settings) if len(sys.argv) > 1: return show(" ".join(sys.argv[1:]), client, settings) print("Say something to Trip and Grace. Blank line or Ctrl+C quits.") while True: try: text = input("> ").strip() except (EOFError, KeyboardInterrupt): return if not text: return show(text, client, settings) if __name__ == "__main__": main()