-
Notifications
You must be signed in to change notification settings - Fork 0
/
quinn.py
57 lines (43 loc) · 1.43 KB
/
quinn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import random
def converse():
while(True):
this = raw_input("YOU: ")
print ""
print "QUINN: " + conversationTree(this)
print ""
def conversationTree(input):
g = open("greetings.txt","r")
eq = open("emotional_questions.txt","r")
er = open("emotional_response.txt", "r")
ynq = open("yes_no_questions.txt","r")
ynr = open("yesno_response.txt","r")
c = open("certainty.txt","r")
greetings = g.readlines()
emotionalq = eq.readlines()
emotionalr = er.readlines()
yesNoq = ynq.readlines()
yesNor = ynr.readlines()
certainty = c.readlines()
#stereotypically, a conversation will start with some kind of greeting
for line in greetings:
if input in line:
response = random.choice(greetings).strip("\n\r")
return response
#Questions are either emotional, factual, or true/false (yes or no)
if "?" in input:
input = input.strip("?")
#if it's an emotional question, respond with an emotion
for line in emotionalq:
line = line.strip("\n\r")
if line in input:
response = "I'm "+random.choice(certainty).strip("\n\r")+" "+random.choice(emotionalr).strip("\n\r")
return response
#if it's a yes or no, respond with yes or no
for line in yesNoq:
line = line.strip("\n\r")
if line in input:
response = random.choice(yesNor).strip("\n\r")
return response
return "Punctuation matters... or you're a terrible conversationalist"
if __name__ == "__main__":
converse()