rude.py 3.1 KB

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