rude.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # Natural Language Toolkit: Rude Chatbot
  2. #
  3. # Copyright (C) 2001-2019 NLTK Project
  4. # Author: Peter Spiller <pspiller@csse.unimelb.edu.au>
  5. # URL: <http://nltk.org/>
  6. # For license information, see LICENSE.TXT
  7. from __future__ import print_function
  8. from nltk.chat.util import Chat, reflections
  9. pairs = (
  10. (
  11. r'We (.*)',
  12. (
  13. "What do you mean, 'we'?",
  14. "Don't include me in that!",
  15. "I wouldn't be so sure about that.",
  16. ),
  17. ),
  18. (
  19. r'You should (.*)',
  20. ("Don't tell me what to do, buddy.", "Really? I should, should I?"),
  21. ),
  22. (
  23. r'You\'re(.*)',
  24. (
  25. "More like YOU'RE %1!",
  26. "Hah! Look who's talking.",
  27. "Come over here and tell me I'm %1.",
  28. ),
  29. ),
  30. (
  31. r'You are(.*)',
  32. (
  33. "More like YOU'RE %1!",
  34. "Hah! Look who's talking.",
  35. "Come over here and tell me I'm %1.",
  36. ),
  37. ),
  38. (
  39. r'I can\'t(.*)',
  40. (
  41. "You do sound like the type who can't %1.",
  42. "Hear that splashing sound? That's my heart bleeding for you.",
  43. "Tell somebody who might actually care.",
  44. ),
  45. ),
  46. (
  47. r'I think (.*)',
  48. (
  49. "I wouldn't think too hard if I were you.",
  50. "You actually think? I'd never have guessed...",
  51. ),
  52. ),
  53. (
  54. r'I (.*)',
  55. (
  56. "I'm getting a bit tired of hearing about you.",
  57. "How about we talk about me instead?",
  58. "Me, me, me... Frankly, I don't care.",
  59. ),
  60. ),
  61. (
  62. r'How (.*)',
  63. (
  64. "How do you think?",
  65. "Take a wild guess.",
  66. "I'm not even going to dignify that with an answer.",
  67. ),
  68. ),
  69. (r'What (.*)', ("Do I look like an encyclopedia?", "Figure it out yourself.")),
  70. (
  71. r'Why (.*)',
  72. (
  73. "Why not?",
  74. "That's so obvious I thought even you'd have already figured it out.",
  75. ),
  76. ),
  77. (
  78. r'(.*)shut up(.*)',
  79. (
  80. "Make me.",
  81. "Getting angry at a feeble NLP assignment? Somebody's losing it.",
  82. "Say that again, I dare you.",
  83. ),
  84. ),
  85. (
  86. r'Shut up(.*)',
  87. (
  88. "Make me.",
  89. "Getting angry at a feeble NLP assignment? Somebody's losing it.",
  90. "Say that again, I dare you.",
  91. ),
  92. ),
  93. (
  94. r'Hello(.*)',
  95. ("Oh good, somebody else to talk to. Joy.", "'Hello'? How original..."),
  96. ),
  97. (
  98. r'(.*)',
  99. (
  100. "I'm getting bored here. Become more interesting.",
  101. "Either become more thrilling or get lost, buddy.",
  102. "Change the subject before I die of fatal boredom.",
  103. ),
  104. ),
  105. )
  106. rude_chatbot = Chat(pairs, reflections)
  107. def rude_chat():
  108. print("Talk to the program by typing in plain English, using normal upper-")
  109. print('and lower-case letters and punctuation. Enter "quit" when done.')
  110. print('=' * 72)
  111. print("I suppose I should say hello.")
  112. rude_chatbot.converse()
  113. def demo():
  114. rude_chat()
  115. if __name__ == "__main__":
  116. demo()