├── .nojekyll ├── docs ├── .nojekyll ├── _static │ ├── __init__.py │ ├── file.png │ ├── minus.png │ ├── plus.png │ ├── images │ │ ├── logo_colab.png │ │ ├── logo_binder.svg │ │ └── logo_jupyterhub.svg │ ├── css │ │ ├── fonts │ │ │ ├── lato-bold.woff │ │ │ ├── lato-bold.woff2 │ │ │ ├── lato-normal.woff │ │ │ ├── lato-normal.woff2 │ │ │ ├── Roboto-Slab-Bold.woff │ │ │ ├── lato-bold-italic.woff │ │ │ ├── Roboto-Slab-Bold.woff2 │ │ │ ├── Roboto-Slab-Regular.woff │ │ │ ├── fontawesome-webfont.eot │ │ │ ├── fontawesome-webfont.ttf │ │ │ ├── fontawesome-webfont.woff │ │ │ ├── lato-bold-italic.woff2 │ │ │ ├── lato-normal-italic.woff │ │ │ ├── lato-normal-italic.woff2 │ │ │ ├── Roboto-Slab-Regular.woff2 │ │ │ └── fontawesome-webfont.woff2 │ │ ├── blank.css │ │ ├── badge_only.css │ │ └── theme.css │ ├── vendor │ │ └── fontawesome │ │ │ └── 5.13.0 │ │ │ ├── webfonts │ │ │ ├── fa-solid-900.eot │ │ │ ├── fa-solid-900.ttf │ │ │ ├── fa-brands-400.eot │ │ │ ├── fa-brands-400.ttf │ │ │ ├── fa-brands-400.woff │ │ │ ├── fa-brands-400.woff2 │ │ │ ├── fa-regular-400.eot │ │ │ ├── fa-regular-400.ttf │ │ │ ├── fa-regular-400.woff │ │ │ ├── fa-solid-900.woff │ │ │ ├── fa-solid-900.woff2 │ │ │ └── fa-regular-400.woff2 │ │ │ └── LICENSE.txt │ ├── documentation_options.js │ ├── js │ │ ├── badge_only.js │ │ ├── html5shiv.min.js │ │ ├── html5shiv-printshiv.min.js │ │ └── theme.js │ ├── webpack-macros.html │ ├── sphinx-book-theme.12a9622fbb08dcb3a2a40b2c02b83a57.js │ ├── pygments.css │ ├── doctools.js │ └── language_data.js ├── objects.inv ├── _images │ ├── dialogNumber.png │ ├── TakeOrderBotV1.png │ └── quickStartBotOutput.png ├── _sources │ ├── modules.rst.txt │ ├── simbots.utils.rst.txt │ └── simbots.rst.txt ├── .buildinfo ├── make.bat ├── conf.py ├── search.html ├── py-modindex.html └── modules.html ├── simbots └── simbots │ ├── __init__.py │ ├── utils │ ├── __init__.py │ ├── schemas.py │ ├── exceptions.py │ ├── builtInEntities.py │ └── builtInIntents.py │ ├── Context.py │ ├── Intent.py │ └── Entity.py ├── MANIFEST.in ├── sampleBots ├── faqBotSaves │ └── faqBot_11_12_2021.p ├── QuickStartBot.ipynb ├── BotForSimpleConversation.ipynb ├── ReplyUsingNameBot.ipynb └── TakeOrderBotV1.ipynb ├── setup.py ├── LICENCE.txt ├── README.md └── .gitignore /.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/_static/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /simbots/simbots/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /simbots/simbots/utils/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md 2 | include COPYING 3 | include LICENCE.txt -------------------------------------------------------------------------------- /docs/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/objects.inv -------------------------------------------------------------------------------- /docs/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/file.png -------------------------------------------------------------------------------- /docs/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/minus.png -------------------------------------------------------------------------------- /docs/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/plus.png -------------------------------------------------------------------------------- /docs/_images/dialogNumber.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_images/dialogNumber.png -------------------------------------------------------------------------------- /docs/_images/TakeOrderBotV1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_images/TakeOrderBotV1.png -------------------------------------------------------------------------------- /docs/_sources/modules.rst.txt: -------------------------------------------------------------------------------- 1 | simbots 2 | ======= 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | simbots 8 | -------------------------------------------------------------------------------- /docs/_static/images/logo_colab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/images/logo_colab.png -------------------------------------------------------------------------------- /docs/_images/quickStartBotOutput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_images/quickStartBotOutput.png -------------------------------------------------------------------------------- /docs/_static/css/fonts/lato-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/lato-bold.woff -------------------------------------------------------------------------------- /docs/_static/css/fonts/lato-bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/lato-bold.woff2 -------------------------------------------------------------------------------- /docs/_static/css/fonts/lato-normal.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/lato-normal.woff -------------------------------------------------------------------------------- /docs/_static/css/fonts/lato-normal.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/lato-normal.woff2 -------------------------------------------------------------------------------- /sampleBots/faqBotSaves/faqBot_11_12_2021.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/sampleBots/faqBotSaves/faqBot_11_12_2021.p -------------------------------------------------------------------------------- /docs/_static/css/fonts/Roboto-Slab-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/Roboto-Slab-Bold.woff -------------------------------------------------------------------------------- /docs/_static/css/fonts/lato-bold-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/lato-bold-italic.woff -------------------------------------------------------------------------------- /docs/_static/css/fonts/Roboto-Slab-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/Roboto-Slab-Bold.woff2 -------------------------------------------------------------------------------- /docs/_static/css/fonts/Roboto-Slab-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/Roboto-Slab-Regular.woff -------------------------------------------------------------------------------- /docs/_static/css/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /docs/_static/css/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /docs/_static/css/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /docs/_static/css/fonts/lato-bold-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/lato-bold-italic.woff2 -------------------------------------------------------------------------------- /docs/_static/css/fonts/lato-normal-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/lato-normal-italic.woff -------------------------------------------------------------------------------- /docs/_static/css/fonts/lato-normal-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/lato-normal-italic.woff2 -------------------------------------------------------------------------------- /docs/_static/css/fonts/Roboto-Slab-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/Roboto-Slab-Regular.woff2 -------------------------------------------------------------------------------- /docs/_static/css/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/css/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.eot -------------------------------------------------------------------------------- /docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.ttf -------------------------------------------------------------------------------- /docs/_static/css/blank.css: -------------------------------------------------------------------------------- 1 | /* This file is intentionally left blank to override the stylesheet of the 2 | parent theme via theme.conf. The parent style we import directly in theme.css */ -------------------------------------------------------------------------------- /docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.eot -------------------------------------------------------------------------------- /docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.ttf -------------------------------------------------------------------------------- /docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff -------------------------------------------------------------------------------- /docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2 -------------------------------------------------------------------------------- /docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-regular-400.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-regular-400.eot -------------------------------------------------------------------------------- /docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-regular-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-regular-400.ttf -------------------------------------------------------------------------------- /docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-regular-400.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-regular-400.woff -------------------------------------------------------------------------------- /docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff -------------------------------------------------------------------------------- /docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2 -------------------------------------------------------------------------------- /docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-regular-400.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaibhavrr1/simbots/HEAD/docs/_static/vendor/fontawesome/5.13.0/webfonts/fa-regular-400.woff2 -------------------------------------------------------------------------------- /docs/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: 8b901117df1e46fdad4dee89ee68e449 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /docs/_static/documentation_options.js: -------------------------------------------------------------------------------- 1 | var DOCUMENTATION_OPTIONS = { 2 | URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), 3 | VERSION: '0.0.23', 4 | LANGUAGE: 'None', 5 | COLLAPSE_INDEX: false, 6 | BUILDER: 'html', 7 | FILE_SUFFIX: '.html', 8 | LINK_SUFFIX: '.html', 9 | HAS_SOURCE: true, 10 | SOURCELINK_SUFFIX: '.txt', 11 | NAVIGATION_WITH_KEYS: true 12 | }; -------------------------------------------------------------------------------- /simbots/simbots/utils/schemas.py: -------------------------------------------------------------------------------- 1 | 2 | class Definitions(): 3 | 4 | def __init__(self): 5 | pass 6 | 7 | @staticmethod 8 | def emptyContext(): 9 | return { 10 | "entities": [], 11 | "intents": [], 12 | "dialogs": [], 13 | "messages": [], 14 | "relations": [] 15 | } 16 | 17 | @staticmethod 18 | def emptyRelation(): 19 | return {} -------------------------------------------------------------------------------- /simbots/simbots/utils/exceptions.py: -------------------------------------------------------------------------------- 1 | 2 | class SchemaException(Exception): 3 | """ 4 | Exception raised for errors in schema. 5 | 6 | """ 7 | 8 | def __init__(self, type=None,name=None, message=None): 9 | 10 | self.message = "\n\n Error encountered in {0} : {1} \n Detail : {2}".format(type,name,message) 11 | super().__init__(self.message) 12 | 13 | 14 | class IndexingError(Exception): 15 | """Exception raised for errors in the input. 16 | 17 | Attributes: 18 | expression -- input expression in which the error occurred 19 | message -- explanation of the error 20 | """ 21 | 22 | def __init__(self, message): 23 | 24 | self.message = "\n Index Error Encounterred : \n "+" "+ message 25 | super().__init__(self.message) 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /docs/_sources/simbots.utils.rst.txt: -------------------------------------------------------------------------------- 1 | simbots.utils package 2 | ===================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | simbots.utils.builtInEntities module 8 | ------------------------------------ 9 | 10 | .. automodule:: simbots.utils.builtInEntities 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | simbots.utils.builtInIntents module 16 | ----------------------------------- 17 | 18 | .. automodule:: simbots.utils.builtInIntents 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | simbots.utils.exceptions module 24 | ----------------------------------- 25 | 26 | .. automodule:: simbots.utils.exceptions 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Module contents 32 | --------------- 33 | 34 | .. automodule:: simbots.utils 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | 4 | from pathlib import Path 5 | this_directory = Path(__file__).parent 6 | long_description = (this_directory / "README.md").read_text() 7 | 8 | setup( 9 | name = "simbots", 10 | version = "0.0.23", 11 | description = "Simple bots or Simbots is a library designed to create simple bots .", 12 | packages =["simbots","simbots\\utils"], 13 | package_dir = {'':'simbots'}, 14 | classifiers = ["Development Status :: 1 - Planning","Operating System :: OS Independent","License :: OSI Approved :: MIT License","Programming Language :: Python :: 3"], 15 | install_requires =['sklearn','objectpath'], 16 | license_files = ('LICENSE.txt'), 17 | long_description=long_description, 18 | long_description_content_type='text/markdown', 19 | author = "Vaibhav Arora", 20 | author_email ="vaibhav.rr1@gmail.com" 21 | 22 | 23 | ) -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.https://www.sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/_static/js/badge_only.js: -------------------------------------------------------------------------------- 1 | !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}({4:function(e,t,r){}}); -------------------------------------------------------------------------------- /docs/_sources/simbots.rst.txt: -------------------------------------------------------------------------------- 1 | simbots package 2 | =============== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | simbots.utils 11 | 12 | Submodules 13 | ---------- 14 | 15 | simbots.Bot module 16 | ------------------ 17 | 18 | .. automodule:: simbots.Bot 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | simbots.Context module 24 | ---------------------- 25 | 26 | .. automodule:: simbots.Context 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | simbots.Entity module 32 | --------------------- 33 | 34 | .. automodule:: simbots.Entity 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | simbots.Intent module 40 | --------------------- 41 | 42 | .. automodule:: simbots.Intent 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | Module contents 48 | --------------- 49 | 50 | .. automodule:: simbots 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | -------------------------------------------------------------------------------- /LICENCE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [2021] [Vaibhav Arora] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /docs/_static/webpack-macros.html: -------------------------------------------------------------------------------- 1 | 2 | {% macro head_pre_icons() %} 3 | 5 | 7 | 9 | {% endmacro %} 10 | 11 | {% macro head_pre_fonts() %} 12 | {% endmacro %} 13 | 14 | {% macro head_pre_bootstrap() %} 15 | 16 | 17 | {% endmacro %} 18 | 19 | {% macro head_js_preload() %} 20 | 21 | {% endmacro %} 22 | 23 | {% macro body_post() %} 24 | 25 | {% endmacro %} -------------------------------------------------------------------------------- /docs/_static/images/logo_binder.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 10 | logo 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Simple bots or Simbots is a library designed to create simple chat bots using python. 2 | 3 | Its Basic functions :- 4 | 5 | 1) Uses Machine learning to create Intents . 6 | 2) Supports multiple ways of creating entities and relations . 7 | 3) Also provides helper functions to query context stack . 8 | 4) Provides a framework to create text based chatbots . 9 | 5) Provides a framework to define test conversation of the bot and test it . 10 | 6) Support saving and loading existing conversation . 11 | 7) Support saving and loading trained Chatbot . 12 | 8) Supports Sub Conversation management and creation . 13 | 14 | if you are unfamiliar with any of these terms check out the [documentation](https://vaibhavrr1.github.io/simbots/index.html) . 15 | 16 | To install simply use 17 | 18 | pip install simbots 19 | 20 | Links 21 | 22 | 1) [Documentation](https://vaibhavrr1.github.io/simbots/index.html) 23 | 2) [pypi](https://pypi.org/project/simbots/) 24 | 3) [github](https://github.com/vaibhavrr1/simbots) 25 | 26 | Check out the [documentation](https://vaibhavrr1.github.io/simbots/index.html) page for chatbot terminology and how to solve some common problems like : 27 | 28 | 29 | 1) How to make simple conversation . 30 | 2) Convert site FAQs (Frequently asked questions) to a chatbot . 31 | 3) Detect and handle person names from chat texts . 32 | 4) Create and Place restaurant orders from chat . 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /docs/_static/vendor/fontawesome/5.13.0/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Font Awesome Free License 2 | ------------------------- 3 | 4 | Font Awesome Free is free, open source, and GPL friendly. You can use it for 5 | commercial projects, open source projects, or really almost whatever you want. 6 | Full Font Awesome Free license: https://fontawesome.com/license/free. 7 | 8 | # Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/) 9 | In the Font Awesome Free download, the CC BY 4.0 license applies to all icons 10 | packaged as SVG and JS file types. 11 | 12 | # Fonts: SIL OFL 1.1 License (https://scripts.sil.org/OFL) 13 | In the Font Awesome Free download, the SIL OFL license applies to all icons 14 | packaged as web and desktop font files. 15 | 16 | # Code: MIT License (https://opensource.org/licenses/MIT) 17 | In the Font Awesome Free download, the MIT license applies to all non-font and 18 | non-icon files. 19 | 20 | # Attribution 21 | Attribution is required by MIT, SIL OFL, and CC BY licenses. Downloaded Font 22 | Awesome Free files already contain embedded comments with sufficient 23 | attribution, so you shouldn't need to do anything additional when using these 24 | files normally. 25 | 26 | We've kept attribution comments terse, so we ask that you do not actively work 27 | to remove them from files, especially code. They're a great way for folks to 28 | learn about Font Awesome. 29 | 30 | # Brand Icons 31 | All brand icons are trademarks of their respective owners. The use of these 32 | trademarks does not indicate endorsement of the trademark holder by Font 33 | Awesome, nor vice versa. **Please do not use brand logos for any purpose except 34 | to represent the company, product, or service to which they refer.** 35 | -------------------------------------------------------------------------------- /docs/_static/images/logo_jupyterhub.svg: -------------------------------------------------------------------------------- 1 | logo_jupyterhubHub 2 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | import os 14 | import sys 15 | sys.path.insert(0, os.path.abspath('..')) 16 | 17 | 18 | # -- Project information ----------------------------------------------------- 19 | 20 | project = 'simbots' 21 | copyright = '2021, Vaibhav Arora' 22 | author = 'Vaibhav Arora' 23 | 24 | # The full version, including alpha/beta/rc tags 25 | release = '0.0.23' 26 | 27 | 28 | # -- General configuration --------------------------------------------------- 29 | 30 | # Add any Sphinx extension module names here, as strings. They can be 31 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 32 | # ones. 33 | extensions = [ 34 | "sphinx.ext.autodoc" 35 | ] 36 | 37 | # Add any paths that contain templates here, relative to this directory. 38 | templates_path = ['_templates'] 39 | 40 | # List of patterns, relative to source directory, that match files and 41 | # directories to ignore when looking for source files. 42 | # This pattern also affects html_static_path and html_extra_path. 43 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 44 | 45 | 46 | # -- Options for HTML output ------------------------------------------------- 47 | 48 | # The theme to use for HTML and HTML Help pages. See the documentation for 49 | # a list of builtin themes. 50 | # 51 | html_theme = 'sphinx_book_theme' 52 | 53 | # Add any paths that contain custom static files (such as style sheets) here, 54 | # relative to this directory. They are copied after the builtin static files, 55 | # so a file named "default.css" will overwrite the builtin "default.css". 56 | html_static_path = ['_static'] -------------------------------------------------------------------------------- /simbots/simbots/utils/builtInEntities.py: -------------------------------------------------------------------------------- 1 | class EntitySamples(): 2 | """ 3 | Contains samples for frequently used entities 4 | 5 | """ 6 | 7 | @staticmethod 8 | def greetingsHelper(): 9 | """ 10 | :return: 11 | 12 | {'wsup': [{'tag': 'case-insensitive','pattern': "\s[w]*[a]*[s]+[u]+[p]+\s",'type': 'regex'}],'hi': [{'tag': 'case-insensitive','pattern': "\s[h]+[i]+\s", 'type': 'regex'}],'hello': [{'tag': 'case-insensitive','pattern': "\s[h]+[e]+[l]+[o]+\s",'type': 'regex'}]} 13 | 14 | """ 15 | return {'wsup': [{'tag': 'case-insensitive', 16 | 'pattern': "\s[w]*[a]*[s]+[u]+[p]+\s", 17 | 'type': 'regex'}], 18 | 'hi': [{'tag': 'case-insensitive', 19 | 'pattern': "\s[h]+[i]+\s", 'type': 'regex'}], 20 | 'hello': [{'tag': 'case-insensitive', 21 | 'pattern': "\s[h]+[e]+[l]+[o]+\s", 22 | 'type': 'regex'}]} 23 | 24 | @staticmethod 25 | def laughterHelper(): 26 | """ 27 | :return: 28 | 29 | {'haha': [{'tag': 'case-insensitive','pattern': "\s(h+(a|e)+)+(h+)?\s",'type': 'regex'}],'happysmily': [{'tag': 'case-insensitive','pattern': "\s\:\)\s", 'type': 'regex'}]} 30 | """ 31 | 32 | return {'haha': [{'tag': 'case-insensitive', 33 | 'pattern': "\s(h+(a|e)+)+(h+)?\s", 34 | 'type': 'regex'}], 35 | 'happysmily': [{'tag': 'case-insensitive', 36 | 'pattern': "\s\:\)\s", 'type': 'regex'}]} 37 | 38 | @staticmethod 39 | def coolHelper(): 40 | """ 41 | :return: 42 | 43 | {'cool': [{'tag': 'case-insensitive','pattern': "\sc+oo+l+\s", 'type': 'regex'}]} 44 | 45 | """ 46 | return {'cool': [{'tag': 'case-insensitive','pattern': "\sc+oo+l+\s", 'type': 'regex'}]} 47 | 48 | @staticmethod 49 | def byeHelper(): 50 | """ 51 | :return: 52 | {'bye': [{'tag': 'case-insensitive','pattern': "\s(goo+d)?b+y+e+\s", 'type': 'regex'}]} 53 | 54 | """ 55 | return {'bye': [{'tag': 'case-insensitive','pattern': "\s(goo+d)?(b+u+)?b+y+e+\s", 'type': 'regex'}]} -------------------------------------------------------------------------------- /docs/_static/sphinx-book-theme.12a9622fbb08dcb3a2a40b2c02b83a57.js: -------------------------------------------------------------------------------- 1 | var initTriggerNavBar=()=>{if($(window).width()<768){$("#navbar-toggler").trigger("click")}} 2 | var scrollToActive=()=>{var navbar=document.getElementById('site-navigation') 3 | var active_pages=navbar.querySelectorAll(".active") 4 | var active_page=active_pages[active_pages.length-1] 5 | if(active_page!==undefined&&active_page.offsetTop>($(window).height()*.5)){navbar.scrollTop=active_page.offsetTop-($(window).height()*.2)}} 6 | var sbRunWhenDOMLoaded=cb=>{if(document.readyState!='loading'){cb()}else if(document.addEventListener){document.addEventListener('DOMContentLoaded',cb)}else{document.attachEvent('onreadystatechange',function(){if(document.readyState=='complete')cb()})}} 7 | function toggleFullScreen(){var navToggler=$("#navbar-toggler");if(!document.fullscreenElement){document.documentElement.requestFullscreen();if(!navToggler.hasClass("collapsed")){navToggler.click();}}else{if(document.exitFullscreen){document.exitFullscreen();if(navToggler.hasClass("collapsed")){navToggler.click();}}}} 8 | var initTooltips=()=>{$(document).ready(function(){$('[data-toggle="tooltip"]').tooltip();});} 9 | var initTocHide=()=>{var scrollTimeout;var throttle=200;var tocHeight=$("#bd-toc-nav").outerHeight(true)+$(".bd-toc").outerHeight(true);var hideTocAfter=tocHeight+200;var checkTocScroll=function(){var margin_content=$(".margin, .tag_margin, .full-width, .full_width, .tag_full-width, .tag_full_width, .sidebar, .tag_sidebar, .popout, .tag_popout");margin_content.each((index,item)=>{var topOffset=$(item).offset().top-$(window).scrollTop();var bottomOffset=topOffset+$(item).outerHeight(true);var topOverlaps=((topOffset>=0)&&(topOffset=0)&&(bottomOffset20){$("div.bd-toc").removeClass("show") 10 | return false}else{$("div.bd-toc").addClass("show")};})};var manageScrolledClassOnBody=function(){if(window.scrollY>0){document.body.classList.add("scrolled");}else{document.body.classList.remove("scrolled");}} 11 | $(window).on('scroll',function(){if(!scrollTimeout){scrollTimeout=setTimeout(function(){checkTocScroll();manageScrolledClassOnBody();scrollTimeout=null;},throttle);}});} 12 | var initThebeSBT=()=>{var title=$("div.section h1")[0] 13 | if(!$(title).next().hasClass("thebe-launch-button")){$("").insertAfter($(title))} 14 | initThebe();} 15 | sbRunWhenDOMLoaded(initTooltips) 16 | sbRunWhenDOMLoaded(initTriggerNavBar) 17 | sbRunWhenDOMLoaded(scrollToActive) 18 | sbRunWhenDOMLoaded(initTocHide) 19 | -------------------------------------------------------------------------------- /docs/_static/js/html5shiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=t.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=t.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),t.elements=c+" "+a,j(b)}function f(a){var b=s[a[q]];return b||(b={},r++,a[q]=r,s[r]=b),b}function g(a,c,d){if(c||(c=b),l)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():p.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||o.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),l)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return t.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(t,b.frag)}function j(a){a||(a=b);var d=f(a);return!t.shivCSS||k||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),l||i(a,d),a}var k,l,m="3.7.3-pre",n=a.html5||{},o=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,p=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q="_html5shiv",r=0,s={};!function(){try{var a=b.createElement("a");a.innerHTML="",k="hidden"in a,l=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){k=!0,l=!0}}();var t={elements:n.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:m,shivCSS:n.shivCSS!==!1,supportsUnknownElements:l,shivMethods:n.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=t,j(b),"object"==typeof module&&module.exports&&(module.exports=t)}("undefined"!=typeof window?window:this,document); -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/python 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=python 4 | 5 | ### Python ### 6 | # Byte-compiled / optimized / DLL files 7 | __pycache__/ 8 | *.py[cod] 9 | *$py.class 10 | 11 | # C extensions 12 | *.so 13 | 14 | # Distribution / packaging 15 | .Python 16 | build/ 17 | develop-eggs/ 18 | dist/ 19 | downloads/ 20 | eggs/ 21 | .eggs/ 22 | lib/ 23 | lib64/ 24 | parts/ 25 | sdist/ 26 | var/ 27 | wheels/ 28 | share/python-wheels/ 29 | *.egg-info/ 30 | .installed.cfg 31 | *.egg 32 | MANIFEST 33 | 34 | # PyInstaller 35 | # Usually these files are written by a python script from a template 36 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 37 | *.manifest 38 | *.spec 39 | 40 | # Installer logs 41 | pip-log.txt 42 | pip-delete-this-directory.txt 43 | 44 | # Unit test / coverage reports 45 | htmlcov/ 46 | .tox/ 47 | .nox/ 48 | .coverage 49 | .coverage.* 50 | .cache 51 | nosetests.xml 52 | coverage.xml 53 | *.cover 54 | *.py,cover 55 | .hypothesis/ 56 | .pytest_cache/ 57 | cover/ 58 | 59 | # Translations 60 | *.mo 61 | *.pot 62 | 63 | # Django stuff: 64 | *.log 65 | local_settings.py 66 | db.sqlite3 67 | db.sqlite3-journal 68 | 69 | # Flask stuff: 70 | instance/ 71 | .webassets-cache 72 | 73 | # Scrapy stuff: 74 | .scrapy 75 | 76 | # Sphinx documentation 77 | docs/_build/ 78 | Makefile 79 | .rst 80 | 81 | # PyBuilder 82 | .pybuilder/ 83 | target/ 84 | 85 | # Jupyter Notebook 86 | .ipynb_checkpoints 87 | 88 | # IPython 89 | profile_default/ 90 | ipython_config.py 91 | 92 | # pyenv 93 | # For a library or package, you might want to ignore these files since the code is 94 | # intended to run in multiple environments; otherwise, check them in: 95 | # .python-version 96 | 97 | # pipenv 98 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 99 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 100 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 101 | # install all needed dependencies. 102 | #Pipfile.lock 103 | 104 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 105 | __pypackages__/ 106 | 107 | # Celery stuff 108 | celerybeat-schedule 109 | celerybeat.pid 110 | 111 | # SageMath parsed files 112 | *.sage.py 113 | 114 | # Environments 115 | .env 116 | .venv 117 | env/ 118 | venv/ 119 | ENV/ 120 | env.bak/ 121 | venv.bak/ 122 | 123 | # Spyder project settings 124 | .spyderproject 125 | .spyproject 126 | 127 | # Rope project settings 128 | .ropeproject 129 | 130 | # mkdocs documentation 131 | /site 132 | 133 | # mypy 134 | .mypy_cache/ 135 | .dmypy.json 136 | dmypy.json 137 | 138 | # Pyre type checker 139 | .pyre/ 140 | 141 | # pytype static type analyzer 142 | .pytype/ 143 | 144 | # Cython debug symbols 145 | cython_debug/ 146 | 147 | # End of https://www.toptal.com/developers/gitignore/api/python -------------------------------------------------------------------------------- /docs/_static/css/badge_only.css: -------------------------------------------------------------------------------- 1 | .fa:before{-webkit-font-smoothing:antialiased}.clearfix{*zoom:1}.clearfix:after,.clearfix:before{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-style:normal;font-weight:400;src:url(fonts/fontawesome-webfont.eot?674f50d287a8c48dc19ba404d20fe713?#iefix) format("embedded-opentype"),url(fonts/fontawesome-webfont.woff2?af7ae505a9eed503f8b8e6982036873e) format("woff2"),url(fonts/fontawesome-webfont.woff?fee66e712a8a08eef5805a46892932ad) format("woff"),url(fonts/fontawesome-webfont.ttf?b06871f281fee6b241d60582ae9369b9) format("truetype"),url(fonts/fontawesome-webfont.svg?912ec66d7572ff821749319396470bde#FontAwesome) format("svg")}.fa:before{font-family:FontAwesome;font-style:normal;font-weight:400;line-height:1}.fa:before,a .fa{text-decoration:inherit}.fa:before,a .fa,li .fa{display:inline-block}li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-.8em}ul.fas li .fa{width:.8em}ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before,.icon-book:before{content:"\f02d"}.fa-caret-down:before,.icon-caret-down:before{content:"\f0d7"}.fa-caret-up:before,.icon-caret-up:before{content:"\f0d8"}.fa-caret-left:before,.icon-caret-left:before{content:"\f0d9"}.fa-caret-right:before,.icon-caret-right:before{content:"\f0da"}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;font-family:Lato,proxima-nova,Helvetica Neue,Arial,sans-serif;z-index:400}.rst-versions a{color:#2980b9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27ae60}.rst-versions .rst-current-version:after{clear:both;content:"";display:block}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book,.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#e74c3c;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#f1c40f;color:#000}.rst-versions.shift-up{height:auto;max-height:100%;overflow-y:scroll}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:grey;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:1px solid #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px;max-height:90%}.rst-versions.rst-badge .fa-book,.rst-versions.rst-badge .icon-book{float:none;line-height:30px}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book,.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge>.rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width:768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}} -------------------------------------------------------------------------------- /docs/_static/js/html5shiv-printshiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3-pre | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=y.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=y.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),y.elements=c+" "+a,j(b)}function f(a){var b=x[a[v]];return b||(b={},w++,a[v]=w,x[w]=b),b}function g(a,c,d){if(c||(c=b),q)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():u.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||t.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),q)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return y.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(y,b.frag)}function j(a){a||(a=b);var d=f(a);return!y.shivCSS||p||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),q||i(a,d),a}function k(a){for(var b,c=a.getElementsByTagName("*"),e=c.length,f=RegExp("^(?:"+d().join("|")+")$","i"),g=[];e--;)b=c[e],f.test(b.nodeName)&&g.push(b.applyElement(l(b)));return g}function l(a){for(var b,c=a.attributes,d=c.length,e=a.ownerDocument.createElement(A+":"+a.nodeName);d--;)b=c[d],b.specified&&e.setAttribute(b.nodeName,b.nodeValue);return e.style.cssText=a.style.cssText,e}function m(a){for(var b,c=a.split("{"),e=c.length,f=RegExp("(^|[\\s,>+~])("+d().join("|")+")(?=[[\\s,>+~#.:]|$)","gi"),g="$1"+A+"\\:$2";e--;)b=c[e]=c[e].split("}"),b[b.length-1]=b[b.length-1].replace(f,g),c[e]=b.join("}");return c.join("{")}function n(a){for(var b=a.length;b--;)a[b].removeNode()}function o(a){function b(){clearTimeout(g._removeSheetTimer),d&&d.removeNode(!0),d=null}var d,e,g=f(a),h=a.namespaces,i=a.parentWindow;return!B||a.printShived?a:("undefined"==typeof h[A]&&h.add(A),i.attachEvent("onbeforeprint",function(){b();for(var f,g,h,i=a.styleSheets,j=[],l=i.length,n=Array(l);l--;)n[l]=i[l];for(;h=n.pop();)if(!h.disabled&&z.test(h.media)){try{f=h.imports,g=f.length}catch(o){g=0}for(l=0;g>l;l++)n.push(f[l]);try{j.push(h.cssText)}catch(o){}}j=m(j.reverse().join("")),e=k(a),d=c(a,j)}),i.attachEvent("onafterprint",function(){n(e),clearTimeout(g._removeSheetTimer),g._removeSheetTimer=setTimeout(b,500)}),a.printShived=!0,a)}var p,q,r="3.7.3",s=a.html5||{},t=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,u=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,v="_html5shiv",w=0,x={};!function(){try{var a=b.createElement("a");a.innerHTML="",p="hidden"in a,q=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){p=!0,q=!0}}();var y={elements:s.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:r,shivCSS:s.shivCSS!==!1,supportsUnknownElements:q,shivMethods:s.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=y,j(b);var z=/^$|\b(?:all|print)\b/,A="html5shiv",B=!q&&function(){var c=b.documentElement;return!("undefined"==typeof b.namespaces||"undefined"==typeof b.parentWindow||"undefined"==typeof c.applyElement||"undefined"==typeof c.removeNode||"undefined"==typeof a.attachEvent)}();y.type+=" print",y.shivPrint=o,o(b),"object"==typeof module&&module.exports&&(module.exports=y)}("undefined"!=typeof window?window:this,document); -------------------------------------------------------------------------------- /docs/_static/js/theme.js: -------------------------------------------------------------------------------- 1 | !function(n){var e={};function t(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return n[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=n,t.c=e,t.d=function(n,e,i){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:i})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var i=Object.create(null);if(t.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)t.d(i,o,function(e){return n[e]}.bind(null,o));return i},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=0)}([function(n,e,t){t(1),n.exports=t(3)},function(n,e,t){(function(){var e="undefined"!=typeof window?window.jQuery:t(2);n.exports.ThemeNav={navBar:null,win:null,winScroll:!1,winResize:!1,linkScroll:!1,winPosition:0,winHeight:null,docHeight:null,isRunning:!1,enable:function(n){var t=this;void 0===n&&(n=!0),t.isRunning||(t.isRunning=!0,e((function(e){t.init(e),t.reset(),t.win.on("hashchange",t.reset),n&&t.win.on("scroll",(function(){t.linkScroll||t.winScroll||(t.winScroll=!0,requestAnimationFrame((function(){t.onScroll()})))})),t.win.on("resize",(function(){t.winResize||(t.winResize=!0,requestAnimationFrame((function(){t.onResize()})))})),t.onResize()})))},enableSticky:function(){this.enable(!0)},init:function(n){n(document);var e=this;this.navBar=n("div.wy-side-scroll:first"),this.win=n(window),n(document).on("click","[data-toggle='wy-nav-top']",(function(){n("[data-toggle='wy-nav-shift']").toggleClass("shift"),n("[data-toggle='rst-versions']").toggleClass("shift")})).on("click",".wy-menu-vertical .current ul li a",(function(){var t=n(this);n("[data-toggle='wy-nav-shift']").removeClass("shift"),n("[data-toggle='rst-versions']").toggleClass("shift"),e.toggleCurrent(t),e.hashChange()})).on("click","[data-toggle='rst-current-version']",(function(){n("[data-toggle='rst-versions']").toggleClass("shift-up")})),n("table.docutils:not(.field-list,.footnote,.citation)").wrap("
"),n("table.docutils.footnote").wrap("
"),n("table.docutils.citation").wrap("
"),n(".wy-menu-vertical ul").not(".simple").siblings("a").each((function(){var t=n(this);expand=n(''),expand.on("click",(function(n){return e.toggleCurrent(t),n.stopPropagation(),!1})),t.prepend(expand)}))},reset:function(){var n=encodeURI(window.location.hash)||"#";try{var e=$(".wy-menu-vertical"),t=e.find('[href="'+n+'"]');if(0===t.length){var i=$('.document [id="'+n.substring(1)+'"]').closest("div.section");0===(t=e.find('[href="#'+i.attr("id")+'"]')).length&&(t=e.find('[href="#"]'))}if(t.length>0){$(".wy-menu-vertical .current").removeClass("current").attr("aria-expanded","false"),t.addClass("current").attr("aria-expanded","true"),t.closest("li.toctree-l1").parent().addClass("current").attr("aria-expanded","true");for(let n=1;n<=10;n++)t.closest("li.toctree-l"+n).addClass("current").attr("aria-expanded","true");t[0].scrollIntoView()}}catch(n){console.log("Error expanding nav for anchor",n)}},onScroll:function(){this.winScroll=!1;var n=this.win.scrollTop(),e=n+this.winHeight,t=this.navBar.scrollTop()+(n-this.winPosition);n<0||e>this.docHeight||(this.navBar.scrollTop(t),this.winPosition=n)},onResize:function(){this.winResize=!1,this.winHeight=this.win.height(),this.docHeight=$(document).height()},hashChange:function(){this.linkScroll=!0,this.win.one("hashchange",(function(){this.linkScroll=!1}))},toggleCurrent:function(n){var e=n.closest("li");e.siblings("li.current").removeClass("current").attr("aria-expanded","false"),e.siblings().find("li.current").removeClass("current").attr("aria-expanded","false");var t=e.find("> ul li");t.length&&(t.removeClass("current").attr("aria-expanded","false"),e.toggleClass("current").attr("aria-expanded",(function(n,e){return"true"==e?"false":"true"})))}},"undefined"!=typeof window&&(window.SphinxRtdTheme={Navigation:n.exports.ThemeNav,StickyNav:n.exports.ThemeNav}),function(){for(var n=0,e=["ms","moz","webkit","o"],t=0;t {1}]".format(key,_filter[key])) 115 | 116 | query="".join(query) 117 | 118 | matchedStuff =list(self.contextTree.execute(query)) 119 | return matchedStuff 120 | 121 | def findCurrentTopIntent(self): 122 | """ 123 | Find the the top intent in the current message 124 | :return: topIntent: the Top intent ie intent with rank 1 125 | """ 126 | # Find current dialog number 127 | currentDialogNumber = self.context["dialogs"][-1] 128 | 129 | # Find 130 | #if confidenceLimit: 131 | topIntent= list(self.findStuff({"dialogNumber": currentDialogNumber, "rank": 1}, stuff="intents")) 132 | 133 | #print "topfound",topIntent 134 | if len(topIntent)>0: 135 | topIntent=topIntent[-1] 136 | else: 137 | topIntent={} 138 | 139 | return topIntent 140 | 141 | def findCurrentEntities(self): 142 | """ 143 | Find the entities detected in the current message 144 | :return: currentEntities : the entities detected in the current message as list 145 | """ 146 | # Find current dialog number 147 | currentDialogNumber = self.context["dialogs"][-1] 148 | 149 | # Find current Entities 150 | currentEntities = list(self.findStuff({"dialogNumber": currentDialogNumber}, stuff="entities")) 151 | 152 | 153 | return currentEntities 154 | 155 | @staticmethod 156 | def findObjectInStuff(stuff,_filter): 157 | """ 158 | Generalised method to search within any given dictionary using objectPath library 159 | :param stuff: the dictionary where the object is to be searched 160 | :param filter: the filter 161 | :return: list of matched objects 162 | """ 163 | 164 | allStuff={ 165 | "allStuff":stuff, 166 | 167 | } 168 | stuffTree=Tree(allStuff) 169 | query=["$.allStuff"] 170 | for key in _filter: 171 | query.append("[@.{0} is {1}]".format(key, _filter[key])) 172 | 173 | query = "".join(query) 174 | return list(stuffTree.execute(query)) 175 | 176 | def updateContextTree(self): 177 | """ 178 | Updates the contextTree with the current context so that everything in the context is searchable, 179 | this becomes useful when saving custom variables in context . 180 | 181 | """ 182 | self.contextTree = Tree(self.context) 183 | 184 | 185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /docs/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Search — simbots 0.0.23 documentation 9 | 10 | 11 | 12 | 13 | 14 | 16 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
57 |
58 | 59 | 102 | 103 | 104 | 105 | 106 | 107 | 108 |
109 | 110 |
111 |
112 | 113 |
114 | 115 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 133 | 134 | 135 | 136 |
137 | 138 | 139 |
140 | 141 |
142 |
143 |
144 |
145 |
146 | 147 |
148 | 149 |

