当前位置:   article > 正文

聊天机器人Eliza 代码_eliza源码

eliza源码

Eliza是基于正则表达式替换的聊天软件,实现非常简单,以下是其Python代码:

  1. from util import reflections
  2. pairs = (
  3. (r'I need (.*)',
  4. ( "Why do you need %1?",
  5. "Would it really help you to get %1?",
  6. "Are you sure you need %1?")),
  7. (r'Why don\'t you (.*)',
  8. ( "Do you really think I don't %1?",
  9. "Perhaps eventually I will %1.",
  10. "Do you really want me to %1?")),
  11. (r'Why can\'t I (.*)',
  12. ( "Do you think you should be able to %1?",
  13. "If you could %1, what would you do?",
  14. "I don't know -- why can't you %1?",
  15. "Have you really tried?")),
  16. (r'I can\'t (.*)',
  17. ( "How do you know you can't %1?",
  18. "Perhaps you could %1 if you tried.",
  19. "What would it take for you to %1?")),
  20. (r'I am (.*)',
  21. ( "Did you come to me because you are %1?",
  22. "How long have you been %1?",
  23. "How do you feel about being %1?")),
  24. (r'I\'m (.*)',
  25. ( "How does being %1 make you feel?",
  26. "Do you enjoy being %1?",
  27. "Why do you tell me you're %1?",
  28. "Why do you think you're %1?")),
  29. (r'Are you (.*)',
  30. ( "Why does it matter whether I am %1?",
  31. "Would you prefer it if I were not %1?",
  32. "Perhaps you believe I am %1.",
  33. "I may be %1 -- what do you think?")),
  34. (r'What (.*)',
  35. ( "Why do you ask?",
  36. "How would an answer to that help you?",
  37. "What do you think?")),
  38. (r'How (.*)',
  39. ( "How do you suppose?",
  40. "Perhaps you can answer your own question.",
  41. "What is it you're really asking?")),
  42. (r'Because (.*)',
  43. ( "Is that the real reason?",
  44. "What other reasons come to mind?",
  45. "Does that reason apply to anything else?",
  46. "If %1, what else must be true?")),
  47. (r'(.*) sorry (.*)',
  48. ( "There are many times when no apology is needed.",
  49. "What feelings do you have when you apologize?")),
  50. (r'Hello(.*)',
  51. ( "Hello... I'm glad you could drop by today.",
  52. "Hi there... how are you today?",
  53. "Hello, how are you feeling today?")),
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/592620
推荐阅读
相关标签
  

闽ICP备14008679号