#!/usr/bin/python3

# Elizalike --- Ling/CSE 472 Assignment I
# Updated by JCrowgey and LPoulson for Spring 2011
# Updated by Olga Zamaraeva for Spring 2018

# Simple automated conversation agent, in the style of
# Weizenbaum's Eliza.  Invoke by typing:

#        python elizalike.py

# from a command prompt or unix shell.

# The basic script provided as part of the assignment takes care
# of input and output, gives one example regular expression, and
# provides a series of comments (preceded by #) indicating what
# you should add.


import re
import sys

def reply(str):
    # Insert a tag at the beginning of the line to identify
    # it as Eliza's reponse, and to make finding word boundaries
    # easier.

    str = 'Elizalike: ' + str

    # Replace all instances of "you are" with "---Eliza-is---":
    # Note how (\W) and \1, etc are used to mark word boundaries
    # and keep whatever non-word character was in the input in the
    # output.

    pat = r'(\W)[Yy]ou are(\W)'
    replace = '\g<1>---Eliza-is---\g<2>'
    str = re.sub(pattern=pat,repl=replace,string=str)

    # A brief note about syntax:  The function re.sub takes three
    # arguments: a regular expression to search for in the string,
    # a replacement string to replace it with, and the string to
    # operate on.  It returns a new string, which the above expression
    # is storing in the variable 'string'.

    # Remaining statements for changing second person reference
    # in the input to third person reference (temporarily):






    # Other transformations on the input that don't have to do with
    # person reference:




    # Statements for changing first person reference to second
    # person reference:






    # Statements for changing third person Eliza reference to
    # first person reference:







    # Print the reply
    return str


def main():
    print ("Welcome to Elizalike.  Talk to me! (Or type \"bye\" to quit.)\n")
    # Start an infinite loop
    while True:

        # Read in the user's input
        str = input("Patient: ")

        # Allow user to quit
        if re.search(r'bye|Bye|BYE',str):

            print ("Elizalike: Well, it was nice talking to you!\n")
            sys.exit()
        rep = reply(str)
        print (rep)




if __name__ == "__main__":
    sys.exit(main())
