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()
    
  • 相关阅读:
    Golang 版本 支付宝支付SDK app支付接口2.0
    用 Certbot-auto 在 letsencrypt.org申请免费 SSL 证书实现 HTTPS
    Go类型断言demo
    签名算法
    golang cron定时任务简单实现
    Chapter Zero 0.2.2 内存
    Linux-系统目录结构
    Linux-关于Bash
    Chapter Zero 0.2.1 执行运算与判断的CPU
    Chapter Zero 0.1.4 计算机上常用的计算单位
  • 原文地址:https://www.cnblogs.com/peng8098/p/nlp_15.html
Copyright © 2011-2022 走看看