예제 #1
0
def Dialogue(therapist, patient, Uresponse, last_Uresponse, count):
    while count < 25:
        response = ProcessInput(therapist, patient, Uresponse, last_Uresponse)
        if response == Therapist.Farewell(therapist):
            break
        else:
            last_Uresponse = Uresponse
            response = "\n%s\n" % (Stylize(therapist, patient, response))
            Uresponse = raw_input(response)
            return Dialogue(therapist, patient, Uresponse, last_Uresponse,
                            count)

    print Therapist.Farewell(therapist)
예제 #2
0
def ProcessInput(therapist, patient, Uresponse, last_Uresponse):

    # check for trigger words
    if DangerZone(Uresponse) == True:
        response = Therapist.Farewell(therapist)
    else:
        # check that user not trying to leave
        gbye = re.compile(r'(([Gg]ood)?[Bb]ye)')
        if re.search(gbye, Uresponse):
            response = Therapist.Farewell(therapist)
        else:

            # check for repetition
            if last_Uresponse == Uresponse:
                response = random.choice(original_responses["repeat"])

            else:
                # check for yelling
                if Uresponse == Uresponse.upper():
                    response = Therapist.Hostile(therapist)

                else:
                    # check for profanity
                    if re.match(HostilePattern, Uresponse):
                        response = Therapist.Hostile(therapist)
                    else:
                        # first level catches most things
                        if RegExProcesses(Uresponse) != False:
                            frame, fill = RegExProcesses(Uresponse)
                            fill = Pronounify(fill)
                            frame = random.choice(original_responses[frame])
                            if fill == "":
                                response = frame
                            else:
                                response = frame % fill
                        else:
                            # checks to be sure user is talking about self
                            if NotMe(Uresponse) != False:
                                response = NotMe(Uresponse)
                            else:
                                # look for comparisons
                                if IsLike(Uresponse) != False:
                                    response = IsLike(Uresponse)
                                else:
                                    # last resort responses
                                    response = Generics(Uresponse)

    return response
예제 #3
0
def ProcessInput(therapist, patient, Uresponse, last_Uresponse):

    # separate user inputs that require processing from those that don't
    if InputBattery(Uresponse, last_Uresponse) == False:

        # look for stock phrases I've decided are likely.
        if BuiltIns(Uresponse) == False:

            # look for feelings-words
            if DetectFeels(Uresponse) == False:

                #look at nouns
                if DownToNouns(Uresponse, count) == False:

                    # look for events
                    if DetectEvent(Uresponse) == False:

                        #last resort is a generic solicitor for more info
                        response = Generics(patient)
                    else:
                        event = DetectEvent(Uresponse)
                        response = "How is the %s making you feel?" % (event)
                else:
                    response = DownToNouns(Uresponse, count)

            else:
                feel, feelkind = DetectFeels(Uresponse)
                if feelkind == "noun":
                    response = Therapist.noun(therapist, feel)
                elif feelkind == "adj":
                    response = Therapist.adj(therapist, feel)
                elif feelkind == "adv":
                    response = Therapist.adv(therapist, feel)
                elif feelkind == "verb":
                    response = Therapist.verb(therapist, feel)
        else:
            response = BuiltIns(Uresponse)

    # if input fails initial battery, go-to operations apply
    else:
        op = InputBattery(Uresponse, last_Uresponse)
        if op == "Farewell":
            response = Therapist.Farewell(therapist)
        elif op == "Repeater":
            response = Therapist.Repeater(therapist)
        elif op == "getMore":
            response = Therapist.getMore(therapist)
        elif op == "Hostile":
            response = Therapist.Hostile(therapist)
        else:
            response = Therapist.NotMe(therapist)

    return response
예제 #4
0
def Stylize(therapist, patient, response):

    N_type_replacements = {"ing ":"in' "," are not ":" aren't "," do ":"d'","Do ":"D'","because":"'cause","You ":"ya ","you\b":"ya\b", \
    " is ":"'s ", "\bam\b":"'m ","\bwill\b":"'ll"," are ":"'re ", "\bnot\b":"n't\b","\bhave\b":"'ve\b","\bwould":"'d"}

    if Therapist.getStyle(therapist) == "NG":
        response = response
    else:
        for key in N_type_replacements.keys():
            response = re.sub(key, N_type_replacements[key], response)
        punct = response[-1]
        response = response[:-1]
        response[0].upper()
        petname = Therapist.petname(therapist, patient)
        response = "%s, %s%s" % (response, petname, punct)

    return response
