zoukankan      html  css  js  c++  java
  • NLP(十五) 聊天机器人

    原文链接:http://www.one2know.cn/nlp15/

    • 对话引擎
      1.了解目标用户
      2.理解用于沟通得语言
      3.了解用户的意图
      4.应答用户,并给出进一步线索
    • NLTK中的引擎
      eliza,iesha,rude,suntsu,zen
    import nltk
    
    def builtinEngines(whichOne): # 测试自带的聊天机器人
        if whichOne == 'eliza':
            nltk.chat.eliza.demo()
        elif whichOne == 'iesha':
            nltk.chat.iesha.demo()
        elif whichOne == 'rude':
            nltk.chat.rude.demo()
        elif whichOne == 'suntsu':
            nltk.chat.suntsu.demo()
        elif whichOne == 'zen':
            nltk.chat.zen.demo()
        else:
            print('unknown built-in chat engine {}'.format(whichOne))
    
    def myEngine(): # 自己的简单对话机器人
        chatpairs = (
            (r"(.*?)Stock price(.*)",
             ("Today stock price is 100",
              "I am unable to find out the stock price.")),
            (r"(.*?)not well(.*)",
             ("Oh, take care. May be you should cisit a doctor",
              "Did you take some medicine ?")),
            (r"(.*?)raining(.*)",
             ("It's monsoon season, what more do you expect ?",
              "Yes, it's good for farmers")),
            (r"How(.*?)health(.*)",
             ("I am always healthy.",
              "I am a program, super healthy!")),
            (r".*",
             ("I am good. How are you today ?",
              "What brings you here ?"))
        )
        def chat():
            print('!'*60)
            print(' >> my Engine << ')
            print('Talk to the program using normal english')
            print('='*60)
            print("Enter 'quit' when done")
            chatbot = nltk.chat.util.Chat(chatpairs,nltk.chat.util.reflections)
            chatbot.converse()
        chat()
    
    if __name__ == "__main__":
        myEngine()
        for engine in ['eliza','iesha','rude','suntsu','zen']:
            print("=== demo of {} ===".format(engine))
            builtinEngines(engine)
            print()
    
  • 相关阅读:
    死锁篇
    java线程池
    sql server 多行数据指定字符串拼接
    动态提交 表格
    ABP
    DDD学习
    sql 语句插入数据返回id
    Post方式提交,通过上下文HttpContext,Request[""]获取
    JQ的过滤隐藏
    sql 查询有多少行
  • 原文地址:https://www.cnblogs.com/peng8098/p/nlp_15.html
Copyright © 2011-2022 走看看