Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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