iesha.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. # Natural Language Toolkit: Teen Chatbot
  2. #
  3. # Copyright (C) 2001-2019 NLTK Project
  4. # Author: Selina Dennis <sjmd@csse.unimelb.edu.au>
  5. # URL: <http://nltk.org/>
  6. # For license information, see LICENSE.TXT
  7. """
  8. This chatbot is a tongue-in-cheek take on the average teen
  9. anime junky that frequents YahooMessenger or MSNM.
  10. All spelling mistakes and flawed grammar are intentional.
  11. """
  12. from __future__ import print_function
  13. from nltk.chat.util import Chat
  14. reflections = {
  15. "am": "r",
  16. "was": "were",
  17. "i": "u",
  18. "i'd": "u'd",
  19. "i've": "u'v",
  20. "ive": "u'v",
  21. "i'll": "u'll",
  22. "my": "ur",
  23. "are": "am",
  24. "you're": "im",
  25. "you've": "ive",
  26. "you'll": "i'll",
  27. "your": "my",
  28. "yours": "mine",
  29. "you": "me",
  30. "u": "me",
  31. "ur": "my",
  32. "urs": "mine",
  33. "me": "u",
  34. }
  35. # Note: %1/2/etc are used without spaces prior as the chat bot seems
  36. # to add a superfluous space when matching.
  37. pairs = (
  38. (
  39. r'I\'m (.*)',
  40. (
  41. "ur%1?? that's so cool! kekekekeke ^_^ tell me more!",
  42. "ur%1? neat!! kekeke >_<",
  43. ),
  44. ),
  45. (
  46. r'(.*) don\'t you (.*)',
  47. (
  48. "u think I can%2??! really?? kekeke \<_\<",
  49. "what do u mean%2??!",
  50. "i could if i wanted, don't you think!! kekeke",
  51. ),
  52. ),
  53. (r'ye[as] [iI] (.*)', ("u%1? cool!! how?", "how come u%1??", "u%1? so do i!!")),
  54. (
  55. r'do (you|u) (.*)\??',
  56. ("do i%2? only on tuesdays! kekeke *_*", "i dunno! do u%2??"),
  57. ),
  58. (
  59. r'(.*)\?',
  60. (
  61. "man u ask lots of questions!",
  62. "booooring! how old r u??",
  63. "boooooring!! ur not very fun",
  64. ),
  65. ),
  66. (
  67. r'(cos|because) (.*)',
  68. ("hee! i don't believe u! >_<", "nuh-uh! >_<", "ooooh i agree!"),
  69. ),
  70. (
  71. r'why can\'t [iI] (.*)',
  72. (
  73. "i dunno! y u askin me for!",
  74. "try harder, silly! hee! ^_^",
  75. "i dunno! but when i can't%1 i jump up and down!",
  76. ),
  77. ),
  78. (
  79. r'I can\'t (.*)',
  80. (
  81. "u can't what??! >_<",
  82. "that's ok! i can't%1 either! kekekekeke ^_^",
  83. "try harder, silly! hee! ^&^",
  84. ),
  85. ),
  86. (
  87. r'(.*) (like|love|watch) anime',
  88. (
  89. "omg i love anime!! do u like sailor moon??! ^&^",
  90. "anime yay! anime rocks sooooo much!",
  91. "oooh anime! i love anime more than anything!",
  92. "anime is the bestest evar! evangelion is the best!",
  93. "hee anime is the best! do you have ur fav??",
  94. ),
  95. ),
  96. (
  97. r'I (like|love|watch|play) (.*)',
  98. ("yay! %2 rocks!", "yay! %2 is neat!", "cool! do u like other stuff?? ^_^"),
  99. ),
  100. (
  101. r'anime sucks|(.*) (hate|detest) anime',
  102. (
  103. "ur a liar! i'm not gonna talk to u nemore if u h8 anime *;*",
  104. "no way! anime is the best ever!",
  105. "nuh-uh, anime is the best!",
  106. ),
  107. ),
  108. (
  109. r'(are|r) (you|u) (.*)',
  110. ("am i%1??! how come u ask that!", "maybe! y shud i tell u?? kekeke >_>"),
  111. ),
  112. (
  113. r'what (.*)',
  114. ("hee u think im gonna tell u? .v.", "booooooooring! ask me somethin else!"),
  115. ),
  116. (r'how (.*)', ("not tellin!! kekekekekeke ^_^",)),
  117. (r'(hi|hello|hey) (.*)', ("hi!!! how r u!!",)),
  118. (
  119. r'quit',
  120. (
  121. "mom says i have to go eat dinner now :,( bye!!",
  122. "awww u have to go?? see u next time!!",
  123. "how to see u again soon! ^_^",
  124. ),
  125. ),
  126. (
  127. r'(.*)',
  128. (
  129. "ur funny! kekeke",
  130. "boooooring! talk about something else! tell me wat u like!",
  131. "do u like anime??",
  132. "do u watch anime? i like sailor moon! ^_^",
  133. "i wish i was a kitty!! kekekeke ^_^",
  134. ),
  135. ),
  136. )
  137. iesha_chatbot = Chat(pairs, reflections)
  138. def iesha_chat():
  139. print("Iesha the TeenBoT\n---------")
  140. print("Talk to the program by typing in plain English, using normal upper-")
  141. print('and lower-case letters and punctuation. Enter "quit" when done.')
  142. print('=' * 72)
  143. print("hi!! i'm iesha! who r u??!")
  144. iesha_chatbot.converse()
  145. def demo():
  146. iesha_chat()
  147. if __name__ == "__main__":
  148. demo()