{ "info": { "author": "Erik Nyquist", "author_email": "eknyquist@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "chatbot_utils\n=============\n\n.. |travis_badge| image:: https://travis-ci.org/eriknyquist/chatbot_utils.svg?branch=master\n :target: https://travis-ci.org/eriknyquist/chatbot_utils\n\n.. |docs_badge| image:: https://readthedocs.org/projects/chatbot-utils/badge/?version=latest\n :target: https://text-game-maker.readthedocs.io\n\n|travis_badge| |docs_badge|\n\n.. contents:: Table of Contents\n\nChatbot utils provides easy-to-use tools for building a chatbot capable of\nreturning flexible, contextual responses when provided with text input.\n\nSupports Python 2.x and 3.x.\n\nBy *Contextual responses*, I mean something like this;\n\n::\n\n human >> hey, what time is it?\n bot >> it's 10.32pm\n human >> is that past my bedtime?\n bot >> no, you're good\n\nThe second phrase typed by the human, ``\"is that past my bedtime?\"``, is\nambiguous, and required the bot to understand that this was an incomplete\nquestion related to the previous question, i.e. the **context**.\n\nInstallation\n------------\n\n>From PyPi\n#########\n\nTODO\n\n>From Github\n###########\n\n#. ``git clone github.com/eriknyquist/chatbot_utils``\n#. ``cd chatbot_utils``\n#. ``python setup.py build``\n#. ``python setup.py install``\n\nExample bot with chatbot_utils\n------------------------------\n\n.. code-block:: python\n\n import random\n import time\n\n from chatbot_utils.responder import Responder, Context\n\n random.seed(time.time())\n\n responder = Responder()\n\n # Add a context for talking about cats\n cat_context = Context()\n cat_context.add_entry_phrases(\n ([\"(.* )?(talk about|tell( me)? about) cats?.*\"], [\"Sure, I love cats\"])\n )\n\n cat_context.add_responses(\n ([\"(.* )?favou?rite thing about (them|cats?).*\"], [\"They are fuzzy\"]),\n ([\"(.* )?(do )?you have (one|(a )?cat).*\"], [\"No, computer programs can't have cats.\"])\n )\n\n # Add a context for talking about cats\n dog_context = Context()\n dog_context.add_entry_phrases(\n ([\"(.* )?(talk about|tell( me)? about) dogs?.*\"], [\"Sure, I think dogs are great\"])\n )\n\n dog_context.add_responses(\n ([\"(.* )?favou?rite thing about (them|dogs?).*\"], [\"They are loyal\"]),\n ([\"(.* )?(do )?you have (one|(a )?dog).*\"], [\"No, computer programs can't have dogs.\"])\n )\n\n responder.add_default_response([\"Oh, really?\", \"Mmhmm.\", \"Indeed.\", \"How fascinating.\"])\n responder.add_responses(\n ([\"(.* )?hello.*\"], [\"How do you do?\", \"Hello!\", \"Oh, hi.\"]),\n ([\"(. *)?(good)?bye.*\"], [\"Alright then, goodbye.\", \"See ya.\", \"Bye.\"])\n )\n\n responder.add_contexts(cat_context, dog_context)\n\n while True:\n text = raw_input(\" > \")\n resp, matchgroups = responder.get_response(text)\n print(\"\\n\\\"%s\\\"\\n\" % (random.choice(resp)))\n\nSave this file as ``simple_bot.py`` and run it with ``python simple_bot.py``.\nExample output:\n\n::\n\n #~$ python simple_bot.py\n\n > hello!\n\n \"Hello!\"\n\n > hey, can we talk about dogs for a bit?\n\n \"Sure, I think dogs are great\"\n\n > what's your favourite thing about them?\n\n \"They are loyal\"\n\n > do you have one?\n\n \"No, computer programs can't have dogs.\"\n\n > OK, let's talk about cats now\n\n \"Sure, I love cats\"\n\n > do you have one?\n\n \"No, computer programs can't have cats.\"\n\n > and what's your favourite thing about them?\n\n \"They are fuzzy\"\n\nPerformance characterizations\n-----------------------------\n\nA core component of ``chatbot_utils`` is a custom dictionary called a ReDict,\nwhich expects values to be set with regular expressions as keys. Values can then\nbe retrieved from the dict by providing input text as the key, and any values\nwith a matching associated regular expression will be returned.\n\nReDicts with a large number of regular expressions (for example, a Responder\nwith several thousand pattern/response pairs added using the ``add_response``\nmethod) may take a significant amount of time when compiling the regular\nexpression(s) initially. By default, this is done automatically on first\nattempt to access a ReDict, but you can also call ``Responder.compile()``\nexplicitly to control when the regular expressions associated with a responder\nare compiled.\n\nOne additional quirk to note is that having more parenthesis groups in your\nregular expressions results in a significant increase in compile time for\nReDicts with a large number of items.\n\nAnalysis: compile time & fetch time with 100k items, no parenthesis groups\n##########################################################################\n\nEach regular expression in the 100k items of test data used for this analysis\nwas 14-19 characters in length, used several common special characters\nand was of the following form:\n\n::\n\n foo? 10|bar* 10\n\nThe *Time to compile* was calculated simply by timing the ``ReDict.compile()``\nmethod. The *Time to fetch* is an average calculated by randomly fetching 10% of\nthe total number of items in the dict (e.g. for a dict with 1000 pattern/value\npairs added, 100 randomly-selected items would be fetched).\n\n.. image:: images/100000_items_no_extra_groups.png\n\nAnalysis: compile time & fetch time with 100k items, extra parenthesis groups\n#############################################################################\n\nEach regular expression in the 100k items of test data used for this analysis\nwas at least 25-30 characters in length, used several common special characters\nand was of the following form (note the addition parenthesis groups):\n\n::\n\n (f)(o)o? 10|b((a)(r)*) 10\n\nSame as the previous test, the *Time to compile* was calculated by timing the\n``ReDict.compile()`` method, and the *Time to fetch* is an average calculated by\nrandomly fetching 10% of the total number of items in the dict.\n\n.. image:: images/100000_items_extra_groups.png\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/eriknyquist/chatbot_utils", "keywords": "", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "chatbot-utils", "package_url": "https://pypi.org/project/chatbot-utils/", "platform": "", "project_url": "https://pypi.org/project/chatbot-utils/", "project_urls": { "Homepage": "http://github.com/eriknyquist/chatbot_utils" }, "release_url": "https://pypi.org/project/chatbot-utils/1.0.1/", "requires_dist": null, "requires_python": "", "summary": "Tools for creating chatbots", "version": "1.0.1" }, "last_serial": 5109064, "releases": { "1.0.1": [ { "comment_text": "", "digests": { "md5": "fe537534c6dba1e62bcae6de0865423b", "sha256": "7c9aef6e9e700d1a8e9acbdbdd134b28d4e3e0c4c6d8af77a2bf21b8415aac09" }, "downloads": -1, "filename": "chatbot_utils-1.0.1-py2-none-any.whl", "has_sig": false, "md5_digest": "fe537534c6dba1e62bcae6de0865423b", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 16340, "upload_time": "2019-04-07T05:28:16", "url": "https://files.pythonhosted.org/packages/b9/3f/3f1952c5dcae192348835a9249852c07d210f4c1b6b4ff57bb574dc4a4d0/chatbot_utils-1.0.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "bf816bd7a82ee64fd598bdfb0a45102b", "sha256": "bab37f11411c8a7fd517420072bf22eb3ff51d57d8870b3950f1032869edc6d6" }, "downloads": -1, "filename": "chatbot_utils-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "bf816bd7a82ee64fd598bdfb0a45102b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 16341, "upload_time": "2019-04-07T05:28:18", "url": "https://files.pythonhosted.org/packages/6e/c4/273f3582f2659e7a687d319a803f000a6be0150567bac77cc03b20a4ed5d/chatbot_utils-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8b881af9ff0c8d3cb5c8697aa4fe7114", "sha256": "f0ecc9b8414ed93dcc48a69e4aa3855e3342b9924f5cdb55678ae46a9362ab3c" }, "downloads": -1, "filename": "chatbot_utils-1.0.1.tar.gz", "has_sig": false, "md5_digest": "8b881af9ff0c8d3cb5c8697aa4fe7114", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11972, "upload_time": "2019-04-07T05:28:19", "url": "https://files.pythonhosted.org/packages/15/38/8cf7d11f06575bd579af21d1b865da0bd2b7824b7a4bfc304a75e5bcd47b/chatbot_utils-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "fe537534c6dba1e62bcae6de0865423b", "sha256": "7c9aef6e9e700d1a8e9acbdbdd134b28d4e3e0c4c6d8af77a2bf21b8415aac09" }, "downloads": -1, "filename": "chatbot_utils-1.0.1-py2-none-any.whl", "has_sig": false, "md5_digest": "fe537534c6dba1e62bcae6de0865423b", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 16340, "upload_time": "2019-04-07T05:28:16", "url": "https://files.pythonhosted.org/packages/b9/3f/3f1952c5dcae192348835a9249852c07d210f4c1b6b4ff57bb574dc4a4d0/chatbot_utils-1.0.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "bf816bd7a82ee64fd598bdfb0a45102b", "sha256": "bab37f11411c8a7fd517420072bf22eb3ff51d57d8870b3950f1032869edc6d6" }, "downloads": -1, "filename": "chatbot_utils-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "bf816bd7a82ee64fd598bdfb0a45102b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 16341, "upload_time": "2019-04-07T05:28:18", "url": "https://files.pythonhosted.org/packages/6e/c4/273f3582f2659e7a687d319a803f000a6be0150567bac77cc03b20a4ed5d/chatbot_utils-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8b881af9ff0c8d3cb5c8697aa4fe7114", "sha256": "f0ecc9b8414ed93dcc48a69e4aa3855e3342b9924f5cdb55678ae46a9362ab3c" }, "downloads": -1, "filename": "chatbot_utils-1.0.1.tar.gz", "has_sig": false, "md5_digest": "8b881af9ff0c8d3cb5c8697aa4fe7114", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11972, "upload_time": "2019-04-07T05:28:19", "url": "https://files.pythonhosted.org/packages/15/38/8cf7d11f06575bd579af21d1b865da0bd2b7824b7a4bfc304a75e5bcd47b/chatbot_utils-1.0.1.tar.gz" } ] }