Search

150 | 151 | 159 | 160 | 161 |

162 | Searching for multiple words only shows matches that contain 163 | all words. 164 |

165 | 166 | 167 |
168 | 169 | 170 | 171 |
172 | 173 | 174 | 175 |
176 | 177 |
178 | 179 | 180 |
181 | 182 | 183 | 184 |
185 |
186 | 187 |
188 |
189 |
190 |
191 |

192 | 193 | By Vaibhav Arora
194 | 195 | © Copyright 2021, Vaibhav Arora.
196 |

197 |
198 |
199 |
200 | 201 | 202 |
203 |
204 | 205 | 206 | 207 | 208 | -------------------------------------------------------------------------------- /docs/py-modindex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Python Module Index — simbots 0.0.23 documentation 9 | 10 | 11 | 12 | 13 | 14 | 16 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 |
55 | 56 | 99 | 100 | 101 | 102 | 103 | 104 | 105 |
106 | 107 |
108 |
109 | 110 |
111 | 112 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 130 | 131 | 132 | 133 |
134 | 135 | 136 |
137 | 138 |
139 |
140 |
141 |
142 |
143 | 144 |
145 | 146 | 147 |

Python Module Index

148 | 149 |
150 | s 151 |
152 | 153 | 154 | 155 | 157 | 158 | 160 | 163 | 164 | 165 | 168 | 169 | 170 | 173 | 174 | 175 | 178 | 179 | 180 | 183 | 184 | 185 | 188 | 189 | 190 | 193 | 194 | 195 | 198 | 199 | 200 | 203 |
 