예제 #5
0
def Stylize(therapist, patient, response):

	N_type_replacements = {"ing ":"in' "," are not ":" aren't "," do ":"d'","Do ":"D'","because":"'cause","You ":"ya ","you\b":"ya\b", \
	" is ":"'s ", "\bam\b":"'m ","\bwill\b":"'ll"," are ":"'re ", "\bnot\b":"n't\b","\bhave\b":"'ve\b","\bwould":"'d"}

	if Therapist.getStyle(therapist)=="NG":
		response = response
	else:
		for key in N_type_replacements.keys():
			response = re.sub(key, N_type_replacements[key], response)
		punct = response[-1]
		response = response[:-1]
		response[0].upper()
		petname = Therapist.petname(therapist, patient)
		response = "%s, %s%s"%(response, petname, punct)

	return response
예제 #6
0
def Stylize(therapist, patient, response):

    N_type_replacements = {"ing ":"in' ","You\b":"ya\b","you\b":"ya\b", \
    " is ":"'s ", "\bare\b":"'re\b", "\bhave\b":"'ve\b"}

    if Therapist.getStyle(therapist) == "NG":
        response = response
    else:
        for key in N_type_replacements.keys():
            response = re.sub(key, N_type_replacements[key], response)
        punct = response[-1]
        response = response[:-1]
        response[0].upper()
        petname = Therapist.petname(therapist, patient)
        response = "%s, %s%s" % (response, petname, punct)

    return response
예제 #7
0
def InitializeSession():

	therapist = ChooseTherapist()

	patient = getPtName()	

	first_Uresponse = raw_input("\n%s\n\n"%(Therapist.introduce(therapist,patient)))

	return therapist, patient, first_Uresponse
예제 #8
0
def InitializeSession():

    therapist = ChooseTherapist()

    patient = getPtName()

    first_Uresponse = raw_input("\n%s\n\n" %
                                (Therapist.introduce(therapist, patient)))

    return therapist, patient, first_Uresponse
예제 #9
0
def ChooseTherapist():
	print "\nHello! Welcome to the ElIZA Partners! We have several partners available to talk to.\n"
		
	for item in therapist_directory:
		print "%s\t(%s)"%(item, Therapist.getKind(therapist_directory[item]))

	therapist_choice = raw_input("\nWho would you like as your therapist today?\n\n")

	if therapist_choice in therapist_directory.keys():

		therapist = therapist_directory[therapist_choice]

		print "\nAll set to talk to %s.\n"%(Therapist.getName(therapist))

		return therapist

	else:
		print "\nI'm afraid that wasn't one of the options. \
		\nPlease choose again, and be sure to type the full name!\n"
		return ChooseTherapist()
예제 #10
0
def ChooseTherapist():

	for item in therapist_directory:
		print "Hello! Welcome to the ElIZA Partners! We have several partners available to talk to."
		print "%s\t%s"%(item, Therapist.getKind(therapist_directory[item]))

	therapist_choice = raw_input("\nWho would you like as your therapist today?\n")

	if therapist_choice in therapist_directory.keys():

		therapist = therapist_directory[therapist_choice]

		print "\nAll set to talk to %s.\n"%(Therapist.getName(therapist))

		return therapist

	else:
		print "\nI'm afraid that wasn't one of the options. \
		\nPlease choose again, and be sure to type the full name!\n"
		return ChooseTherapist()
예제 #11
0
def Stylize(therapist, answer):

	tokenized_answer = nltk.word_tokenize(answer)
	answer_tagged = nltk.pos_tag(answer)

	if Therapist.getStyle(therapist)=="NG":

		answer = answer

	else:

		answer = re.sub("ing\W", "in' ", answer)

	return answer
예제 #12
0
	return answer

def DetectFeels(user_input):

	feel_think = re.compile(r'(.*?((feel|think)(ing)?)(.*)\.)')

	if re.match(feel_think, user_input):
		answer = "What makes you %s that way?"%(feel_think.group(1))


therapist = ChooseTherapist()

name = NameCheck(raw_input("\nAnd what's your name?\n\n"))

patient = pt(name)

print Therapist.introduce(therapist,name)

opener = Stylize(therapist, "\nWhat would you say is the single biggest challenge you're facing right now?")

user_init = raw_input(opener+"\n\n")