-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdog_chat.py
53 lines (43 loc) · 1.2 KB
/
dog_chat.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
# Natural Language Toolkit: Eliza
#
# Copyright (C) 2001-2013 NLTK Project
# Authors: Steven Bird <stevenbird1@gmail.com>
# Edward Loper <edloper@gmail.com>
# URL: <http://nltk.org/>
# For license information, see LICENSE.TXT
# Based on an Eliza implementation by Joe Strout <joe@strout.net>,
# Jeff Epler <jepler@inetnebr.com> and Jez Higgins <mailto:jez@jezuk.co.uk>.
# a translation table used to convert things you say into things the
# computer says back, e.g. "I am" --> "you are"
import nltk
reflections = {
"am" : "are",
"was" : "were"
}
pairs = (
# suggestions
(
r"I'm hungry",
( "I'm hungry too!",
"Let's get dinner!",
"Let's go to the Doggy Diner!")),
(r"Where is(.*)",
( "Those teethmarks on %1 are not mine!",
"I bet you didn't know %1 was edible...")),
# anything else
(r'(.*)',
(
"(Looking soulfully) treat please...",
"Did you say 'Let's go for a walk?'",
"Yes! Yes! Nap time!",
)
)
)
dog_chatbot = nltk.chat.Chat(pairs, reflections)
def dog_chat():
print "Emoting cutely ..."
dog_chatbot.converse()
def demo():
dog_chat()
if __name__ == "__main__":
demo()