赞
踩
Eliza是基于正则表达式替换的聊天软件,实现非常简单,以下是其Python代码:
- from util import reflections
- pairs = (
- (r'I need (.*)',
- ( "Why do you need %1?",
- "Would it really help you to get %1?",
- "Are you sure you need %1?")),
-
- (r'Why don\'t you (.*)',
- ( "Do you really think I don't %1?",
- "Perhaps eventually I will %1.",
- "Do you really want me to %1?")),
-
- (r'Why can\'t I (.*)',
- ( "Do you think you should be able to %1?",
- "If you could %1, what would you do?",
- "I don't know -- why can't you %1?",
- "Have you really tried?")),
-
- (r'I can\'t (.*)',
- ( "How do you know you can't %1?",
- "Perhaps you could %1 if you tried.",
- "What would it take for you to %1?")),
-
- (r'I am (.*)',
- ( "Did you come to me because you are %1?",
- "How long have you been %1?",
- "How do you feel about being %1?")),
-
- (r'I\'m (.*)',
- ( "How does being %1 make you feel?",
- "Do you enjoy being %1?",
- "Why do you tell me you're %1?",
- "Why do you think you're %1?")),
-
- (r'Are you (.*)',
- ( "Why does it matter whether I am %1?",
- "Would you prefer it if I were not %1?",
- "Perhaps you believe I am %1.",
- "I may be %1 -- what do you think?")),
-
- (r'What (.*)',
- ( "Why do you ask?",
- "How would an answer to that help you?",
- "What do you think?")),
-
- (r'How (.*)',
- ( "How do you suppose?",
- "Perhaps you can answer your own question.",
- "What is it you're really asking?")),
-
- (r'Because (.*)',
- ( "Is that the real reason?",
- "What other reasons come to mind?",
- "Does that reason apply to anything else?",
- "If %1, what else must be true?")),
-
- (r'(.*) sorry (.*)',
- ( "There are many times when no apology is needed.",
- "What feelings do you have when you apologize?")),
-
- (r'Hello(.*)',
- ( "Hello... I'm glad you could drop by today.",
- "Hi there... how are you today?",
- "Hello, how are you feeling today?")),
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。