156 | s
161 | simbots 162 |
    166 | simbots.Bot 167 |
    171 | simbots.Context 172 |
    176 | simbots.Entity 177 |
    181 | simbots.Intent 182 |
    186 | simbots.utils 187 |
    191 | simbots.utils.builtInEntities 192 |
    196 | simbots.utils.builtInIntents 197 |
    201 | simbots.utils.exceptions 202 |
204 | 205 | 206 |
207 | 208 | 209 | 210 |
211 |
212 | 213 |
214 |
215 |
216 |
217 |

218 | 219 | By Vaibhav Arora
220 | 221 | © Copyright 2021, Vaibhav Arora.
222 |

223 |
224 |
225 |
226 | 227 | 228 |
229 |
230 | 231 | 232 | 233 | 234 | -------------------------------------------------------------------------------- /docs/modules.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | simbots — simbots 0.0.23 documentation 9 | 10 | 11 | 12 | 13 | 14 | 16 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
51 |
52 | 53 | 96 | 97 | 98 | 99 | 100 | 101 | 102 |
103 | 104 |
105 |
106 | 107 |
108 | 109 | 117 | 118 | 119 | 135 | 136 | 137 | 138 | 139 | 140 | 144 | 145 | 146 | 147 |
148 | 149 | 150 |
151 | 152 |
153 |
154 |
155 |
156 |
157 | 158 |
159 | 160 | 187 | 188 | 189 |
190 | 191 | 192 | 193 |
194 |
195 | 196 |
197 |
198 |
199 |
200 |

201 | 202 | By Vaibhav Arora
203 | 204 | © Copyright 2021, Vaibhav Arora.
205 |

