{"id":627,"date":"2018-11-25T17:52:42","date_gmt":"2018-11-25T17:52:42","guid":{"rendered":"http:\/\/ai.intelligentonlinetools.com\/ml\/?page_id=627"},"modified":"2018-11-26T01:52:52","modified_gmt":"2018-11-26T01:52:52","slug":"python-chatterbot-example-with-added-logic","status":"publish","type":"page","link":"https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/","title":{"rendered":"Python Chatterbot Example with Added Logic"},"content":{"rendered":"<div class=\"klngm69efa5d2ecffe\" ><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<!-- Text analytics techniques 728_90 horizontal top -->\n<ins class=\"adsbygoogle\"\n     style=\"display:inline-block;width:728px;height:90px\"\n     data-ad-client=\"ca-pub-3416618249440971\"\n     data-ad-slot=\"2926649501\"><\/ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/div><style type=\"text\/css\">\r\n.klngm69efa5d2ecffe {\r\nmargin: 5px; padding: 0px;\r\n}\r\n@media screen and (min-width: 1201px) {\r\n.klngm69efa5d2ecffe {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 993px) and (max-width: 1200px) {\r\n.klngm69efa5d2ecffe {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 769px) and (max-width: 992px) {\r\n.klngm69efa5d2ecffe {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 768px) and (max-width: 768px) {\r\n.klngm69efa5d2ecffe {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (max-width: 767px) {\r\n.klngm69efa5d2ecffe {\r\ndisplay: block;\r\n}\r\n}\r\n<\/style>\r\n<p>This is the code for the post <a href=\"http:\/\/ai.intelligentonlinetools.com\/ml\/chatbots-examples-chatterbot\/\" target=\"_blank\">Chatbots Examples with ChatterBot \u2013 How to Add Logic<\/a><\/p>\n<p>The code here is based on the example from previous post but updated with chatterbot.logic.specific_response  logic adapter and few chatterbot training data conversations to classify user response.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom chatterbot import ChatBot\r\n \r\nchatbot = ChatBot(&quot;mybot&quot;,\r\n        logic_adapters=[\r\n        {\r\n            'import_path': 'chatterbot.logic.SpecificResponseAdapter',\r\n            'input_text': 'prev_day_disk',\r\n            'output_text': 'How much did you do toward your goal on previous day?'\r\n        },\r\n        {\r\n            &quot;import_path&quot;: &quot;chatterbot.logic.BestMatch&quot;,\r\n            &quot;statement_comparison_function&quot;: &quot;chatterbot.comparisons.levenshtein_distance&quot;,\r\n            &quot;response_selection_method&quot;: &quot;chatterbot.response_selection.get_first_response&quot;\r\n        },\r\n        {\r\n            'import_path': 'chatterbot.logic.LowConfidenceAdapter',\r\n            'threshold': 0.65,\r\n            'default_response': 'I am sorry, but I do not understand.'\r\n        }\r\n    ],\r\n    trainer='chatterbot.trainers.ListTrainer')\r\n \r\n \r\n########################################\r\n###   TRAINING - run this just one time\r\n########################################\r\n \r\nchatbot.train([\r\n    &quot;I did not do much this week&quot;,\r\n    &quot;Did you run into the problems with programs or just did not have time?&quot;\r\n])\r\n\r\n\r\nchatbot.train([\r\n    &quot;I did a lot of progress&quot;,\r\n    &quot;Fantastic! Keep going on&quot;\r\n]) \r\n\r\n\r\nchatbot.train([\r\n    'Good morning!',\r\n    'Good morning!',\r\n    'How are you today?',\r\n    'I am fine',\r\n    'Do you like machine learning?',\r\n    'Yes, I like machine learning'\r\n])\r\n \r\n \r\nchatbot.train([\r\n    'Good morning!',\r\n    'Good morning!'\r\n  \r\n])\r\n \r\nchatbot.train([\r\n    'Hello',\r\n    'Hi there!'\r\n  \r\n])\r\n \r\n \r\nchatbot.train([\r\n    'Let us talk about current activities',\r\n    'What are you working on now?',\r\n    'I am just browsing Internet for news',\r\n    'What a waste of time! Dont you have any other things to do?',\r\n    'I am working on python script to make new chatbot',\r\n    'This is great. Keep working on this'\r\n])\r\n \r\n \r\nchatbot.train(\r\n    &quot;chatterbot.corpus.english.greetings&quot;\r\n  \r\n)\r\n \r\nchatbot.train(\r\n   &quot;chatterbot.corpus.english.conversations&quot;\r\n)\r\n \r\n \r\n \r\nfrom chatterbot.trainers import ListTrainer\r\n \r\nconversation = [\r\n    &quot;Hello&quot;,\r\n    &quot;Hi there!&quot;,\r\n    &quot;How are you doing?&quot;,\r\n    &quot;I'm doing great.&quot;,\r\n    &quot;That is good to hear&quot;,\r\n    &quot;Thank you.&quot;,\r\n    &quot;You're welcome.&quot;\r\n]\r\n \r\nchatbot.set_trainer(ListTrainer)\r\nchatbot.train(conversation)\r\n \r\n########################################\r\n###  END of  TRAINING\r\n########################################\r\n \r\n \r\n \r\nprint (&quot;USER: How are you doing?&quot;)\r\n \r\nresponse = chatbot.get_response(&quot;How are you doing?&quot;)\r\nprint(&quot;BOT:&quot; + str(response))\r\nprint (&quot;USER: Hello&quot;)\r\n \r\nresponse = chatbot.get_response(&quot;Hello&quot;)\r\nprint(&quot;BOT:&quot; + str(response))\r\nprint (&quot;USER: Good morning!&quot;)\r\n \r\nresponse = chatbot.get_response(&quot;Good morning!&quot;)\r\nprint(&quot;BOT:&quot; + str(response))\r\n \r\n \r\n \r\nprint (&quot;USER: Do you like machine learning?&quot;)\r\n \r\nresponse = chatbot.get_response(&quot;Do you like machine learning?&quot;)\r\nprint (&quot;BOT:&quot; + str(response))\r\nprint (&quot;USER: How do I make a neural network?&quot;)\r\n \r\nresponse = chatbot.get_response('How do I make a neural network?')\r\nprint(&quot;BOT&quot; + str(response))\r\nprint (&quot;USER: Let us talk about current activities&quot;)\r\n \r\nresponse = chatbot.get_response(&quot;Let us talk about current activities&quot;)\r\nprint(&quot;BOT:&quot;+str(response))\r\n \r\nprint (&quot;USER: I am just browsing Internet for news&quot;)\r\n \r\nresponse = chatbot.get_response(&quot;BOT: I am just browsing Internet for news&quot;)\r\nprint(&quot;BOT:&quot; + str(response))\r\n \r\nprint (&quot;USER: I am working on python script to make new chatbot&quot;)\r\n \r\nresponse = chatbot.get_response(&quot;I am working on python script to make new chatbot&quot;)\r\nprint(&quot;BOT:&quot;+str(response))\r\n \r\n \r\nprint (&quot;USER: Bye&quot;)\r\n \r\nresponse = chatbot.get_response(&quot;Bye&quot;)\r\nprint(&quot;BOT:&quot; + str(response))\r\n<\/pre>\n<div class=\"dtfpn69efa5d2ed02c\" ><center>\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<!-- Text analytics techniques link ads horizontal Medium after content -->\n<ins class=\"adsbygoogle\"\n     style=\"display:inline-block;width:468px;height:15px\"\n     data-ad-client=\"ca-pub-3416618249440971\"\n     data-ad-slot=\"5765984772\"><\/ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-3416618249440971\"\n     data-ad-slot=\"3903486841\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n<\/center><\/div><style type=\"text\/css\">\r\n.dtfpn69efa5d2ed02c {\r\nmargin: 5px; padding: 0px;\r\n}\r\n@media screen and (min-width: 1201px) {\r\n.dtfpn69efa5d2ed02c {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 993px) and (max-width: 1200px) {\r\n.dtfpn69efa5d2ed02c {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 769px) and (max-width: 992px) {\r\n.dtfpn69efa5d2ed02c {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 768px) and (max-width: 768px) {\r\n.dtfpn69efa5d2ed02c {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (max-width: 767px) {\r\n.dtfpn69efa5d2ed02c {\r\ndisplay: block;\r\n}\r\n}\r\n<\/style>\r\n","protected":false},"excerpt":{"rendered":"<p>This is the code for the post Chatbots Examples with ChatterBot \u2013 How to Add Logic The code here is based on the example from previous post but updated with chatterbot.logic.specific_response logic adapter and few chatterbot training data conversations to classify user response.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Chatterbot Example with Added Logic - Text Analytics Techniques<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Chatterbot Example with Added Logic - Text Analytics Techniques\" \/>\n<meta property=\"og:description\" content=\"This is the code for the post Chatbots Examples with ChatterBot \u2013 How to Add Logic The code here is based on the example from previous post but updated with chatterbot.logic.specific_response logic adapter and few chatterbot training data conversations to classify user response.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/\" \/>\n<meta property=\"og:site_name\" content=\"Text Analytics Techniques\" \/>\n<meta property=\"article:modified_time\" content=\"2018-11-26T01:52:52+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/\",\"url\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/\",\"name\":\"Python Chatterbot Example with Added Logic - Text Analytics Techniques\",\"isPartOf\":{\"@id\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/#website\"},\"datePublished\":\"2018-11-25T17:52:42+00:00\",\"dateModified\":\"2018-11-26T01:52:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Chatterbot Example with Added Logic\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/#website\",\"url\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/\",\"name\":\"Text Analytics Techniques\",\"description\":\"Text Analytics Techniques\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ai.intelligentonlinetools.com\/ml\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Chatterbot Example with Added Logic - Text Analytics Techniques","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/","og_locale":"en_US","og_type":"article","og_title":"Python Chatterbot Example with Added Logic - Text Analytics Techniques","og_description":"This is the code for the post Chatbots Examples with ChatterBot \u2013 How to Add Logic The code here is based on the example from previous post but updated with chatterbot.logic.specific_response logic adapter and few chatterbot training data conversations to classify user response.","og_url":"https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/","og_site_name":"Text Analytics Techniques","article_modified_time":"2018-11-26T01:52:52+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/","url":"https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/","name":"Python Chatterbot Example with Added Logic - Text Analytics Techniques","isPartOf":{"@id":"https:\/\/ai.intelligentonlinetools.com\/ml\/#website"},"datePublished":"2018-11-25T17:52:42+00:00","dateModified":"2018-11-26T01:52:52+00:00","breadcrumb":{"@id":"https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/ai.intelligentonlinetools.com\/ml\/python-chatterbot-example-with-added-logic\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ai.intelligentonlinetools.com\/ml\/"},{"@type":"ListItem","position":2,"name":"Python Chatterbot Example with Added Logic"}]},{"@type":"WebSite","@id":"https:\/\/ai.intelligentonlinetools.com\/ml\/#website","url":"https:\/\/ai.intelligentonlinetools.com\/ml\/","name":"Text Analytics Techniques","description":"Text Analytics Techniques","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ai.intelligentonlinetools.com\/ml\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/pages\/627"}],"collection":[{"href":"https:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/comments?post=627"}],"version-history":[{"count":8,"href":"https:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/pages\/627\/revisions"}],"predecessor-version":[{"id":659,"href":"https:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/pages\/627\/revisions\/659"}],"wp:attachment":[{"href":"https:\/\/ai.intelligentonlinetools.com\/ml\/wp-json\/wp\/v2\/media?parent=627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}