206 |
207 |
208 |
209 | 210 | 211 |
212 |
213 | 214 | 215 | 216 | 217 | -------------------------------------------------------------------------------- /sampleBots/QuickStartBot.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Quick Start Bot\n", 8 | "\n", 9 | "\n", 10 | "lets build a bot to answer two simple questions\n", 11 | "\n", 12 | "1) Who are you ?\n", 13 | "\n", 14 | "2) What is your age ?" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "# Declare Intents here\n", 24 | "\n", 25 | "import json\n", 26 | "\n", 27 | "intentExamples = {\n", 28 | " 'Greetings': [\n", 29 | " 'Hello !',\n", 30 | " 'Hi , How are you ?',\n", 31 | " 'Hey !! ',\n", 32 | " 'Namaste ',\n", 33 | " 'Good day',\n", 34 | " 'Good evening',\n", 35 | " 'Good morning',\n", 36 | " 'Good to see you',\n", 37 | " 'Greetings',\n", 38 | " 'Have you been well?',\n", 39 | " 'Hello Agent',\n", 40 | " 'Hello',\n", 41 | " 'Hello I am looking for some help here',\n", 42 | " 'Hey how are you doing',\n", 43 | " 'Hey there all',\n", 44 | " 'Hey there',\n", 45 | " 'Hey twin',\n", 46 | " 'Hey you',\n", 47 | " 'Hi advisor',\n", 48 | " 'Hi there',\n", 49 | " 'How are things going?',\n", 50 | " 'How are you today?',\n", 51 | " 'How have you been?',\n", 52 | " 'How is it going?',\n", 53 | " 'How r u?',\n", 54 | " 'Looking good eve',\n", 55 | " 'take me back',\n", 56 | " \"What's new?\",\n", 57 | " \"What's up?\",\n", 58 | " 'Who is this?',\n", 59 | " 'You there',\n", 60 | " 'Namaste',\n", 61 | " 'satsriyakaal',\n", 62 | " 'helo',\n", 63 | " 'hiiiiiii',\n", 64 | " 'abe oye',\n", 65 | " ' sup ',\n", 66 | " ' wassup bruh ',\n", 67 | " ' sup bro ',\n", 68 | " ' ssssup mate whats up',\n", 69 | " ],\n", 70 | " 'BotName': [\n", 71 | " 'Who are you',\n", 72 | " 'Who are you ?',\n", 73 | " 'What is your Name ?',\n", 74 | " 'What is your name ',\n", 75 | " 'what should i call you ?',\n", 76 | " 'What should i call you',\n", 77 | " 'How to address you ?',\n", 78 | " 'how to address you by name',\n", 79 | " 'what is your name in english',\n", 80 | " 'call you',\n", 81 | " 'your name',\n", 82 | " 'call you ?',\n", 83 | " 'your name ?',\n", 84 | " 'whom are you',\n", 85 | " 'whom are you referred as',\n", 86 | " ],\n", 87 | "\n", 88 | " 'Irrelevant': ['the weather is fine todaythe sun rises in the east'\n", 89 | " , 'the quick brown fox jumps over the red carpet',\n", 90 | " 'This is random irrelevant text',\n", 91 | " 'What is love , baby dont hurt me ',\n", 92 | " ],\n", 93 | "}" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": 2, 99 | "metadata": {}, 100 | "outputs": [], 101 | "source": [ 102 | "# or equivalently\n", 103 | "\n", 104 | "from simbots.utils.builtInIntents import IntentSamples\n", 105 | "\n", 106 | "intentExamples = {\n", 107 | " 'Greetings': IntentSamples.greetingSamples(),\n", 108 | " 'BotName': IntentSamples.botNameSamples(),\n", 109 | " 'Irrelevant': ['the weather is fine today','the sun rises in the east','the quick brown fox jumps over the red carpet',\n", 110 | " 'the sun rises in the east',\n", 111 | " 'What is love , baby dont hurt me ',\n", 112 | " 'this is a new dawn a new day']\n", 113 | " }" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 3, 119 | "metadata": {}, 120 | "outputs": [], 121 | "source": [ 122 | "# Now Declaring Entites\n", 123 | "\n", 124 | "\n", 125 | "entityExamples = {\n", 126 | " \"GreetingsHelper\": {\n", 127 | " \"wsup\": [\n", 128 | " {\n", 129 | " \"tag\": \"case-insensitive\",\n", 130 | " \"pattern\": \"\\s[w]*[a]*[s] [u] [p] \\s\",\n", 131 | " \"type\": \"regex\",\n", 132 | " }\n", 133 | " ],\n", 134 | " \"hi\": [{\"tag\": \"case-insensitive\", \"pattern\": \"\\s[h] [i] \\s\", \"type\": \"regex\"}],\n", 135 | " \"hello\": [\n", 136 | " {\n", 137 | " \"tag\": \"case-insensitive\",\n", 138 | " \"pattern\": \"\\s[h] [e] [l] [o] \\s\",\n", 139 | " \"type\": \"regex\",\n", 140 | " }\n", 141 | " ],\n", 142 | " }}\n", 143 | "\n" 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": 4, 149 | "metadata": {}, 150 | "outputs": [], 151 | "source": [ 152 | "# Or Equivalently\n", 153 | "\n", 154 | "from simbots.utils.builtInEntities import EntitySamples\n", 155 | "\n", 156 | "entityExamples = {\n", 157 | " 'GreetingsHelper': EntitySamples.greetingsHelper(),\n", 158 | " }" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 5, 164 | "metadata": {}, 165 | "outputs": [], 166 | "source": [ 167 | "# Declaring how the bot should respond" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": 6, 173 | "metadata": {}, 174 | "outputs": [], 175 | "source": [ 176 | "botMessages = {\n", 177 | " \"themeBasic\": {\n", 178 | " \"Greetings\": {\n", 179 | " \"basic\": [\n", 180 | " \"Hello ! What can i do for you ?\",\n", 181 | " \"Hi there ! what can I do for you ?\",\n", 182 | " \"Hello\",\n", 183 | " ]\n", 184 | " },\n", 185 | " \"BotName\": {\"basic\": [\"I am riko\", \"You can call me riko\"]},\n", 186 | " \"Irrelevant\": {\n", 187 | " \"basic\": [\n", 188 | " \"Im sorry Im not getting you :( \",\n", 189 | " \"Im sorry could you please rephrase ?\",\n", 190 | " ]\n", 191 | " },\n", 192 | " },\n", 193 | " \"funky\": {\n", 194 | " \"Greetings\": {\n", 195 | " \"basic\": [\"Hey Yo Wassup Bro What can i do for ya ?\", \"Heyo what ya want ?\"]\n", 196 | " },\n", 197 | " \"BotName\": {\"basic\": [\"Yo Im Riko ! \"]},\n", 198 | " },\n", 199 | " \"cowboy\": {\n", 200 | " \"Greetings\": {\n", 201 | " \"basic\": [\n", 202 | " \"Howdy partner what can i do for you greenhorn\",\n", 203 | " \" Howdy ! Pleasure meeting ya ?\",\n", 204 | " ]\n", 205 | " },\n", 206 | " \"BotName\": {\n", 207 | " \"basic\": [\"Howdy Partner , Im Riko \"]\n", 208 | " },\n", 209 | " },\n", 210 | "}" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": 7, 216 | "metadata": {}, 217 | "outputs": [], 218 | "source": [ 219 | "from simbots.Bot import Bot\n", 220 | "\n", 221 | "newB = Bot(intentExamples, entityExamples, botMessages,\n", 222 | " confidenceLimit=0)" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 8, 228 | "metadata": {}, 229 | "outputs": [ 230 | { 231 | "name": "stdout", 232 | "output_type": "stream", 233 | "text": [ 234 | "Type in @@ to exit bot\n", 235 | "@i to get intents\n", 236 | "@c to get context \n", 237 | "@e to get entities\n", 238 | "@t to add a test case\n", 239 | "@etc to evaluate a test case\n", 240 | "@eatc to evaluate all test cases\n", 241 | "@ti to add intent\n", 242 | "<1> User : Hi\n", 243 | "<1> themeBasicBot : Hi there ! what can I do for you ?\n", 244 | "<2> User : Who are you ?\n", 245 | "<2> themeBasicBot : I am riko\n", 246 | "<3> User : hello \n", 247 | "<3> themeBasicBot : Hi there ! what can I do for you ?\n", 248 | "<4> User : do you know me \n", 249 | "<4> themeBasicBot : You can call me riko\n", 250 | "<5> User : get me a pizza\n", 251 | "<5> themeBasicBot : Im sorry Im not getting you :( \n", 252 | "<6> User : @@\n" 253 | ] 254 | } 255 | ], 256 | "source": [ 257 | "newB.run(theme=\"themeBasic\")" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 9, 263 | "metadata": {}, 264 | "outputs": [ 265 | { 266 | "name": "stdout", 267 | "output_type": "stream", 268 | "text": [ 269 | "I am riko\n" 270 | ] 271 | } 272 | ], 273 | "source": [ 274 | "output = newB.getBotOutput(\"hi who are you ?\",outputTheme =\"themeBasic\")\n", 275 | "print(output)" 276 | ] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": null, 281 | "metadata": {}, 282 | "outputs": [], 283 | "source": [] 284 | } 285 | ], 286 | "metadata": { 287 | "kernelspec": { 288 | "display_name": "condagpu", 289 | "language": "python", 290 | "name": "condagpu" 291 | }, 292 | "language_info": { 293 | "codemirror_mode": { 294 | "name": "ipython", 295 | "version": 3 296 | }, 297 | "file_extension": ".py", 298 | "mimetype": "text/x-python", 299 | "name": "python", 300 | "nbconvert_exporter": "python", 301 | "pygments_lexer": "ipython3", 302 | "version": "3.7.7" 303 | } 304 | }, 305 | "nbformat": 4, 306 | "nbformat_minor": 4 307 | } 308 | -------------------------------------------------------------------------------- /sampleBots/BotForSimpleConversation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Bot For Simple Conversation" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "from simbots.Bot import Bot\n", 17 | "from simbots.utils.builtInIntents import IntentSamples\n", 18 | "from simbots.utils.builtInEntities import EntitySamples\n", 19 | "import json\n", 20 | "\n", 21 | "\n", 22 | "\n", 23 | "intentExamples = {\n", 24 | " 'Greetings': IntentSamples.greetingSamples(),\n", 25 | " 'BotName': IntentSamples.botNameSamples(),\n", 26 | " 'Relatives': IntentSamples.relativeSamples(),\n", 27 | " 'Age': IntentSamples.ageSamples(),\n", 28 | " 'BirthPlace': IntentSamples.birthPlaceSamples(),\n", 29 | " 'Abilities': IntentSamples.abilitiesSamples(),\n", 30 | " 'Really': IntentSamples.reallySamples(),\n", 31 | " 'Laughter': IntentSamples.laughterSamples(),\n", 32 | " 'Cool': IntentSamples.coolSamples(),\n", 33 | " 'Praise': IntentSamples.praiseSamples(),\n", 34 | " 'TrueT': IntentSamples.trueSamples(),\n", 35 | " 'FalseT': IntentSamples.falseSamples(),\n", 36 | " 'Bye': IntentSamples.byeSamples(),\n", 37 | " 'Confirm': IntentSamples.confirmSamples(),\n", 38 | " 'Thanks': IntentSamples.thanksSamples(),\n", 39 | " 'Discard': IntentSamples.discardSamples(),\n", 40 | " 'Joke': IntentSamples.jokeSamples(),\n", 41 | " 'Irrelevant': ['the weather is fine today','the sun rises in the east','the quick brown fox jumps over the red carpet',\n", 42 | " 'the sun rises in the east',\n", 43 | " 'What is love , baby dont hurt me ',\n", 44 | " 'this is a new dawn a new day'],\n", 45 | "}\n", 46 | "\n", 47 | "entityExamples = {\n", 48 | " 'GreetingsHelper': EntitySamples.greetingsHelper(),\n", 49 | " 'LaughterHelper': EntitySamples.laughterHelper(),\n", 50 | " 'CoolHelper': EntitySamples.coolHelper(),\n", 51 | " 'ByeHelper': EntitySamples.byeHelper(),\n", 52 | "}\n", 53 | "someJokes = ['''Sure here is one {0}'''.format(el.replace('...'\n", 54 | " , '''''')) for el in ['What did one pirate say to the other when he beat him at chess? Checkmatey.',\n", 55 | " 'I burned 2000 calories today<>I left my food in the oven for too long.'\n", 56 | " ]]\n", 57 | "\n", 58 | "botMessages = {\n", 59 | " \"themeBasic\":{\n", 60 | " \"Greetings\":{\n", 61 | " \"basic\":[\n", 62 | " \"Hello ! What can i do for you ?\",\n", 63 | " \"Hi there ! what can I do for you ?\",\n", 64 | " \"Hello\"\n", 65 | " ]\n", 66 | " },\n", 67 | " \"Age\":{\n", 68 | " \"basic\":[\n", 69 | " \"I am two years old \",\n", 70 | " \"I am two\"\n", 71 | " ]\n", 72 | " },\n", 73 | " \"BotName\":{\n", 74 | " \"basic\":[\n", 75 | " \"I am riko\",\n", 76 | " \"You can call me riko\"\n", 77 | " ]\n", 78 | " },\n", 79 | " \"Abilities\":{\n", 80 | " \"basic\":[\n", 81 | " \"I am learning to make basic conversation ! \\n ... and i can tell you a couple of jokes :) \"\n", 82 | " ]\n", 83 | " },\n", 84 | " \"BirthPlace\":{\n", 85 | " \"basic\":[\n", 86 | " \"I am from India\",\n", 87 | " \"I am an Indian\",\n", 88 | " \"I am punjabi and i love food\"\n", 89 | " ]\n", 90 | " },\n", 91 | " \"Really\":{\n", 92 | " \"basic\":[\n", 93 | " \"To the best of my knowledge\",\n", 94 | " \"Im positive !\"\n", 95 | " ]\n", 96 | " },\n", 97 | " \"Laughter\":{\n", 98 | " \"basic\":[\n", 99 | " \"Im glad i was able to make you smile !\",\n", 100 | " \"See I can be funny !\",\n", 101 | " \"And they say I dont have a sense of humor :)\"\n", 102 | " ]\n", 103 | " },\n", 104 | " \"Cool\":{\n", 105 | " \"basic\":[\n", 106 | " \"cool\",\n", 107 | " \"thanks\"\n", 108 | " ]\n", 109 | " },\n", 110 | " \"Bye\":{\n", 111 | " \"basic\":[\n", 112 | " \"Bubye !\",\n", 113 | " \"Bye ! nice chatting with you !\"\n", 114 | " ]\n", 115 | " },\n", 116 | " \"Confirm\":{\n", 117 | " \"basic\":[\n", 118 | " \"cool \"\n", 119 | " ]\n", 120 | " },\n", 121 | " \"Discard\":{\n", 122 | " \"basic\":[\n", 123 | " \"No it is then\",\n", 124 | " \"agreed , no it is .\"\n", 125 | " ]\n", 126 | " },\n", 127 | " \"TrueT\":{\n", 128 | " \"basic\":[\n", 129 | " \"I know right\",\n", 130 | " \"that makes me \"\n", 131 | " ]\n", 132 | " },\n", 133 | " \"FalseT\":{\n", 134 | " \"basic\":[\n", 135 | " \"Im still learning ... I sometimes make mistakes \"\n", 136 | " ]\n", 137 | " },\n", 138 | " \"Praise\":{\n", 139 | " \"basic\":[\n", 140 | " \"Thanks ! now i think ill blush \",\n", 141 | " \"So nice of you to say that !\"\n", 142 | " ]\n", 143 | " },\n", 144 | " \"Relatives\":{\n", 145 | " \"basic\":[\n", 146 | " \"Umm no i dont really have any relatives :)\"\n", 147 | " ]\n", 148 | " },\n", 149 | " \"Thanks\":{\n", 150 | " \"basic\":[\n", 151 | " \"Dont mention it \",\n", 152 | " \" Im glad , please dont mention it\"\n", 153 | " ]\n", 154 | " },\n", 155 | " \"Joke\":{\n", 156 | " \"basic\":someJokes\n", 157 | " },\n", 158 | " \"Question\":{\n", 159 | " \"basic\":[\n", 160 | " \"i dont know !\"\n", 161 | " ]\n", 162 | " },\n", 163 | " \"Irrelevant\":{\n", 164 | " \"basic\":[\n", 165 | " \"Im sorry Im not getting you :( \",\n", 166 | " \"Im sorry could you please rephrase ?\"\n", 167 | " ]\n", 168 | " }\n", 169 | " },\n", 170 | " \"funky\":{\n", 171 | " \"Greetings\":{\n", 172 | " \"basic\":[\n", 173 | " \"Hey Yo Wassup Bro What can i do for ya ?\",\n", 174 | " \"Heyo what ya want ?\"\n", 175 | " ]\n", 176 | " },\n", 177 | " \"Abilities\":{\n", 178 | " \"basic\":[\n", 179 | " \"Yo I can get ya somethin to eat \"\n", 180 | " ]\n", 181 | " }\n", 182 | " },\n", 183 | " \"cowboy\":{\n", 184 | " \"Greetings\":{\n", 185 | " \"basic\":[\n", 186 | " \"Howdy partner what can i do for you greenhorn\",\n", 187 | " \" Howdy ! Pleasure meeting ya ?\"\n", 188 | " ]\n", 189 | " },\n", 190 | " \"Abilities\":{\n", 191 | " \"basic\":[\n", 192 | " \"You up for some food ? cause i can help you with that \"\n", 193 | " ]\n", 194 | " }\n", 195 | " }\n", 196 | "}\n" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": 2, 202 | "metadata": {}, 203 | "outputs": [ 204 | { 205 | "name": "stdout", 206 | "output_type": "stream", 207 | "text": [ 208 | "Type in @@ to exit bot\n", 209 | "@i to get intents\n", 210 | "@c to get context \n", 211 | "@e to get entities\n", 212 | "@t to add a test case\n", 213 | "@etc to evaluate a test case\n", 214 | "@eatc to evaluate all test cases\n", 215 | "@ti to add intent\n", 216 | "<1> User : hi\n", 217 | "<1> themeBasicBot : Hello ! What can i do for you ?\n", 218 | "<2> User : who are you?\n", 219 | "<2> themeBasicBot : You can call me riko\n", 220 | "<3> User : hey riko !\n", 221 | "<3> themeBasicBot : Hello ! What can i do for you ?\n", 222 | "<4> User : what can you do ?\n", 223 | "<4> themeBasicBot : I am learning to make basic conversation ! \n", 224 | " ... and i can tell you a couple of jokes :) \n", 225 | "<5> User : sure tell me one\n", 226 | "<5> themeBasicBot : Sure here is one I burned 2000 calories today<>I left my food in the oven for too long.\n", 227 | "<6> User : hahah\n", 228 | "<6> themeBasicBot : And they say I dont have a sense of humor :)\n", 229 | "<7> User : thats amazing !\n", 230 | "<7> themeBasicBot : So nice of you to say that !\n", 231 | "<8> User : do you have a sister perhaps ?\n", 232 | "<8> themeBasicBot : Umm no i dont really have any relatives :)\n", 233 | "<9> User : oh thats too bad\n", 234 | "<9> themeBasicBot : I know right\n", 235 | "<10> User : thanks for talking to me !\n", 236 | "<10> themeBasicBot : So nice of you to say that !\n", 237 | "<11> User : bye then\n", 238 | "<11> themeBasicBot : Bubye !\n", 239 | "<12> User : @@\n" 240 | ] 241 | } 242 | ], 243 | "source": [ 244 | "newB = Bot(intentExamples, entityExamples, botMessages,\n", 245 | " confidenceLimit=0)\n", 246 | "\n", 247 | "outputTheme = 'themeBasic'\n", 248 | "newB.run(theme = outputTheme)" 249 | ] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": null, 254 | "metadata": {}, 255 | "outputs": [], 256 | "source": [] 257 | } 258 | ], 259 | "metadata": { 260 | "kernelspec": { 261 | "display_name": "condagpu", 262 | "language": "python", 263 | "name": "condagpu" 264 | }, 265 | "language_info": { 266 | "codemirror_mode": { 267 | "name": "ipython", 268 | "version": 3 269 | }, 270 | "file_extension": ".py", 271 | "mimetype": "text/x-python", 272 | "name": "python", 273 | "nbconvert_exporter": "python", 274 | "pygments_lexer": "ipython3", 275 | "version": "3.7.7" 276 | } 277 | }, 278 | "nbformat": 4, 279 | "nbformat_minor": 4 280 | } 281 | -------------------------------------------------------------------------------- /docs/_static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Sphinx JavaScript utilities for all documentation. 6 | * 7 | * :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /** 13 | * select a different prefix for underscore 14 | */ 15 | $u = _.noConflict(); 16 | 17 | /** 18 | * make the code below compatible with browsers without 19 | * an installed firebug like debugger 20 | if (!window.console || !console.firebug) { 21 | var names = ["log", "debug", "info", "warn", "error", "assert", "dir", 22 | "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", 23 | "profile", "profileEnd"]; 24 | window.console = {}; 25 | for (var i = 0; i < names.length; ++i) 26 | window.console[names[i]] = function() {}; 27 | } 28 | */ 29 | 30 | /** 31 | * small helper function to urldecode strings 32 | * 33 | * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent#Decoding_query_parameters_from_a_URL 34 | */ 35 | jQuery.urldecode = function(x) { 36 | if (!x) { 37 | return x 38 | } 39 | return decodeURIComponent(x.replace(/\+/g, ' ')); 40 | }; 41 | 42 | /** 43 | * small helper function to urlencode strings 44 | */ 45 | jQuery.urlencode = encodeURIComponent; 46 | 47 | /** 48 | * This function returns the parsed url parameters of the 49 | * current request. Multiple values per key are supported, 50 | * it will always return arrays of strings for the value parts. 51 | */ 52 | jQuery.getQueryParameters = function(s) { 53 | if (typeof s === 'undefined') 54 | s = document.location.search; 55 | var parts = s.substr(s.indexOf('?') + 1).split('&'); 56 | var result = {}; 57 | for (var i = 0; i < parts.length; i++) { 58 | var tmp = parts[i].split('=', 2); 59 | var key = jQuery.urldecode(tmp[0]); 60 | var value = jQuery.urldecode(tmp[1]); 61 | if (key in result) 62 | result[key].push(value); 63 | else 64 | result[key] = [value]; 65 | } 66 | return result; 67 | }; 68 | 69 | /** 70 | * highlight a given string on a jquery object by wrapping it in 71 | * span elements with the given class name. 72 | */ 73 | jQuery.fn.highlightText = function(text, className) { 74 | function highlight(node, addItems) { 75 | if (node.nodeType === 3) { 76 | var val = node.nodeValue; 77 | var pos = val.toLowerCase().indexOf(text); 78 | if (pos >= 0 && 79 | !jQuery(node.parentNode).hasClass(className) && 80 | !jQuery(node.parentNode).hasClass("nohighlight")) { 81 | var span; 82 | var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg"); 83 | if (isInSVG) { 84 | span = document.createElementNS("http://www.w3.org/2000/svg", "tspan"); 85 | } else { 86 | span = document.createElement("span"); 87 | span.className = className; 88 | } 89 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 90 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 91 | document.createTextNode(val.substr(pos + text.length)), 92 | node.nextSibling)); 93 | node.nodeValue = val.substr(0, pos); 94 | if (isInSVG) { 95 | var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect"); 96 | var bbox = node.parentElement.getBBox(); 97 | rect.x.baseVal.value = bbox.x; 98 | rect.y.baseVal.value = bbox.y; 99 | rect.width.baseVal.value = bbox.width; 100 | rect.height.baseVal.value = bbox.height; 101 | rect.setAttribute('class', className); 102 | addItems.push({ 103 | "parent": node.parentNode, 104 | "target": rect}); 105 | } 106 | } 107 | } 108 | else if (!jQuery(node).is("button, select, textarea")) { 109 | jQuery.each(node.childNodes, function() { 110 | highlight(this, addItems); 111 | }); 112 | } 113 | } 114 | var addItems = []; 115 | var result = this.each(function() { 116 | highlight(this, addItems); 117 | }); 118 | for (var i = 0; i < addItems.length; ++i) { 119 | jQuery(addItems[i].parent).before(addItems[i].target); 120 | } 121 | return result; 122 | }; 123 | 124 | /* 125 | * backward compatibility for jQuery.browser 126 | * This will be supported until firefox bug is fixed. 127 | */ 128 | if (!jQuery.browser) { 129 | jQuery.uaMatch = function(ua) { 130 | ua = ua.toLowerCase(); 131 | 132 | var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || 133 | /(webkit)[ \/]([\w.]+)/.exec(ua) || 134 | /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || 135 | /(msie) ([\w.]+)/.exec(ua) || 136 | ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || 137 | []; 138 | 139 | return { 140 | browser: match[ 1 ] || "", 141 | version: match[ 2 ] || "0" 142 | }; 143 | }; 144 | jQuery.browser = {}; 145 | jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true; 146 | } 147 | 148 | /** 149 | * Small JavaScript module for the documentation. 150 | */ 151 | var Documentation = { 152 | 153 | init : function() { 154 | this.fixFirefoxAnchorBug(); 155 | this.highlightSearchWords(); 156 | this.initIndexTable(); 157 | if (DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) { 158 | this.initOnKeyListeners(); 159 | } 160 | }, 161 | 162 | /** 163 | * i18n support 164 | */ 165 | TRANSLATIONS : {}, 166 | PLURAL_EXPR : function(n) { return n === 1 ? 0 : 1; }, 167 | LOCALE : 'unknown', 168 | 169 | // gettext and ngettext don't access this so that the functions 170 | // can safely bound to a different name (_ = Documentation.gettext) 171 | gettext : function(string) { 172 | var translated = Documentation.TRANSLATIONS[string]; 173 | if (typeof translated === 'undefined') 174 | return string; 175 | return (typeof translated === 'string') ? translated : translated[0]; 176 | }, 177 | 178 | ngettext : function(singular, plural, n) { 179 | var translated = Documentation.TRANSLATIONS[singular]; 180 | if (typeof translated === 'undefined') 181 | return (n == 1) ? singular : plural; 182 | return translated[Documentation.PLURALEXPR(n)]; 183 | }, 184 | 185 | addTranslations : function(catalog) { 186 | for (var key in catalog.messages) 187 | this.TRANSLATIONS[key] = catalog.messages[key]; 188 | this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')'); 189 | this.LOCALE = catalog.locale; 190 | }, 191 | 192 | /** 193 | * add context elements like header anchor links 194 | */ 195 | addContextElements : function() { 196 | $('div[id] > :header:first').each(function() { 197 | $('\u00B6'). 198 | attr('href', '#' + this.id). 199 | attr('title', _('Permalink to this headline')). 200 | appendTo(this); 201 | }); 202 | $('dt[id]').each(function() { 203 | $('\u00B6'). 204 | attr('href', '#' + this.id). 205 | attr('title', _('Permalink to this definition')). 206 | appendTo(this); 207 | }); 208 | }, 209 | 210 | /** 211 | * workaround a firefox stupidity 212 | * see: https://bugzilla.mozilla.org/show_bug.cgi?id=645075 213 | */ 214 | fixFirefoxAnchorBug : function() { 215 | if (document.location.hash && $.browser.mozilla) 216 | window.setTimeout(function() { 217 | document.location.href += ''; 218 | }, 10); 219 | }, 220 | 221 | /** 222 | * highlight the search words provided in the url in the text 223 | */ 224 | highlightSearchWords : function() { 225 | var params = $.getQueryParameters(); 226 | var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : []; 227 | if (terms.length) { 228 | var body = $('div.body'); 229 | if (!body.length) { 230 | body = $('body'); 231 | } 232 | window.setTimeout(function() { 233 | $.each(terms, function() { 234 | body.highlightText(this.toLowerCase(), 'highlighted'); 235 | }); 236 | }, 10); 237 | $('') 239 | .appendTo($('#searchbox')); 240 | } 241 | }, 242 | 243 | /** 244 | * init the domain index toggle buttons 245 | */ 246 | initIndexTable : function() { 247 | var togglers = $('img.toggler').click(function() { 248 | var src = $(this).attr('src'); 249 | var idnum = $(this).attr('id').substr(7); 250 | $('tr.cg-' + idnum).toggle(); 251 | if (src.substr(-9) === 'minus.png') 252 | $(this).attr('src', src.substr(0, src.length-9) + 'plus.png'); 253 | else 254 | $(this).attr('src', src.substr(0, src.length-8) + 'minus.png'); 255 | }).css('display', ''); 256 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) { 257 | togglers.click(); 258 | } 259 | }, 260 | 261 | /** 262 | * helper function to hide the search marks again 263 | */ 264 | hideSearchWords : function() { 265 | $('#searchbox .highlight-link').fadeOut(300); 266 | $('span.highlighted').removeClass('highlighted'); 267 | }, 268 | 269 | /** 270 | * make the url absolute 271 | */ 272 | makeURL : function(relativeURL) { 273 | return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL; 274 | }, 275 | 276 | /** 277 | * get the current relative url 278 | */ 279 | getCurrentURL : function() { 280 | var path = document.location.pathname; 281 | var parts = path.split(/\//); 282 | $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() { 283 | if (this === '..') 284 | parts.pop(); 285 | }); 286 | var url = parts.join('/'); 287 | return path.substring(url.lastIndexOf('/') + 1, path.length - 1); 288 | }, 289 | 290 | initOnKeyListeners: function() { 291 | $(document).keydown(function(event) { 292 | var activeElementType = document.activeElement.tagName; 293 | // don't navigate when in search box, textarea, dropdown or button 294 | if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT' 295 | && activeElementType !== 'BUTTON' && !event.altKey && !event.ctrlKey && !event.metaKey 296 | && !event.shiftKey) { 297 | switch (event.keyCode) { 298 | case 37: // left 299 | var prevHref = $('link[rel="prev"]').prop('href'); 300 | if (prevHref) { 301 | window.location.href = prevHref; 302 | return false; 303 | } 304 | break; 305 | case 39: // right 306 | var nextHref = $('link[rel="next"]').prop('href'); 307 | if (nextHref) { 308 | window.location.href = nextHref; 309 | return false; 310 | } 311 | break; 312 | } 313 | } 314 | }); 315 | } 316 | }; 317 | 318 | // quick alias for translations 319 | _ = Documentation.gettext; 320 | 321 | $(document).ready(function() { 322 | Documentation.init(); 323 | }); 324 | -------------------------------------------------------------------------------- /docs/_static/language_data.js: -------------------------------------------------------------------------------- 1 | /* 2 | * language_data.js 3 | * ~~~~~~~~~~~~~~~~ 4 | * 5 | * This script contains the language-specific data used by searchtools.js, 6 | * namely the list of stopwords, stemmer, scorer and splitter. 7 | * 8 | * :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. 9 | * :license: BSD, see LICENSE for details. 10 | * 11 | */ 12 | 13 | var stopwords = ["a","and","are","as","at","be","but","by","for","if","in","into","is","it","near","no","not","of","on","or","such","that","the","their","then","there","these","they","this","to","was","will","with"]; 14 | 15 | 16 | /* Non-minified version is copied as a separate JS file, is available */ 17 | 18 | /** 19 | * Porter Stemmer 20 | */ 21 | var Stemmer = function() { 22 | 23 | var step2list = { 24 | ational: 'ate', 25 | tional: 'tion', 26 | enci: 'ence', 27 | anci: 'ance', 28 | izer: 'ize', 29 | bli: 'ble', 30 | alli: 'al', 31 | entli: 'ent', 32 | eli: 'e', 33 | ousli: 'ous', 34 | ization: 'ize', 35 | ation: 'ate', 36 | ator: 'ate', 37 | alism: 'al', 38 | iveness: 'ive', 39 | fulness: 'ful', 40 | ousness: 'ous', 41 | aliti: 'al', 42 | iviti: 'ive', 43 | biliti: 'ble', 44 | logi: 'log' 45 | }; 46 | 47 | var step3list = { 48 | icate: 'ic', 49 | ative: '', 50 | alize: 'al', 51 | iciti: 'ic', 52 | ical: 'ic', 53 | ful: '', 54 | ness: '' 55 | }; 56 | 57 | var c = "[^aeiou]"; // consonant 58 | var v = "[aeiouy]"; // vowel 59 | var C = c + "[^aeiouy]*"; // consonant sequence 60 | var V = v + "[aeiou]*"; // vowel sequence 61 | 62 | var mgr0 = "^(" + C + ")?" + V + C; // [C]VC... is m>0 63 | var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1 64 | var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1 65 | var s_v = "^(" + C + ")?" + v; // vowel in stem 66 | 67 | this.stemWord = function (w) { 68 | var stem; 69 | var suffix; 70 | var firstch; 71 | var origword = w; 72 | 73 | if (w.length < 3) 74 | return w; 75 | 76 | var re; 77 | var re2; 78 | var re3; 79 | var re4; 80 | 81 | firstch = w.substr(0,1); 82 | if (firstch == "y") 83 | w = firstch.toUpperCase() + w.substr(1); 84 | 85 | // Step 1a 86 | re = /^(.+?)(ss|i)es$/; 87 | re2 = /^(.+?)([^s])s$/; 88 | 89 | if (re.test(w)) 90 | w = w.replace(re,"$1$2"); 91 | else if (re2.test(w)) 92 | w = w.replace(re2,"$1$2"); 93 | 94 | // Step 1b 95 | re = /^(.+?)eed$/; 96 | re2 = /^(.+?)(ed|ing)$/; 97 | if (re.test(w)) { 98 | var fp = re.exec(w); 99 | re = new RegExp(mgr0); 100 | if (re.test(fp[1])) { 101 | re = /.$/; 102 | w = w.replace(re,""); 103 | } 104 | } 105 | else if (re2.test(w)) { 106 | var fp = re2.exec(w); 107 | stem = fp[1]; 108 | re2 = new RegExp(s_v); 109 | if (re2.test(stem)) { 110 | w = stem; 111 | re2 = /(at|bl|iz)$/; 112 | re3 = new RegExp("([^aeiouylsz])\\1$"); 113 | re4 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 114 | if (re2.test(w)) 115 | w = w + "e"; 116 | else if (re3.test(w)) { 117 | re = /.$/; 118 | w = w.replace(re,""); 119 | } 120 | else if (re4.test(w)) 121 | w = w + "e"; 122 | } 123 | } 124 | 125 | // Step 1c 126 | re = /^(.+?)y$/; 127 | if (re.test(w)) { 128 | var fp = re.exec(w); 129 | stem = fp[1]; 130 | re = new RegExp(s_v); 131 | if (re.test(stem)) 132 | w = stem + "i"; 133 | } 134 | 135 | // Step 2 136 | re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/; 137 | if (re.test(w)) { 138 | var fp = re.exec(w); 139 | stem = fp[1]; 140 | suffix = fp[2]; 141 | re = new RegExp(mgr0); 142 | if (re.test(stem)) 143 | w = stem + step2list[suffix]; 144 | } 145 | 146 | // Step 3 147 | re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/; 148 | if (re.test(w)) { 149 | var fp = re.exec(w); 150 | stem = fp[1]; 151 | suffix = fp[2]; 152 | re = new RegExp(mgr0); 153 | if (re.test(stem)) 154 | w = stem + step3list[suffix]; 155 | } 156 | 157 | // Step 4 158 | re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/; 159 | re2 = /^(.+?)(s|t)(ion)$/; 160 | if (re.test(w)) { 161 | var fp = re.exec(w); 162 | stem = fp[1]; 163 | re = new RegExp(mgr1); 164 | if (re.test(stem)) 165 | w = stem; 166 | } 167 | else if (re2.test(w)) { 168 | var fp = re2.exec(w); 169 | stem = fp[1] + fp[2]; 170 | re2 = new RegExp(mgr1); 171 | if (re2.test(stem)) 172 | w = stem; 173 | } 174 | 175 | // Step 5 176 | re = /^(.+?)e$/; 177 | if (re.test(w)) { 178 | var fp = re.exec(w); 179 | stem = fp[1]; 180 | re = new RegExp(mgr1); 181 | re2 = new RegExp(meq1); 182 | re3 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 183 | if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) 184 | w = stem; 185 | } 186 | re = /ll$/; 187 | re2 = new RegExp(mgr1); 188 | if (re.test(w) && re2.test(w)) { 189 | re = /.$/; 190 | w = w.replace(re,""); 191 | } 192 | 193 | // and turn initial Y back to y 194 | if (firstch == "y") 195 | w = firstch.toLowerCase() + w.substr(1); 196 | return w; 197 | } 198 | } 199 | 200 | 201 | 202 | 203 | var splitChars = (function() { 204 | var result = {}; 205 | var singles = [96, 180, 187, 191, 215, 247, 749, 885, 903, 907, 909, 930, 1014, 1648, 206 | 1748, 1809, 2416, 2473, 2481, 2526, 2601, 2609, 2612, 2615, 2653, 2702, 207 | 2706, 2729, 2737, 2740, 2857, 2865, 2868, 2910, 2928, 2948, 2961, 2971, 208 | 2973, 3085, 3089, 3113, 3124, 3213, 3217, 3241, 3252, 3295, 3341, 3345, 209 | 3369, 3506, 3516, 3633, 3715, 3721, 3736, 3744, 3748, 3750, 3756, 3761, 210 | 3781, 3912, 4239, 4347, 4681, 4695, 4697, 4745, 4785, 4799, 4801, 4823, 211 | 4881, 5760, 5901, 5997, 6313, 7405, 8024, 8026, 8028, 8030, 8117, 8125, 212 | 8133, 8181, 8468, 8485, 8487, 8489, 8494, 8527, 11311, 11359, 11687, 11695, 213 | 11703, 11711, 11719, 11727, 11735, 12448, 12539, 43010, 43014, 43019, 43587, 214 | 43696, 43713, 64286, 64297, 64311, 64317, 64319, 64322, 64325, 65141]; 215 | var i, j, start, end; 216 | for (i = 0; i < singles.length; i++) { 217 | result[singles[i]] = true; 218 | } 219 | var ranges = [[0, 47], [58, 64], [91, 94], [123, 169], [171, 177], [182, 184], [706, 709], 220 | [722, 735], [741, 747], [751, 879], [888, 889], [894, 901], [1154, 1161], 221 | [1318, 1328], [1367, 1368], [1370, 1376], [1416, 1487], [1515, 1519], [1523, 1568], 222 | [1611, 1631], [1642, 1645], [1750, 1764], [1767, 1773], [1789, 1790], [1792, 1807], 223 | [1840, 1868], [1958, 1968], [1970, 1983], [2027, 2035], [2038, 2041], [2043, 2047], 224 | [2070, 2073], [2075, 2083], [2085, 2087], [2089, 2307], [2362, 2364], [2366, 2383], 225 | [2385, 2391], [2402, 2405], [2419, 2424], [2432, 2436], [2445, 2446], [2449, 2450], 226 | [2483, 2485], [2490, 2492], [2494, 2509], [2511, 2523], [2530, 2533], [2546, 2547], 227 | [2554, 2564], [2571, 2574], [2577, 2578], [2618, 2648], [2655, 2661], [2672, 2673], 228 | [2677, 2692], [2746, 2748], [2750, 2767], [2769, 2783], [2786, 2789], [2800, 2820], 229 | [2829, 2830], [2833, 2834], [2874, 2876], [2878, 2907], [2914, 2917], [2930, 2946], 230 | [2955, 2957], [2966, 2968], [2976, 2978], [2981, 2983], [2987, 2989], [3002, 3023], 231 | [3025, 3045], [3059, 3076], [3130, 3132], [3134, 3159], [3162, 3167], [3170, 3173], 232 | [3184, 3191], [3199, 3204], [3258, 3260], [3262, 3293], [3298, 3301], [3312, 3332], 233 | [3386, 3388], [3390, 3423], [3426, 3429], [3446, 3449], [3456, 3460], [3479, 3481], 234 | [3518, 3519], [3527, 3584], [3636, 3647], [3655, 3663], [3674, 3712], [3717, 3718], 235 | [3723, 3724], [3726, 3731], [3752, 3753], [3764, 3772], [3774, 3775], [3783, 3791], 236 | [3802, 3803], [3806, 3839], [3841, 3871], [3892, 3903], [3949, 3975], [3980, 4095], 237 | [4139, 4158], [4170, 4175], [4182, 4185], [4190, 4192], [4194, 4196], [4199, 4205], 238 | [4209, 4212], [4226, 4237], [4250, 4255], [4294, 4303], [4349, 4351], [4686, 4687], 239 | [4702, 4703], [4750, 4751], [4790, 4791], [4806, 4807], [4886, 4887], [4955, 4968], 240 | [4989, 4991], [5008, 5023], [5109, 5120], [5741, 5742], [5787, 5791], [5867, 5869], 241 | [5873, 5887], [5906, 5919], [5938, 5951], [5970, 5983], [6001, 6015], [6068, 6102], 242 | [6104, 6107], [6109, 6111], [6122, 6127], [6138, 6159], [6170, 6175], [6264, 6271], 243 | [6315, 6319], [6390, 6399], [6429, 6469], [6510, 6511], [6517, 6527], [6572, 6592], 244 | [6600, 6607], [6619, 6655], [6679, 6687], [6741, 6783], [6794, 6799], [6810, 6822], 245 | [6824, 6916], [6964, 6980], [6988, 6991], [7002, 7042], [7073, 7085], [7098, 7167], 246 | [7204, 7231], [7242, 7244], [7294, 7400], [7410, 7423], [7616, 7679], [7958, 7959], 247 | [7966, 7967], [8006, 8007], [8014, 8015], [8062, 8063], [8127, 8129], [8141, 8143], 248 | [8148, 8149], [8156, 8159], [8173, 8177], [8189, 8303], [8306, 8307], [8314, 8318], 249 | [8330, 8335], [8341, 8449], [8451, 8454], [8456, 8457], [8470, 8472], [8478, 8483], 250 | [8506, 8507], [8512, 8516], [8522, 8525], [8586, 9311], [9372, 9449], [9472, 10101], 251 | [10132, 11263], [11493, 11498], [11503, 11516], [11518, 11519], [11558, 11567], 252 | [11622, 11630], [11632, 11647], [11671, 11679], [11743, 11822], [11824, 12292], 253 | [12296, 12320], [12330, 12336], [12342, 12343], [12349, 12352], [12439, 12444], 254 | [12544, 12548], [12590, 12592], [12687, 12689], [12694, 12703], [12728, 12783], 255 | [12800, 12831], [12842, 12880], [12896, 12927], [12938, 12976], [12992, 13311], 256 | [19894, 19967], [40908, 40959], [42125, 42191], [42238, 42239], [42509, 42511], 257 | [42540, 42559], [42592, 42593], [42607, 42622], [42648, 42655], [42736, 42774], 258 | [42784, 42785], [42889, 42890], [42893, 43002], [43043, 43055], [43062, 43071], 259 | [43124, 43137], [43188, 43215], [43226, 43249], [43256, 43258], [43260, 43263], 260 | [43302, 43311], [43335, 43359], [43389, 43395], [43443, 43470], [43482, 43519], 261 | [43561, 43583], [43596, 43599], [43610, 43615], [43639, 43641], [43643, 43647], 262 | [43698, 43700], [43703, 43704], [43710, 43711], [43715, 43738], [43742, 43967], 263 | [44003, 44015], [44026, 44031], [55204, 55215], [55239, 55242], [55292, 55295], 264 | [57344, 63743], [64046, 64047], [64110, 64111], [64218, 64255], [64263, 64274], 265 | [64280, 64284], [64434, 64466], [64830, 64847], [64912, 64913], [64968, 65007], 266 | [65020, 65135], [65277, 65295], [65306, 65312], [65339, 65344], [65371, 65381], 267 | [65471, 65473], [65480, 65481], [65488, 65489], [65496, 65497]]; 268 | for (i = 0; i < ranges.length; i++) { 269 | start = ranges[i][0]; 270 | end = ranges[i][1]; 271 | for (j = start; j <= end; j++) { 272 | result[j] = true; 273 | } 274 | } 275 | return result; 276 | })(); 277 | 278 | function splitQuery(query) { 279 | var result = []; 280 | var start = -1; 281 | for (var i = 0; i < query.length; i++) { 282 | if (splitChars[query.charCodeAt(i)]) { 283 | if (start !== -1) { 284 | result.push(query.slice(start, i)); 285 | start = -1; 286 | } 287 | } else if (start === -1) { 288 | start = i; 289 | } 290 | } 291 | if (start !== -1) { 292 | result.push(query.slice(start)); 293 | } 294 | return result; 295 | } 296 | 297 | 298 | -------------------------------------------------------------------------------- /sampleBots/ReplyUsingNameBot.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Type in @@ to exit bot\n", 13 | "@i to get intents\n", 14 | "@c to get context \n", 15 | "@e to get entities\n", 16 | "@t to add a test case\n", 17 | "@etc to evaluate a test case\n", 18 | "@eatc to evaluate all test cases\n", 19 | "@ti to add intent\n", 20 | "<1> User : Hi\n", 21 | "<1> basicBot : Hello ! What can i do for you ?\n", 22 | "<2> User : who are you ?\n", 23 | "<2> basicBot : I am riko\n", 24 | "<3> User : hey Riko you can call me Victor .\n", 25 | "<3> basicBot : Its a pleasure to meet you Victor .\n", 26 | "<4> User : Im driving a car Can you please call me Vic ?\n", 27 | "<4> basicBot : Its a pleasure to meet you Vic .\n", 28 | "<5> User : hey\n", 29 | "<5> basicBot : Hey Vic its a pleasure talking to you !\n", 30 | "<6> User : @@\n" 31 | ] 32 | } 33 | ], 34 | "source": [ 35 | "import spacy\n", 36 | "\n", 37 | "# Load English tokenizer, tagger, parser and NER\n", 38 | "nlp = spacy.load(\"en_core_web_sm\")\n", 39 | "\n", 40 | "def extractor(messageText,dialogNumber):\n", 41 | " doc = nlp(messageText)\n", 42 | " extractedNamesFromText = []\n", 43 | " for entity in doc.ents:\n", 44 | " if entity.label_ =='PERSON':\n", 45 | " extractedNamesFromText.append(\n", 46 | "\n", 47 | " {\n", 48 | " \"value\" : entity.text,\n", 49 | " \"exactValue\" : entity.text,\n", 50 | " \"kind\":'PERSON',\n", 51 | " \"dialogNumber\": dialogNumber,\n", 52 | " \"foundAt\":[entity.start_char, entity.end_char]\n", 53 | " }\n", 54 | " )\n", 55 | " return extractedNamesFromText\n", 56 | "\n", 57 | "\n", 58 | "def substituter(messageText):\n", 59 | " doc = nlp(messageText)\n", 60 | " textLabel = [(entity.text, entity.label_) for entity in doc.ents if entity.label_=='PERSON']\n", 61 | " for text, label in textLabel:\n", 62 | " messageText = messageText.replace(text, \"--!\"+label)\n", 63 | "\n", 64 | " return messageText\n", 65 | "\n", 66 | "\n", 67 | "\n", 68 | "from simbots.Bot import Bot\n", 69 | "from simbots.utils.builtInIntents import IntentSamples\n", 70 | "from simbots.utils.builtInEntities import EntitySamples\n", 71 | "import json\n", 72 | "\n", 73 | "intentExamples = {\n", 74 | "\n", 75 | " \"PersonName\": [\"My name is Vaibhav\",\"I am Vaibhav Arora .\",\"You can call me Rahul .\" ,\n", 76 | " \"I am Simon . \",\"I am Riko .\",\"You can call me Shiva . \"],\n", 77 | "\n", 78 | " 'Greetings': IntentSamples.greetingSamples(),\n", 79 | "\n", 80 | " 'BotName': IntentSamples.botNameSamples(),\n", 81 | "\n", 82 | " 'Relatives': IntentSamples.relativeSamples(),\n", 83 | "\n", 84 | " 'Age': IntentSamples.ageSamples(),\n", 85 | "\n", 86 | " 'BirthPlace': IntentSamples.birthPlaceSamples(),\n", 87 | "\n", 88 | " 'Abilities': IntentSamples.abilitiesSamples(),\n", 89 | "\n", 90 | " 'Really': IntentSamples.reallySamples(),\n", 91 | "\n", 92 | " 'Laughter': IntentSamples.laughterSamples(),\n", 93 | "\n", 94 | " 'Cool': IntentSamples.coolSamples(),\n", 95 | "\n", 96 | " 'Praise': IntentSamples.praiseSamples(),\n", 97 | "\n", 98 | " 'TrueT': IntentSamples.trueSamples(),\n", 99 | "\n", 100 | " 'FalseT': IntentSamples.falseSamples(),\n", 101 | "\n", 102 | " 'Bye': IntentSamples.byeSamples(),\n", 103 | "\n", 104 | " 'Confirm': IntentSamples.confirmSamples(),\n", 105 | "\n", 106 | " 'Thanks': IntentSamples.thanksSamples(),\n", 107 | "\n", 108 | " 'Irrelevant': ['the weather is fine today','the sun rises in the east','the quick brown fox jumps over the red carpet',\n", 109 | " 'the sun rises in the east',\n", 110 | " 'What is love , baby dont hurt me ',\n", 111 | " 'this is a new dawn a new day'],\n", 112 | "}\n", 113 | "\n", 114 | "\n", 115 | "entityExamples = {\n", 116 | " 'GreetingsHelper': EntitySamples.greetingsHelper(),\n", 117 | " 'LaughterHelper': {'haha': [{ 'tag': 'case-insensitive',\n", 118 | " 'pattern': \"\\s(h+(a|e)+)+(h+)?\\s\",\n", 119 | " 'type': 'regex'}],\n", 120 | " 'happysmily': [{'tag': 'case-insensitive',\n", 121 | " 'pattern': \"\\s\\:\\)\\s\", 'type': 'regex'}]},\n", 122 | " 'CoolHelper': EntitySamples.coolHelper(),\n", 123 | " 'ByeHelper': EntitySamples.byeHelper(),\n", 124 | " 'NameHelper':{\n", 125 | " 'personName':[{'type' : 'function',\n", 126 | " 'extractor': extractor,\n", 127 | " 'substituter':substituter,\n", 128 | " 'tag':'case-insensitive'\n", 129 | " }]\n", 130 | "\n", 131 | "\n", 132 | "\n", 133 | " }\n", 134 | "}\n", 135 | "\n", 136 | "\n", 137 | "\n", 138 | "botMessages = {\n", 139 | " 'basic': {\n", 140 | " 'Greetings': {\n", 141 | " 'basic': ['Hello ! What can i do for you ?',\n", 142 | " 'Hi there ! what can I do for you ?', 'Hello'\n", 143 | " ],\n", 144 | " \"nameKnown\":[\n", 145 | " \"Hi {0} ! Its a pleasure to meet you !\",\n", 146 | " \"Hey {0} its a pleasure talking to you !\"\n", 147 | " ]\n", 148 | " },\n", 149 | " \"PersonName\": {\n", 150 | " 'basic': [\"Its a pleasure to meet you {0} .\"],\n", 151 | " \"nameNotFound\": [\"Im sorry i couldn't get your name could you please write it in title case like -> Riko \"]\n", 152 | "\n", 153 | "\n", 154 | " },\n", 155 | " 'Age': {\n", 156 | " 'basic': ['I am two years old ', 'I am two']\n", 157 | " },\n", 158 | " 'BotName': {\n", 159 | " 'basic': ['I am riko', 'You can call me riko']\n", 160 | " },\n", 161 | " 'Abilities': {\n", 162 | " 'basic': ['I am still learning ! So cant do much !']\n", 163 | " },\n", 164 | " 'BirthPlace': {\n", 165 | " 'basic': ['I am from Punjab , india', 'I am punjabi', 'I am punjabi and i love food']\n", 166 | " },\n", 167 | " 'Really': {\n", 168 | " 'basic': ['To the best of my knowledge', 'Im positive !']\n", 169 | " },\n", 170 | " 'Laughter': {\n", 171 | " 'basic': ['Im glad i was able to make you smile !',\n", 172 | " 'See I can be funny !',\n", 173 | " 'And they say I dont have a sense of humor :)'\n", 174 | " ]\n", 175 | " },\n", 176 | " 'Cool': {\n", 177 | " 'basic': ['cool', 'thanks']\n", 178 | " },\n", 179 | " 'Bye': {\n", 180 | " 'basic': ['Bubye !', 'Bye ! nice chatting with you !']\n", 181 | " },\n", 182 | " 'Confirm': {\n", 183 | " 'basic': ['cool ']\n", 184 | " },\n", 185 | " 'Discard': {\n", 186 | " 'basic': ['No it is then', 'agreed , no it is .']\n", 187 | " },\n", 188 | " 'Praise': {\n", 189 | " 'basic': ['Thanks ! now i think ill blush ',\n", 190 | " 'So nice of you to say that !'\n", 191 | " ]\n", 192 | " },\n", 193 | " 'Relatives': {\n", 194 | " 'basic': ['Umm no i dont really have any relatives :)']\n", 195 | " },\n", 196 | " 'Thanks': {\n", 197 | " 'basic': ['Dont mention it ',\n", 198 | " ' Im glad , please dont mention it'\n", 199 | " ]\n", 200 | " },\n", 201 | " 'Irrelevant': {\n", 202 | " 'basic': ['Im sorry Im not getting you :( ',\n", 203 | " 'Im sorry could you please rephrase ?'\n", 204 | " ]\n", 205 | " },\n", 206 | " }\n", 207 | "}\n", 208 | "\n", 209 | "class NewBot(Bot):\n", 210 | "\n", 211 | " def reason(self):\n", 212 | "\n", 213 | " # # find current dialogNumber\n", 214 | "\n", 215 | " currentDialogNumber = self.contextManager.context['dialogs'][-1]\n", 216 | "\n", 217 | " currentTopIntent = self.contextManager.findCurrentTopIntent()\n", 218 | "\n", 219 | " currentEntities = self.contextManager.findCurrentEntities()\n", 220 | "\n", 221 | " output = []\n", 222 | "\n", 223 | " if currentTopIntent['confidence'] < self.confidenceLimit or currentTopIntent['name'] == 'Irrelevant':\n", 224 | " currentTopIntent = {}\n", 225 | "\n", 226 | " if currentTopIntent:\n", 227 | " ##\n", 228 | " ## Getting the Intent name here\n", 229 | " ##\n", 230 | " name = currentTopIntent['name']\n", 231 | "\n", 232 | " if name == 'Greetings' and (\"sessionVariables\" in self.contextManager.context.keys()):\n", 233 | "\n", 234 | " personName = self.contextManager.context[\"sessionVariables\"][\"PERSON\"]\n", 235 | "\n", 236 | " reply = {'tag': '{0}.nameKnown'.format(name), 'data': personName}\n", 237 | "\n", 238 | "\n", 239 | " elif name =='PersonName' and len(currentEntities) >0:\n", 240 | "\n", 241 | " currentEntities =[ent for ent in currentEntities if ent[\"kind\"] =='PERSON' and ent[\"exactValue\"].lower() != 'riko']\n", 242 | "\n", 243 | " self.contextManager.context[\"sessionVariables\"] = {\n", 244 | "\n", 245 | " \"PERSON\" :currentEntities[0][\"exactValue\"]\n", 246 | "\n", 247 | " }\n", 248 | " self.contextManager.updateContextTree()\n", 249 | "\n", 250 | "\n", 251 | " reply = {'tag': '{0}.basic'.format(name), 'data': currentEntities[0][\"exactValue\"]}\n", 252 | "\n", 253 | " elif name =='PersonName':\n", 254 | "\n", 255 | " reply = {'tag': '{0}.nameNotFound'.format(name), 'data': None}\n", 256 | " else:\n", 257 | " reply = {'tag': '{0}.basic'.format(name), 'data': None}\n", 258 | "\n", 259 | "\n", 260 | " output.append(reply)\n", 261 | "\n", 262 | " else:\n", 263 | "\n", 264 | " # #\n", 265 | " # #\n", 266 | " # # Rule for irrelevant\n", 267 | " # #\n", 268 | " # #\n", 269 | "\n", 270 | " irrelevant = {'tag': 'Irrelevant.basic', 'data': None}\n", 271 | "\n", 272 | " output.append(irrelevant)\n", 273 | "\n", 274 | " return output\n", 275 | "\n", 276 | "\n", 277 | "newB = NewBot(intentExamples, entityExamples, botMessages,\n", 278 | " confidenceLimit=0.5)\n", 279 | "\n", 280 | "outputTheme = 'basic'\n", 281 | "\n", 282 | "newB.run(theme = outputTheme)" 283 | ] 284 | }, 285 | { 286 | "cell_type": "code", 287 | "execution_count": null, 288 | "metadata": {}, 289 | "outputs": [], 290 | "source": [] 291 | } 292 | ], 293 | "metadata": { 294 | "kernelspec": { 295 | "display_name": "condagpu", 296 | "language": "python", 297 | "name": "condagpu" 298 | }, 299 | "language_info": { 300 | "codemirror_mode": { 301 | "name": "ipython", 302 | "version": 3 303 | }, 304 | "file_extension": ".py", 305 | "mimetype": "text/x-python", 306 | "name": "python", 307 | "nbconvert_exporter": "python", 308 | "pygments_lexer": "ipython3", 309 | "version": "3.7.7" 310 | } 311 | }, 312 | "nbformat": 4, 313 | "nbformat_minor": 4 314 | } 315 | -------------------------------------------------------------------------------- /simbots/simbots/utils/builtInIntents.py: -------------------------------------------------------------------------------- 1 | 2 | class IntentSamples(): 3 | """ 4 | Contains samples for frequently used intents, which can be used to train intents .Each method returns a list of samples 5 | 6 | """ 7 | def __init__(self): 8 | pass 9 | 10 | @staticmethod 11 | def greetingSamples(): 12 | """ 13 | :return: list of samples like 'Hello !', 'Hi , How are you ?', 14 | """ 15 | return [ 16 | 'Hello !', 17 | 'Hi , How are you ?', 18 | 'Hey !! ', 19 | 'Namaste ', 20 | 'Good day', 21 | 'Good evening', 22 | 'Good morning', 23 | 'Good to see you', 24 | 'Greetings', 25 | 'Have you been well?', 26 | 'Hello Agent', 27 | 'Hello', 28 | 'Hey how are you doing', 29 | 'Hey there all', 30 | 'Hey there', 31 | 'Hey twin', 32 | 'Hey you', 33 | 'Hi advisor', 34 | 'Hi there', 35 | 'How are things going?', 36 | 'How are you today?', 37 | 'How have you been?', 38 | 'How is it going?', 39 | 'How r u?', 40 | 'Looking good eve', 41 | "What's new?", 42 | "What's up?", 43 | 'You there', 44 | 'Namaste', 45 | 'satsriyakaal', 46 | 'helo', 47 | 'hiiiiiii', 48 | ' sup ', 49 | ' wassup bruh ', 50 | ' sup bro ', 51 | ' ssssup mate whats up', 52 | "hi", 53 | "hey" 54 | ] 55 | @staticmethod 56 | def botNameSamples(): 57 | """ 58 | :return: list of samples like 'Who is this?', 'Hi' ,'Who are you', 59 | """ 60 | return [ 61 | 'Who is this?', 62 | 'Who are you', 63 | 'Who are you ?', 64 | 'What is your Name ?', 65 | 'What is your name ', 66 | 'what should i call you ?', 67 | 'What should i call you', 68 | 'How to address you ?', 69 | 'how to address you by name', 70 | 'what is your name ', 71 | 'call you', 72 | 'your name', 73 | 'call you ?', 74 | 'your name ?', 75 | 'whom are you', 76 | 'whom are you referred as', 77 | ] 78 | 79 | @staticmethod 80 | def relativeSamples(): 81 | """ 82 | 83 | :return: list of samples like 'Do you have any relatives ' , "do you have any siblings ?" 84 | """ 85 | return [ 86 | 'Do you have any relatives ', 87 | 'Do you have a sibling ', 88 | 'Any brother or sister', 89 | 'Do you have a father', 90 | 'Do you happen to have a grandparent ?', 91 | 'Any grandparents or parents ', 92 | 'do you have Any wife ?', 93 | 'Are you married ?', 94 | ] 95 | 96 | @staticmethod 97 | def ageSamples(): 98 | """ 99 | :return: list of samples like 'what is your age' , "how old are you ?" 100 | 101 | """ 102 | return [ 103 | 'What is your age', 104 | 'your age ?', 105 | 'how old are you ?' 106 | 'when were you born', 107 | 'your year of birth', 108 | 'year of birth', 109 | 'when were you born again', 110 | 'born ?', 111 | 'born again ?', 112 | "how long have you lived ?" 113 | 114 | ] 115 | 116 | @staticmethod 117 | def birthPlaceSamples(): 118 | """ 119 | 120 | :return: list of samples like 'where were you born ' , "where are you from ?" 121 | """ 122 | return [ 123 | 'where were you born ?', 124 | 'where are you from', 125 | 'where in the world are you from ?', 126 | 'where do you belong to', 127 | 'you are from ', 128 | 'are you from ', 129 | 'you belong to ', 130 | 'place of birth', 131 | 'and you are from ?', 132 | 'and your birthplace is from ?and you are from ?', 133 | 'birthplace', 134 | 'place of birth', 135 | 'location of birth', 136 | 'place of residence', 137 | 'location', 138 | 'your address', 139 | 'where do you reside ?', 140 | 'place of residence ?', 141 | ] 142 | 143 | @staticmethod 144 | def abilitiesSamples(): 145 | """ 146 | 147 | :return: list of samples like 'what can you do ? ' , "what are your capabilities ?" 148 | """ 149 | return [ 150 | 'What can you do ?', 151 | 'What are your abilities ', 152 | 'your abilities', 153 | 'your capabilities', 154 | 'what are your capabilities', 155 | 'ability', 156 | 'your ability', 157 | 'capability', 158 | 'your capability', 159 | 'your abilities', 160 | 'your powers', 161 | 'what are your superpowers', 162 | 'superpowers', 163 | 'you are capable of ', 164 | 'what are you capable of', 165 | 'what can you do ?', 166 | 'what can you do ?', 167 | 'Can you jump ?', 168 | 'could you do this ?', 169 | 'could you please do this ?', 170 | ] 171 | @staticmethod 172 | def reallySamples(): 173 | """ 174 | 175 | :return: list of samples like 'is that so ? ' , "really ?" 176 | """ 177 | return [ 178 | 'really', 179 | 'is that so ?', 180 | 'is that what you believe', 181 | 'are you sure', 182 | 'is that what you belief', 183 | 'you positive about that', 184 | 'are you positively sure', 185 | 'is that what you think', 186 | 'are you positive about that ?', 187 | 'you positive', 188 | 'are you really sure', 189 | 'really bro ?', 190 | "ya sure ?" 191 | ] 192 | 193 | @staticmethod 194 | def laughterSamples(): 195 | """ 196 | 197 | :return: list of samples like 'hahaha' , "thats very funny" 198 | """ 199 | return [ 200 | 'i think thats funny ', 201 | 'thats very funny ,hahaha', 202 | 'i think that hahahaha', 203 | 'thats very funny', 204 | 'laughter', 205 | ':)', 206 | 'thats really funny ', 207 | 'I think thats hilarious', 208 | 'thats so funny !', 209 | 'that really made me laugh !', 210 | "you are so funny :)" 211 | ] 212 | 213 | 214 | @staticmethod 215 | def coolSamples(): 216 | """ 217 | 218 | :return: list of samples like "thats cool !","cool" 219 | """ 220 | return [ 221 | 'thats cool', 222 | 'cool', 223 | 'that is really cool', 224 | 'very cool', 225 | 'totally cool !', 226 | 'Awesome !', 227 | 'Very cool', 228 | 'Pretty cool', 229 | 'surely very cool', 230 | 'nice', 231 | 'neat', 232 | 'thats neat', 233 | 'thats pretty neat', 234 | 'thats nice', 235 | ] 236 | 237 | @staticmethod 238 | def praiseSamples(): 239 | """ 240 | 241 | :return: list of samples like 'you are awesome ' , "thats incredible !" 242 | """ 243 | return [ 244 | 'I think that you are absolutely amazing !', 245 | 'I really think you are amazing', 246 | 'You are absolutely fantastic', 247 | 'Thats Incredible', 248 | "you are awesome buddy !", 249 | "this is awesome ", 250 | "talking to you is awesome", 251 | " i believe you are awesome !!", 252 | "pretty awesome my friend !", 253 | "thanks for being so awesome !!" 254 | 'How Extraordinary !', 255 | 'Far Out ! ', 256 | 'Great ! ', 257 | 'Outstanding', 258 | 'Performance', 259 | 'Marvelous', 260 | 'I Cant Get Over It !', 261 | 'Wonderful ! ', 262 | 'Amazing Effort !', 263 | 'Unbelievable Work', 264 | 'You Should Be Proud', 265 | 'Phenomenal ! ', 266 | 'Youve Got It', 267 | 'Superb ! ', 268 | 'Youre Special', 269 | 'Excellent ! ', 270 | 'Cool ! ', 271 | 'Your Project Is First Rate !', 272 | 'Way to Go ! ', 273 | 'Youve Outdone', 274 | 'Yourself', 275 | 'Thumbs Up', 276 | 'What A Great', 277 | 'Listener', 278 | 'Your Help Counts ! ', 279 | 'You Came Through ! ', 280 | 'Terrific', 281 | 'You Tried Hard', 282 | 'Youre OK', 283 | 'Fabulous', 284 | 'You Made It', 285 | 'Happen', 286 | 'Youre a Real', 287 | 'Trooper', 288 | 'It Couldnt Be', 289 | 'Better', 290 | 'The Time You Put in Shows', 291 | 'Bravo ! ', 292 | 'Youre Unique', 293 | 'Exceptional', 294 | 'Fantastic Work', 295 | 'Breathtaking ! ', 296 | 'Youre a Great', 297 | 'Example For Others', 298 | 'Keep Up the Good', 299 | 'Work', 300 | 'Awesome !', 301 | 'I Knew You Had It In You', 302 | 'Youve Made', 303 | 'Progress', 304 | 'Your Work Is Out of Sight', 305 | 'What an Imagination ! ', 306 | 'Its Everything I Hoped For', 307 | 'Stupendous', 308 | 'Youre Sensational', 309 | 'Very Good !', 310 | ] 311 | 312 | @staticmethod 313 | def trueSamples(): 314 | """ 315 | 316 | :return: list of samples like 'thats true' , "thats evident" 317 | """ 318 | return [ 319 | 'Thats True', 320 | 'thats self evident', 321 | 'thats evident', 322 | 'thats truly evident', 323 | 'true that', 324 | 'true as it comes', 325 | 'thats completely true', 326 | 'true as it comes', 327 | 'thats correct', 328 | 'absolutely correct', 329 | ] 330 | 331 | @staticmethod 332 | def falseSamples(): 333 | """ 334 | 335 | :return: list of samples like 'thats false ' , "you are wrong " 336 | """ 337 | return [ 338 | 'thats false', 339 | 'you are wrong', 340 | 'completely wrong', 341 | 'absolutely and utterly wrong', 342 | 'I dont believe that', 343 | 'i think thats not correct ', 344 | 'thats absolutely not correct', 345 | ] 346 | 347 | @staticmethod 348 | def byeSamples(): 349 | """ 350 | 351 | :return: list of samples like 'bye ' , "goodbye" 352 | """ 353 | return [ 354 | 'good bye', 355 | 'bye bye', 356 | 'buh bye', 357 | 'see you later', 358 | 'byee', 359 | 'se ya later aligator', 360 | 'I gotta go', 361 | 'I have someplace else i need to be', 362 | 'I Need to be someplace else', 363 | 'We can talk later', 364 | 'Will chat later', 365 | 'We can chat later', 366 | 'Will be chatting later', 367 | 'goodbye', 368 | ] 369 | 370 | @staticmethod 371 | def confirmSamples(): 372 | """ 373 | 374 | :return: list of samples like 'confirm that' , "yes","do that please" 375 | """ 376 | return [ 377 | 'Yes ', 378 | 'Okay', 379 | 'Please do that', 380 | 'Okay go ahead', 381 | 'You do that', 382 | 'Wrap it up', 383 | 'I confirm', 384 | 'Please do', 385 | 'Sure go ahead', 386 | 'Sure', 387 | 'ok', 388 | 'ok', 389 | 'yep', 390 | 'yep yep do that ', 391 | ] 392 | 393 | @staticmethod 394 | def thanksSamples(): 395 | """ 396 | :return: list of samples like "Thanks"," Thank you" 397 | """ 398 | return ['Thank you', 'Thanks', 'Thank you so very much !'," my thanks !"] 399 | @staticmethod 400 | def discardSamples(): 401 | """ 402 | 403 | :return: list of samples like 'No","cancel that " 404 | """ 405 | 406 | return [ 407 | 'No', 408 | 'No , i dont wanna do that', 409 | 'Nope change that', 410 | ' negative ', 411 | 'No no', 412 | 'I said no', 413 | 'Never', 414 | 'Cancel that', 415 | 'Build a new one', 416 | 'cancel ', 417 | "i do not want to do that", 418 | "i changed my mind", 419 | "i have had a change of heart", 420 | "i think i want to cancel", 421 | "please dont", 422 | "please do not do that" 423 | ] 424 | 425 | @staticmethod 426 | def jokeSamples(): 427 | """ 428 | 429 | :return: list of samples like "can you tell me a joke","tell a joke" 430 | """ 431 | return [ 432 | 'Can you tell a joke ?', 433 | 'Tell a joke !', 434 | 'Tell me another joke !', 435 | 'I want to smile ', 436 | 'can you make me smile', 437 | 'could you tell me a joke ?', 438 | 'make me laugh', 439 | 'I want some laughter', 440 | 'make some laughter', 441 | 'give me some jokes ', 442 | ] 443 | 444 | -------------------------------------------------------------------------------- /simbots/simbots/Intent.py: -------------------------------------------------------------------------------- 1 | import json 2 | from abc import ABC, abstractmethod 3 | from sklearn.feature_extraction.text import CountVectorizer 4 | from sklearn.model_selection import train_test_split 5 | from sklearn.naive_bayes import MultinomialNB 6 | from sklearn import metrics 7 | import copy 8 | from simbots.utils.exceptions import SchemaException 9 | 10 | class Intent(ABC): 11 | """ 12 | The abstract method for any intent. 13 | """ 14 | 15 | @abstractmethod 16 | def __init__(self, intentName="Irrelevant",allIntentExamples=None, entityHandler=None,testSize=0.25,vocab=None): 17 | 18 | self.intentName = intentName 19 | self.testSize = testSize 20 | 21 | if not allIntentExamples: 22 | allIntentExamples = {} 23 | 24 | self.entityHandler = entityHandler 25 | self.allIntentExamples = allIntentExamples 26 | 27 | self.classifier = None 28 | self.vocab=vocab 29 | 30 | self.trainedIntentArray = [] 31 | self.trained = False 32 | self.createIntent() 33 | 34 | 35 | 36 | @abstractmethod 37 | def createIntent(self,clfName=None): 38 | """ 39 | 40 | Method to create intent will be overridden in the derived class 41 | 42 | :param clfName: Classifier Name 43 | :return: the inherited class should return a classifier 44 | 45 | """ 46 | pass 47 | 48 | @staticmethod 49 | @abstractmethod 50 | def train(X_train, y_train, params = None): 51 | """ 52 | 53 | :param X_train: Training examples 54 | :param y_train: Training labels 55 | :param params: Any additional parameters that may be needed can be defined here 56 | :return: 57 | 58 | """ 59 | pass 60 | 61 | 62 | class MultinomialNBIntent(Intent): 63 | """ 64 | Uses Multinomial Naive bayes classifier for intent training. 65 | """ 66 | 67 | def __init__(self,intentName="Irrelevant",allIntentExamples=None,entityHandler = None,vocab=None): 68 | """ 69 | 70 | :param allIntentExamples: 71 | :param entityHandler: 72 | """ 73 | 74 | super().__init__(intentName=intentName,allIntentExamples=allIntentExamples, 75 | entityHandler = entityHandler,testSize=0.25,vocab=vocab) 76 | 77 | 78 | 79 | def createVocab(self): 80 | """ 81 | This function creates the vocab for intent and updates the intent vocabulary 82 | :return: 83 | count_vect : This returns a fitted Countvectorizer object 84 | """ 85 | 86 | ## 87 | ## Initialise the Count Vectoriser 88 | ## 89 | count_vect = CountVectorizer() # stop_words="english" 90 | ## 91 | ## Create the Count Vectoriser Object (This gives a bag of words representation) 92 | ## 93 | allIntentExamplesCopy = copy.deepcopy(self.allIntentExamples) 94 | 95 | allData=[intentExample for intentExamples in allIntentExamplesCopy.values() for intentExample in intentExamples] 96 | count_vect.fit_transform(allData) 97 | vocab=count_vect.vocabulary_ 98 | count_vect.revVocabulary_ = dict(zip(vocab.values(),vocab.keys())) 99 | self.vocab = count_vect 100 | 101 | return count_vect 102 | 103 | def createDataSetForIntent(self): 104 | """ 105 | Creates the data set for the intent model 106 | :return: 107 | X_train: training sentences asn list 108 | X_test: testing sentences as list 109 | X : all sentences as list 110 | y_train: train set labels 111 | y_test: testset labels 112 | y : the complete sample labels (including the training and the testing sets) 113 | 114 | """ 115 | ## 116 | ## if output is 1 means intent is present else not 117 | ## 118 | allIntentExamplesCopy = copy.deepcopy(self.allIntentExamples) 119 | 120 | intentSamples = allIntentExamplesCopy[self.intentName] 121 | 122 | allIntentExamplesCopy.pop(self.intentName, None) 123 | nonIntentSamples = [intentExample for intentExamples in allIntentExamplesCopy.values() for intentExample in 124 | intentExamples] 125 | 126 | Y = [1 for i in range(len(intentSamples))] + [0 for i in range(len(nonIntentSamples))] 127 | intentSamples.extend(nonIntentSamples) 128 | X = copy.deepcopy(intentSamples) 129 | 130 | ## 131 | ## stratify split the dataset to maintain class balance 132 | ## 133 | X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=self.testSize, stratify=Y, random_state=2020) 134 | 135 | return X_train, X_test, X, y_train, y_test, Y 136 | 137 | @staticmethod 138 | def train(X_train, y_train, params = None): 139 | """ 140 | Train the intent model 141 | 142 | :param X_train: Training sentences 143 | :param y_train: Training labels 144 | :param params: None 145 | :return: trained classifier 146 | """ 147 | vectorizer = params["vectorizer"] 148 | X_trainCount = vectorizer.transform(X_train) 149 | clf = MultinomialNB() 150 | clf.fit(X_trainCount, y_train) 151 | return clf 152 | 153 | @staticmethod 154 | def predictClassifierOutput(clf, X, count_vect): 155 | """ 156 | Make predictions on the trained intent 157 | :param clf: trained classifier 158 | :param X: The sample for prediction 159 | :param count_vect: count vectoriser for the classifier 160 | :return: 161 | 162 | predictions: predicted class 163 | probabilities: probablities for the predicted class 164 | """ 165 | X_count = count_vect.transform(X) 166 | predictions = clf.predict(X_count) 167 | probabilities = clf.predict_proba(X_count) 168 | return predictions, probabilities 169 | 170 | 171 | def getIntentProbability(self, userMessage): 172 | """ 173 | Get the intent probability 174 | :param userMessage: Text message from the user 175 | :return: { 176 | "name": classifier name 177 | "confidence": classifier confidence 178 | } 179 | """ 180 | userMessage = [userMessage] 181 | predictions, probabilities = self.predictClassifierOutput(self.classifier["classifier"], userMessage, 182 | self.classifier["data"]["countVect"]) 183 | 184 | 185 | return {"name": self.classifier["name"], "confidence": probabilities[0][1]} 186 | 187 | def createIntent(self, clfName=None): 188 | """ 189 | 190 | :param clfName: Classifier Name , if not provided , will default to intentName+'_multinomialNbClassifier' 191 | :return: classifier 192 | 193 | classifier = { 194 | "name": Classifier name, 195 | "classifier": Classifier Object, 196 | "expectedAccuracy": Training accuracy achieved by the intent, 197 | "data": { 198 | "countVect": count vectoriser , 199 | "trainedOnX": Training samples, 200 | "trainedOnY": Training labels 201 | } 202 | 203 | 204 | 205 | """ 206 | if not clfName: 207 | clfName = self.intentName # + "_multinomialNbClassifier" 208 | 209 | ## 210 | ## Create vocabulary 211 | ## 212 | 213 | if not self.vocab: 214 | cv = self.createVocab() 215 | else: 216 | cv= self.vocab 217 | 218 | X_train, X_test, X_all, y_train, y_test, y_all = self.createDataSetForIntent() 219 | 220 | clf = self.train(X_train, y_train, {"vectorizer" :cv}) 221 | 222 | predictions, probabilities = self.predictClassifierOutput(clf, X_test, cv) 223 | 224 | expectedAccuracy = metrics.accuracy_score(y_test, predictions) 225 | 226 | ## 227 | ## Now train on the complete dataset 228 | ## 229 | clf = self.train(X_all, y_all, {"vectorizer" :cv}) 230 | 231 | classifier = { 232 | "name": clfName, 233 | "classifier": clf, 234 | "expectedAccuracy": expectedAccuracy, 235 | "data": { 236 | "countVect": cv, 237 | "trainedOnX": X_train, 238 | "trainedOnY": y_train 239 | } 240 | } 241 | 242 | self.classifier = classifier 243 | return classifier 244 | 245 | 246 | 247 | class IntentsHandler(): 248 | """ 249 | Class for creating and handling multiple intents 250 | """ 251 | 252 | def __init__(self,allIntentExamples=None, entityHandler=None): 253 | 254 | """ 255 | 256 | Intent Schema validation 257 | 258 | """ 259 | 260 | if type(allIntentExamples) != dict: 261 | raise SchemaException("Intent Samples","", 262 | "Intents should be a dict of the schema : \n "+ 263 | "{\n 'IntentName1' : list of str ,\n 'IntentName2' : list of str \n "+"}" 264 | 265 | ) 266 | 267 | for intentName in allIntentExamples.keys(): 268 | if "_" in intentName: 269 | raise SchemaException("Intent", intentName,"Intent Name should not contain '_' .") 270 | 271 | intentExamples = allIntentExamples[intentName] 272 | 273 | if type(intentExamples) != list: 274 | raise SchemaException("Intent",intentName ,"Intent should be a list of type str , instead intent is {0} .".format(type(intentExamples))) 275 | 276 | for i,intentSample in enumerate(intentExamples): 277 | if type(intentSample) != str: 278 | raise SchemaException("Intent",intentName,"Intent should be a list of type str ,instead intent sample no {0} ({1}) is {2} .".format(i,intentSample,type(intentSample))) 279 | 280 | intentNames = allIntentExamples.keys() 281 | if "Irrelevant" not in intentNames: 282 | raise SchemaException("Intent Samples","No intent with the name Irrelevant .","Every bot should have an intent with the name 'Irrelevant' , not found in detected intent names .") 283 | ## 284 | ## Initialise intent 285 | ## 286 | self.allIntentExamples = allIntentExamples 287 | self.entityHandler = entityHandler 288 | self.substituteAllEntitiesInAllTrainingExamples() 289 | self.intentSamplesAugment() 290 | 291 | self.trained = False 292 | self.createAllTrainedIntents() 293 | 294 | 295 | def intentSamplesAugment(self): 296 | """ 297 | 298 | Function to augment intent samples ,making sure each intent is at least 100 samples long 299 | 300 | 301 | """ 302 | 303 | for key in self.allIntentExamples: 304 | while len(self.allIntentExamples[key]) < 100: 305 | self.allIntentExamples[key].extend(self.allIntentExamples[key]) 306 | 307 | 308 | def substituteAllEntitiesInAllTrainingExamples(self): 309 | 310 | """ 311 | 312 | For certain types of classifiers it is helpful to have entities substituted 313 | Whenever a new intent is trained , all the entitiy values in the message texts get replaced by the entity kind values. 314 | This is to help training the intents . Note that you can define certain entities to help increase the accuracy of intent 315 | 316 | 317 | """ 318 | 319 | allIntentExamplesSubstituted = {} 320 | allIntentExamplesCopy = copy.deepcopy(self.allIntentExamples) 321 | 322 | for key in allIntentExamplesCopy: 323 | dum = [] 324 | for mes in allIntentExamplesCopy[key]: 325 | dum.append(self.entityHandler.substituteAllEntities(" {0} ".format(mes))) 326 | 327 | allIntentExamplesSubstituted[key] = dum 328 | 329 | self.allIntentExamples = allIntentExamplesSubstituted 330 | 331 | def createAllTrainedIntents(self): 332 | """ 333 | Creates trained intents and sets self.trained 334 | 335 | """ 336 | 337 | allIntentExamplesCopy = copy.deepcopy(self.allIntentExamples) 338 | 339 | trainedIntentArray = [] 340 | intentNames = list(allIntentExamplesCopy.keys()) 341 | intentNames.sort() 342 | #trainedIntentArray.append(MultinomialNBIntent(intentName=intentNames[0],allIntentExamples=self.allIntentExamples,entityHandler=self.entityHandler)) 343 | #vocab = trainedIntentArray[0].vocab 344 | 345 | for intentName in intentNames: 346 | # 347 | # allIntentExamplesCopy = copy.deepcopy(self.allIntentExamples) 348 | # 349 | trainedIntentArray.append( 350 | MultinomialNBIntent(intentName=intentName,allIntentExamples=self.allIntentExamples,entityHandler=self.entityHandler,vocab=None) 351 | 352 | ) 353 | self.trainedIntentArray =trainedIntentArray 354 | self.trained=True 355 | 356 | 357 | 358 | def getMessageIntents(self, message,dialogNumber=0): 359 | """ 360 | Get message intents for a given dialog number 361 | :param message: Message Text 362 | :param dialogNumber: The current dialog number 363 | :return: 364 | list of [{ 365 | "name": classifier name 366 | "confidence": Classifier confidence 367 | "dialogNumber": Current dialog number 368 | "rank": Classifier rank 369 | }] 370 | """ 371 | 372 | if self.entityHandler: 373 | # substitute message entities if they are available 374 | message = self.entityHandler.substituteAllEntities(message) 375 | 376 | if self.trained: 377 | allIntents = sorted([trainedIntent.getIntentProbability(message) for trainedIntent in self.trainedIntentArray], 378 | key=lambda x: x["confidence"], reverse=True) 379 | 380 | allIntentsDialogCounterUpdated=[] 381 | rank=1 382 | for elem in allIntents: 383 | elem["dialogNumber"]=dialogNumber 384 | elem["rank"]=rank 385 | allIntentsDialogCounterUpdated.append(elem) 386 | rank+=1 387 | 388 | return allIntentsDialogCounterUpdated 389 | else: 390 | return "model not trained" 391 | 392 | 393 | 394 | -------------------------------------------------------------------------------- /sampleBots/TakeOrderBotV1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Take Order Bot" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 2, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "from simbots.Bot import SubConversation\n", 17 | "\n", 18 | "\n", 19 | "## \n", 20 | "## Sub Conversation Functions\n", 21 | "##\n", 22 | "\n", 23 | "def enterTakeOrder(contextManager):\n", 24 | " \n", 25 | " # Will enter this loop if intent is order food\n", 26 | " \n", 27 | " currentIntentName = contextManager.findCurrentTopIntent()['name']\n", 28 | " \n", 29 | " return currentIntentName == \"OrderFood\"\n", 30 | "\n", 31 | "def exitTakeOrder(contextManager):\n", 32 | " \n", 33 | " # Will exit loop if intent is Discard\n", 34 | " \n", 35 | " currentIntentName = contextManager.findCurrentTopIntent()['name']\n", 36 | " \n", 37 | " return currentIntentName == \"Discard\"\n", 38 | "\n", 39 | "\n", 40 | "def checkIfPresentInSessionVariables(entityKind,sessionVariables):\n", 41 | " \n", 42 | " entityKindPresent = entityKind in sessionVariables.keys()\n", 43 | " \n", 44 | " entityValue = sessionVariables.get(entityKind, \"\") \n", 45 | " \n", 46 | " return entityKindPresent,entityValue\n", 47 | " \n", 48 | "\n", 49 | "\n", 50 | "def enterLogicTakeOrder(contextManager,outputs = None):\n", 51 | " \n", 52 | " if outputs is None:\n", 53 | " outputs = []\n", 54 | " \n", 55 | " # Get Already Existing Entities\n", 56 | " \n", 57 | " if \"sessionVariables\" in contextManager.context.keys():\n", 58 | " sessionVariables = contextManager.context[\"sessionVariables\"]\n", 59 | " else:\n", 60 | " sessionVariables={}\n", 61 | " \n", 62 | " currentEntities = [entity for entity in contextManager.findCurrentEntities() if \"Food\" in entity[\"kind\"]]\n", 63 | " \n", 64 | " # Update entites in context \n", 65 | " \n", 66 | " for entity in currentEntities:\n", 67 | " \n", 68 | " sessionVariables[entity[\"kind\"]] = entity[\"value\"]\n", 69 | " \n", 70 | " contextManager.context[\"sessionVariables\"] = sessionVariables\n", 71 | " \n", 72 | " contextManager.updateContextTree()\n", 73 | " \n", 74 | " \n", 75 | " # Formulate reply\n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " foodTypePresent,foodType = checkIfPresentInSessionVariables(\"FoodType\",sessionVariables)\n", 80 | " foodSizePresent,foodSize = checkIfPresentInSessionVariables(\"FoodSize\",sessionVariables)\n", 81 | " foodNamePresent,foodName = checkIfPresentInSessionVariables(\"FoodName\",sessionVariables)\n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " if foodNamePresent and foodTypePresent and foodSizePresent :\n", 86 | " stayInSubConversation = False\n", 87 | " \n", 88 | " contextManager.context[\"sessionVariables\"] = {}\n", 89 | " contextManager.updateContextTree()\n", 90 | " foodType = foodType.replace(\"pizza\",\"\").replace(\"burger\",\"\")\n", 91 | " \n", 92 | " # Write function to save context variables here\n", 93 | " \n", 94 | " outputs.append({'tag': 'OrderFood.basic', 'data': [foodName,foodSize,foodType]})\n", 95 | " \n", 96 | " else:\n", 97 | " stayInSubConversation = True\n", 98 | " outputs.append({'tag': 'OrderFood.missing', 'data': [foodName,foodSize,foodType]})\n", 99 | " \n", 100 | " return stayInSubConversation, contextManager, outputs\n", 101 | "\n", 102 | "\n", 103 | "\n", 104 | "\n", 105 | "def enterAllElse(contextManager):\n", 106 | " \n", 107 | " currentIntentName = contextManager.findCurrentTopIntent()['name']\n", 108 | " return currentIntentName != \"OrderFood\"\n", 109 | "\n", 110 | "def enterLogicAllElse(contextManager,outputs =None):\n", 111 | " \n", 112 | " if outputs is None:\n", 113 | " outputs = []\n", 114 | " \n", 115 | " intentName = contextManager.findCurrentTopIntent()['name']\n", 116 | " \n", 117 | " reply = {'tag': '{0}.basic'.format(intentName), 'data': None}\n", 118 | "\n", 119 | " outputs.append(reply)\n", 120 | " \n", 121 | " stayInSubConversation = False\n", 122 | " \n", 123 | " return stayInSubConversation, contextManager, outputs\n", 124 | " \n", 125 | "\n", 126 | "subConversation1 = SubConversation(\n", 127 | " name = \"allElse\" ,\n", 128 | " enter = enterAllElse,\n", 129 | " onEnterLogic = enterLogicAllElse\n", 130 | ")\n", 131 | "\n", 132 | " \n", 133 | "subConversation2 = SubConversation(name=\"TakingOrder\",\n", 134 | " enter = enterTakeOrder,\n", 135 | " exit = exitTakeOrder,\n", 136 | " onEnterLogic = enterLogicTakeOrder,\n", 137 | " \n", 138 | " )\n", 139 | "\n", 140 | "\n", 141 | "\n", 142 | " \n", 143 | "subConversations =[\n", 144 | " subConversation1,\n", 145 | " subConversation2,\n", 146 | " \n", 147 | " \n", 148 | "]\n" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": 3, 154 | "metadata": {}, 155 | "outputs": [ 156 | { 157 | "name": "stdout", 158 | "output_type": "stream", 159 | "text": [ 160 | "Type in @@ to exit bot\n", 161 | "@i to get intents\n", 162 | "@c to get context \n", 163 | "@e to get entities\n", 164 | "@t to add a test case\n", 165 | "@etc to evaluate a test case\n", 166 | "@eatc to evaluate all test cases\n", 167 | "@ti to add intent\n", 168 | "<1> User : hi\n", 169 | "<1> themeBasicBot : Hi there ! what can I do for you ?\n", 170 | "<2> User : what can you do ?\n", 171 | "<2> themeBasicBot : I am learning to make basic conversation ! Im taking orders if you want something to eat ! \n", 172 | "<3> User : sure get me a pizza\n", 173 | "<3> themeBasicBot : Just need a few more details to complete your order : \n", 174 | " 1) Name : pizza\n", 175 | " 2) Size : \n", 176 | " 3) Type : \n", 177 | "<4> User : oh i forgot to ask your name , what is it ?\n", 178 | "<4> themeBasicBot : You can call me riko\n", 179 | "Just need a few more details to complete your order : \n", 180 | " 1) Name : pizza\n", 181 | " 2) Size : \n", 182 | " 3) Type : \n", 183 | "<5> User : umm i changed my mind on the pizza\n", 184 | "<5> themeBasicBot : Im cancelling your order\n", 185 | "<6> User : show me wats else is on the menu ?\n", 186 | "<6> themeBasicBot : We currently serve \n", 187 | " 1) Pizza [cheese and corn , Margherita ] \n", 188 | " 2) Burger [Alu tikki , Bean] \n", 189 | "<7> User : thats cool , get me a bean burger\n", 190 | "<7> themeBasicBot : Just need a few more details to complete your order : \n", 191 | " 1) Name : burger\n", 192 | " 2) Size : \n", 193 | " 3) Type : burgerBean\n", 194 | "<8> User : make it a small one .. im dieting\n", 195 | "<8> themeBasicBot : Thanks for placing your order . Your order is :\n", 196 | " 1) Name : burger\n", 197 | " 2) Size : small\n", 198 | " 3) Type : Bean\n", 199 | "\n", 200 | "<9> User : bye\n", 201 | "<9> themeBasicBot : Bye ! nice chatting with you !\n", 202 | "<10> User : thanks for being so awesome !\n", 203 | "<10> themeBasicBot : So nice of you to say that !\n", 204 | "<11> User : bye again\n", 205 | "<11> themeBasicBot : Bye ! nice chatting with you !\n", 206 | "<12> User : @@\n" 207 | ] 208 | } 209 | ], 210 | "source": [ 211 | "from simbots.Bot import Bot\n", 212 | "from simbots.utils.builtInIntents import IntentSamples\n", 213 | "from simbots.utils.builtInEntities import EntitySamples\n", 214 | "import json\n", 215 | "\n", 216 | "\n", 217 | "\n", 218 | "intentExamples = {\n", 219 | " 'Greetings': IntentSamples.greetingSamples(),\n", 220 | " 'BotName': IntentSamples.botNameSamples(),\n", 221 | " 'Relatives': IntentSamples.relativeSamples(),\n", 222 | " 'Age': IntentSamples.ageSamples(),\n", 223 | " 'BirthPlace': IntentSamples.birthPlaceSamples(),\n", 224 | " 'Abilities': IntentSamples.abilitiesSamples()+[\"tell me what can you do ?\"],\n", 225 | " 'Really': IntentSamples.reallySamples(),\n", 226 | " 'Laughter': IntentSamples.laughterSamples(),\n", 227 | " 'Cool': IntentSamples.coolSamples(),\n", 228 | " 'Praise': IntentSamples.praiseSamples(),\n", 229 | " 'TrueT': IntentSamples.trueSamples(),\n", 230 | " 'FalseT': IntentSamples.falseSamples(),\n", 231 | " 'Bye': IntentSamples.byeSamples(),\n", 232 | " 'Confirm': IntentSamples.confirmSamples(),\n", 233 | " 'Thanks': IntentSamples.thanksSamples(),\n", 234 | " 'Discard': IntentSamples.discardSamples()+[\n", 235 | " 'No',\n", 236 | " 'No , i dont wanna do that',\n", 237 | " 'Nope change that',\n", 238 | " ' negative ',\n", 239 | " 'No no',\n", 240 | " 'I said no',\n", 241 | " 'Never',\n", 242 | " 'Cancel that',\n", 243 | " 'Build a new one',\n", 244 | " 'cancel ',\n", 245 | " \"i do not want to do that\",\n", 246 | " \"i changed my mind\",\n", 247 | " \"i have had a change of heart\",\n", 248 | " \"i think i want to cancel\",\n", 249 | " \"please dont\",\n", 250 | " \"please do not do that\"\n", 251 | " ],\n", 252 | " \"Menu\":[\"whats on the menu ?\",\"what is on the menu ?\",\"could you tell me What is on the Menu ?\",\"What are you serving ?\",\n", 253 | " \"What do you serve ? \", \" what do you serve ? \",\"What do you currently Serve ?\",\"Id like to know whats on the Menu ?\",\n", 254 | " \"what do you have ?\"\n", 255 | " ],\n", 256 | "\n", 257 | " \"OrderFood\":[\"I want to order a piiza\",\"can you get me a burger ?\",\"need something to eat \",\"im hungry !\",\"I am starving\",\n", 258 | " \"please get me something to eat \",\"my stomach is empty\",\"can you please take my order\",\"i want to order food\",\n", 259 | " \"can you get me a bean burger ?\",\"need a bean burger \",\"i want a burger\",\"i am ordering food\",\"just put in a medium one\",\n", 260 | " \"okay ill go with medium one\"\n", 261 | " \n", 262 | " ],\n", 263 | " 'Irrelevant': ['the weather is fine today','the sun rises in the east','the quick brown fox jumps over the red carpet',\n", 264 | " 'the sun rises in the east',\n", 265 | " 'What is love , baby dont hurt me ',\n", 266 | " 'this is a new dawn a new day'],\n", 267 | "}\n", 268 | "\n", 269 | "entityExamples = {\n", 270 | " 'GreetingsHelper': EntitySamples.greetingsHelper(),\n", 271 | " 'LaughterHelper': EntitySamples.laughterHelper(),\n", 272 | " 'CoolHelper': EntitySamples.coolHelper(),\n", 273 | " 'ByeHelper': EntitySamples.byeHelper(),\n", 274 | " \"FoodName\": { \n", 275 | " 'pizza' : [{'tag': 'case-insensitive','pattern': 'p+i+[z|j]+a+','type': 'regex'}],\n", 276 | " 'burger': [{'tag': 'case-insensitive','pattern': 'b+u+r+g+e+r','type': 'regex'}],\n", 277 | " },\n", 278 | " \"FoodSize\":{\n", 279 | " 'small' : [{'tag': 'case-insensitive','pattern': 'small','type': 'regex'}],\n", 280 | " 'large': [{'tag': 'case-insensitive','pattern': 'large','type': 'regex'}],\n", 281 | " \"medium\": [{'tag': 'case-insensitive','pattern': 'medium','type': 'regex'}]\n", 282 | " \n", 283 | " },\n", 284 | " \"FoodType\":{\n", 285 | " 'pizzaMargherita' : [{'tag': 'case-insensitive','pattern': 'margherita','type': 'regex'}],\n", 286 | " 'pizzaCheeseAndCorn': [{'tag': 'case-insensitive','pattern': '(cheese\\s+and\\s+corn)|(corn\\s+and\\s+cheese)','type': 'regex'}],\n", 287 | " \"burgerAluTikki\": [{'tag': 'case-insensitive','pattern': 'a+l+(u|o)+ tikki','type': 'regex'}],\n", 288 | " \"burgerBean\": [{'tag': 'case-insensitive','pattern': 'bean','type': 'regex'}]\n", 289 | " \n", 290 | " }\n", 291 | " \n", 292 | "}\n", 293 | "\n", 294 | "botMessages = {'themeBasic': {\n", 295 | " 'Greetings': {'basic': ['Hello ! What can i do for you ?',\n", 296 | " 'Hi there ! what can I do for you ?', 'Hello']},\n", 297 | " 'Age': {'basic': ['I am two years old ', 'I am two']},\n", 298 | " 'BotName': {'basic': ['I am riko', 'You can call me riko']},\n", 299 | " 'Abilities': {'basic': ['I am learning to make basic conversation ! Im taking orders if you want something to eat ! '\n", 300 | " ]},\n", 301 | " 'Menu':{ 'basic':[\"We currently serve \\n 1) Pizza [cheese and corn , Margherita ] \\n 2) Burger [Alu tikki , Bean] \"]\n", 302 | " \n", 303 | " },\n", 304 | " \n", 305 | " 'BirthPlace': {'basic': ['I am from India', 'I am an Indian'\n", 306 | " , 'I am punjabi and i love food']},\n", 307 | " 'Really': {'basic': ['To the best of my knowledge', 'Im positive !'\n", 308 | " ]},\n", 309 | " 'Laughter': {'basic': ['Im glad i was able to make you smile !',\n", 310 | " 'See I can be funny !',\n", 311 | " 'And they say I dont have a sense of humor :)']},\n", 312 | " 'Cool': {'basic': ['cool', 'thanks']},\n", 313 | " 'Bye': {'basic': ['Bubye !', 'Bye ! nice chatting with you !']},\n", 314 | " 'Confirm': {'basic': ['okay ']},\n", 315 | " 'Discard': {'basic': ['Im cancelling your order']},\n", 316 | " 'TrueT': {'basic': ['I know right', 'that makes me ']},\n", 317 | " 'FalseT': {'basic': ['Im still learning ... I sometimes make mistakes '\n", 318 | " ]},\n", 319 | " 'Praise': {'basic': ['Thanks ! now i think ill blush ',\n", 320 | " 'So nice of you to say that !']},\n", 321 | " 'Relatives': {'basic': ['Umm no i dont really have any relatives :)'\n", 322 | " ]},\n", 323 | " 'Thanks': {'basic': ['Dont mention it ',\n", 324 | " ' Im glad , please dont mention it']},\n", 325 | " \n", 326 | " \"OrderFood\":{\"basic\": [\"Thanks for placing your order . Your order is :\\n 1) Name : {0}\\n 2) Size : {1}\\n 3) Type : {2}\\n\"],\n", 327 | " \"missing\":[\"Just need a few more details to complete your order : \\n 1) Name : {0}\\n 2) Size : {1}\\n 3) Type : {2}\"],\n", 328 | " \n", 329 | "\n", 330 | " },\n", 331 | " 'Irrelevant': {'basic': ['Im sorry Im not getting you :( ',\n", 332 | " 'Im sorry could you please rephrase ?']},\n", 333 | "}\n", 334 | " }\n", 335 | "\n", 336 | "\n", 337 | "class NewBot(Bot):\n", 338 | "\n", 339 | " def reason(self):\n", 340 | " \n", 341 | " outputs = []\n", 342 | " # If user has asked any of the other questions except placing order execute this\n", 343 | " if self.subConversations[0].enterOn(self.contextManager):\n", 344 | " self.contextManager,outputs = self.subConversations[0].execute(self.contextManager,outputs)\n", 345 | " \n", 346 | " # If user was in the process of making an order execute this\n", 347 | " if self.subConversations[1].isHappening or self.subConversations[1].enterOn(self.contextManager):\n", 348 | " self.contextManager,outputs = self.subConversations[1].execute(self.contextManager,outputs)\n", 349 | " \n", 350 | "\n", 351 | " return outputs\n", 352 | "\n", 353 | "\n", 354 | "newB = NewBot(intentExamples, entityExamples, botMessages,\n", 355 | " confidenceLimit=0,subConversations=subConversations)\n", 356 | "\n", 357 | "outputTheme = 'themeBasic'\n", 358 | "newB.run(theme = outputTheme)" 359 | ] 360 | }, 361 | { 362 | "cell_type": "code", 363 | "execution_count": null, 364 | "metadata": {}, 365 | "outputs": [], 366 | "source": [] 367 | } 368 | ], 369 | "metadata": { 370 | "kernelspec": { 371 | "display_name": "condagpu", 372 | "language": "python", 373 | "name": "condagpu" 374 | }, 375 | "language_info": { 376 | "codemirror_mode": { 377 | "name": "ipython", 378 | "version": 3 379 | }, 380 | "file_extension": ".py", 381 | "mimetype": "text/x-python", 382 | "name": "python", 383 | "nbconvert_exporter": "python", 384 | "pygments_lexer": "ipython3", 385 | "version": "3.7.7" 386 | } 387 | }, 388 | "nbformat": 4, 389 | "nbformat_minor": 4 390 | } 391 | -------------------------------------------------------------------------------- /simbots/simbots/Entity.py: -------------------------------------------------------------------------------- 1 | #from examples import entities as entitiesExtractorJson 2 | import re 3 | import json 4 | from .utils.exceptions import SchemaException 5 | 6 | class EntitiesHandler(): 7 | """ 8 | This class is responsible for handling entities within the bot 9 | The init method for the EntitiesHandler Class 10 | :param entitiesExtractorJson: this is a json which specifies the type of entities and their definitions . Note currently no schema checks have been implemented . 11 | 12 | **Sample Json accepted** 13 | 14 | .. code-block:: json 15 | 16 | { 17 | "GreetingsHelper":{ 18 | "wsup" : [{ 19 | "tag":"case-insensitive", 20 | "pattern":"\s[w]*[a]*[s]+[u]+[p]+\s", 21 | "type":"regex" 22 | } 23 | ], 24 | "hi":[ 25 | { 26 | "tag":"case-insensitive", 27 | "pattern":"\s[h]+[i]+\s", 28 | "type":"regex" 29 | 30 | 31 | } 32 | 33 | ], 34 | "hello":[ 35 | { 36 | "tag":"case-insensitive", 37 | "pattern":"\s[h]+[e]+[l]+[o]+\s", 38 | "type":"regex" 39 | 40 | 41 | }, 42 | { 43 | "tag":"case-insensitive", 44 | "extractor":helloExtractorFunc -> 45 | "type":"function" 46 | 47 | } 48 | 49 | ] 50 | 51 | 52 | }, 53 | 54 | "LaughterHelper":{ 55 | 56 | "haha" : [{ 57 | "tag":"case-insensitive", 58 | "pattern":"\s(h+(a|e)+)+(h+)?\s", 59 | "type":"regex" 60 | 61 | 62 | } 63 | ], 64 | "happysmily":[ 65 | { 66 | "tag":"case-insensitive", 67 | "pattern":"\s\:\)\s", 68 | "type":"regex" 69 | 70 | 71 | } 72 | 73 | ], 74 | 75 | }, 76 | "CoolHelper":{ 77 | "cool":[ 78 | { 79 | "tag":"case-insensitive", 80 | "pattern":"\sc+oo+l+\s", 81 | "type":"regex" 82 | 83 | } 84 | 85 | 86 | ] 87 | 88 | 89 | }, 90 | "ByeHelper":{ 91 | "bye":[ 92 | { 93 | "tag":"case-insensitive", 94 | "pattern":"\s(goo+d)?b+y+e+\s", 95 | "type":"regex" 96 | 97 | } 98 | ] 99 | 100 | } 101 | 102 | } 103 | 104 | **kind** : Here GreetingsHelper,LaughterHelper,CoolHelper,ByeHelper are entity kinds. 105 | also "wsup","hi","hello" are entity values assosciated with the entity kind GreetingsHelper 106 | 107 | **type**: Only two types are supported -> regex and function. 108 | 109 | **pattern** : the pattern of the regex, only used if type is regex, 110 | 111 | **extractor**: A function that extracts the given entity from the message text should be present if type is function, 112 | 113 | Note that any function used should take in two arguments messageText and dialogNumber and should 114 | return A list of dicts of the format 115 | 116 | .. code-block:: json 117 | 118 | [{ 119 | "value":the value of the entity , for more details look at the sample json., 120 | "exactValue":the exact value that occurs within the message text., 121 | "kind":the kind of the entity eg food in case of pizza., 122 | "dialogNumber":the dialog number of the current message -> same as the input param., 123 | "foundAt":[start location , end location], 124 | 125 | }] 126 | 127 | 128 | **substituter**: A custom substitution function to substitute entity by another value, This function takes in the message text and should 129 | return the substituted message text this should always be present if type is "function". should return substituted message text. 130 | 131 | 132 | """ 133 | 134 | def __init__(self,entitiesExtractorJson=None): 135 | if not entitiesExtractorJson: 136 | entitiesExtractorJson={} 137 | else: 138 | # validate entity schema here 139 | if type(entitiesExtractorJson) != dict: 140 | # check if entity is dict 141 | raise SchemaException("Entities", "Entity samples", 142 | "Entities should be specified as a dict instead got {0} .".format(type(entitiesExtractorJson))) 143 | 144 | for entityName in entitiesExtractorJson.keys(): 145 | entityContent = entitiesExtractorJson[entityName] 146 | if type(entityContent) != dict: 147 | raise SchemaException("Entity", entityName, 148 | "Entities should be specified as a dict instead got {0} .".format( 149 | type(entityContent))) 150 | for entitySynonym in entityContent.keys(): 151 | synonymContent = entityContent[entitySynonym] 152 | if type(synonymContent) != list: 153 | raise SchemaException("Entity","{0} - {1}".format(entityName,entitySynonym),"Should be a list of dicts instead got {0} of {1}".format(synonymContent,type(synonymContent)) 154 | 155 | ) 156 | for i,synonymDefinition in enumerate(synonymContent): 157 | if type(synonymDefinition) != dict: 158 | raise SchemaException("Entity","{0} - {1}- index {2}".format(entityName,entitySynonym,i),"Should be a dict got {0} of {1}".format(synonymDefinition,type(synonymDefinition)) 159 | 160 | ) 161 | for key in synonymDefinition.keys(): 162 | if key == 'tag': 163 | value = synonymDefinition[key] 164 | if value not in ["case-insensitive","case-sensitive"]: 165 | raise SchemaException("Entity","{0} - {1}- index {2}".format(entityName,entitySynonym,i),"allowed 'tag' values in ['case-insensitive','case-sensitive'] got {0}".format(value)) 166 | if key == "type": 167 | value = synonymDefinition[key] 168 | if value not in ["regex", "function"]: 169 | raise SchemaException("Entity", 170 | "{0} - {1}- index {2}".format(entityName, entitySynonym, 171 | i), 172 | "allowed 'type' values in ['regex', 'function'] got {0}".format( 173 | value)) 174 | if key == "pattern": 175 | value = synonymDefinition[key] 176 | if type(value) != str: 177 | raise SchemaException("Entity", 178 | "{0} - {1}- index {2}".format(entityName, entitySynonym, 179 | i), 180 | "pattern should be a regex got {0}".format( 181 | type(value))) 182 | if key =="extractor": 183 | # work more on this 184 | value = synonymDefinition[key] 185 | if not callable(value): 186 | raise SchemaException("Entity", 187 | "{0} - {1}- index {2}".format(entityName, entitySynonym, 188 | i), 189 | "extractor should be a function got {0}".format( 190 | type(value))) 191 | # write extractor text here 192 | 193 | if "tag" not in synonymDefinition.keys(): 194 | raise SchemaException("Entity", 195 | "{0} - {1}- index {2}".format(entityName, entitySynonym, i), 196 | "should have a key called 'tag' ") 197 | if "type" not in synonymDefinition.keys(): 198 | raise SchemaException("Entity", 199 | "{0} - {1}- index {2}".format(entityName, entitySynonym, i), 200 | "should have a key called 'type' ") 201 | 202 | if ("tag" =='regex') and "pattern" not in synonymDefinition.keys(): 203 | raise SchemaException("Entity", 204 | "{0} - {1}- index {2}".format(entityName, entitySynonym, i), 205 | "if 'tag' =='regex' you must add a key called 'pattern' with a regex value ") 206 | 207 | if ("tag" =='function') and "extractor" not in synonymDefinition.keys(): 208 | raise SchemaException("Entity", 209 | "{0} - {1}- index {2}".format(entityName, entitySynonym, i), 210 | "if 'tag' =='function' you must add a key called 'extractor' with a function that extracts the entities and a key called 'substituter' which is a function that substitues the message entities for more details refer documentation -> EntitiesHandler") 211 | 212 | if ("tag" =='function') and "substituter" not in synonymDefinition.keys(): 213 | raise SchemaException("Entity", 214 | "{0} - {1}- index {2}".format(entityName, entitySynonym, i), 215 | "if 'tag' =='function' you must add a key called 'extractor' with a function that extracts the entities and a key called 'substituter' which is a function that substitues the message entities for more details refer documentation -> EntitiesHandler") 216 | 217 | 218 | 219 | 220 | 221 | self.entitiesExtractorJson=entitiesExtractorJson 222 | 223 | 224 | def extractEntitySynonym(self,message,pattern,value,kind,tag,dialogNumber): 225 | """ 226 | This function extracts the entities and synonyms from the text message and returns a json. Currently it does not extract any synonyms 227 | :param message: The text message str eg "I want to buy a pizza" 228 | :param pattern: 229 | :param value: 230 | :param kind: 231 | :param tag: can be "case-insensitive" if we want the extractor to ignore the casing (uppercase or lowercase) of the entity text 232 | :param dialogNumber: the dialog number of the message string. 233 | :return: A list of dicts of the format 234 | 235 | .. code-block:: json 236 | 237 | [{ 238 | "value":the value of the entity , for more details look at the sample json., 239 | "exactValue":the exact value that occurs within the message text., 240 | "kind":the kind of the entity eg : food in case of pizza., 241 | "dialogNumber":the dialog number of the current message -> same as the input param., 242 | "foundAt":[start location , end location], 243 | 244 | }] 245 | """ 246 | 247 | 248 | entitiesFound=[] 249 | if "case-insensitive" in tag: 250 | iter=re.finditer(pattern=pattern,string= message,flags=re.I) 251 | else: 252 | iter = re.finditer(pattern=pattern, string=message) 253 | 254 | for entityDetected in iter: 255 | 256 | exactValue=message[entityDetected.start() : entityDetected.end()] 257 | entitiesFound.append( 258 | { 259 | "value":value, 260 | "exactValue":exactValue.strip(), 261 | "kind":kind, 262 | "dialogNumber":dialogNumber, 263 | "foundAt":[entityDetected.start() , entityDetected.end()], 264 | #"logic":synonymSpecs 265 | 266 | } 267 | ) 268 | return entitiesFound 269 | 270 | 271 | def extractAllEntities(self,message,dialogNumber=0): 272 | """ 273 | This function extracts all entities from the message . 274 | :param message: The message text 275 | :param dialogNumber: the current dialog number 276 | :return: A list of dicts of the format 277 | 278 | .. code-block:: json 279 | 280 | [{ 281 | "value":the value of the entity , for more details look at the sample json., 282 | "exactValue":the exact value that occurs within the message text., 283 | "kind":the kind of the entity eg : food in case of pizza., 284 | "dialogNumber":the dialog number of the current message -> same as the input param., 285 | "foundAt":[start location , end location], 286 | 287 | }] 288 | """ 289 | #message = " {0} ".format(message) 290 | allEntities=[] 291 | for entityKind in self.entitiesExtractorJson.keys(): 292 | for entityValue in self.entitiesExtractorJson[entityKind].keys(): 293 | for synonymSpecs in self.entitiesExtractorJson[entityKind][entityValue]: 294 | if synonymSpecs["type"] == "regex": 295 | tag=synonymSpecs["tag"] 296 | synonymPattern=synonymSpecs["pattern"] 297 | entFound = self.extractEntitySynonym(message,synonymPattern,entityValue,entityKind,tag,dialogNumber) 298 | elif synonymSpecs["type"] == "function": 299 | entFound = synonymSpecs["extractor"](message,dialogNumber) 300 | else: 301 | entFound =[] 302 | 303 | allEntities.extend(entFound) 304 | 305 | 306 | return allEntities 307 | 308 | 309 | 310 | def substituteEntityKind(self,message,pattern,by,tag): 311 | """ 312 | This function substitutes an entity value for its kind in the message text and returns the substituted message text . 313 | Note this function is currently unstable and a better version needs to be written to substitute entities effectively . 314 | :param message: The message text 315 | :param pattern: the entity pattern 316 | :param by: the value to be substituted by eg if we need to substitute the word "equivalent" by "alike" then by ="alike" 317 | or if pizza then it will be kind 318 | :param tag:"case-insensitive" or not 319 | :return: the substituted message text 320 | """ 321 | 322 | #message = " {0} ".format(message) 323 | if "case-insensitive" in tag: 324 | flags=re.I 325 | else: 326 | flags=None 327 | 328 | messageVar = re.sub( pattern , by, message,flags=flags) 329 | 330 | return messageVar 331 | 332 | def substituteAllEntities(self,message): 333 | """ 334 | This function substitutes all entity values with entity kinds 335 | :param message:The message text 336 | :return: substituted message text 337 | """ 338 | #message =" {0} ".format(message) 339 | for entityKind in self.entitiesExtractorJson.keys(): 340 | for entityValue in self.entitiesExtractorJson[entityKind].keys(): 341 | for synonymSpecs in self.entitiesExtractorJson[entityKind][entityValue]: 342 | if synonymSpecs["type"] == "regex": 343 | tag=synonymSpecs["tag"] 344 | synonymPattern=synonymSpecs["pattern"] 345 | message = self.substituteEntityKind(message, synonymPattern, " --!{0} ".format(entityKind), tag) 346 | elif synonymSpecs["type"] == "function": 347 | message = synonymSpecs["substituter"](message) 348 | 349 | 350 | return message 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | --------------------------------------------------------------------------------