├── .gitignore ├── .gitmodules ├── .travis.yml ├── CHANGES ├── CMakeLists.txt ├── CONTRIBUTORS ├── Dockerfile ├── Doxyfile.in ├── LICENSE ├── README.md ├── bindings ├── CMakeLists.txt └── nodejs │ ├── .gitignore │ ├── CMakeLists.txt │ ├── Dockerfile │ ├── README.md │ ├── bin │ ├── open-intent-project.js │ └── open-intent.js │ ├── config │ ├── config.js │ └── default.yaml │ ├── docker │ └── entrypoint.sh │ ├── include │ └── intentjs │ │ └── SerializableChatbot.hpp │ ├── index.js │ ├── lib │ ├── chatbot-api │ │ ├── chatbot-factory.js │ │ ├── chatbot-interface.js │ │ ├── chatbot-with-logger.js │ │ ├── chatbot.js │ │ ├── session-manager │ │ │ ├── redis-driver.js │ │ │ └── standalone-driver.js │ │ └── user-defined-actions │ │ │ └── simple-driver.js │ ├── chatbot-client.js │ ├── chatbot.js │ ├── middleware │ │ ├── README.md │ │ ├── doc-publisher.js │ │ ├── index.js │ │ ├── irc.js │ │ ├── loggers │ │ │ ├── elasticsearch.js │ │ │ └── logger.js │ │ ├── platforms.js │ │ ├── platforms │ │ │ └── controllers │ │ │ │ ├── kik.js │ │ │ │ ├── messenger.js │ │ │ │ ├── skype.js │ │ │ │ ├── slack.js │ │ │ │ └── telegram.js │ │ ├── public_html │ │ │ └── viz.js │ │ ├── rest.js │ │ └── templates │ │ │ └── intent-story.html │ └── project │ │ └── project.js │ ├── package.json │ ├── project-skeletons │ └── chatbot │ │ ├── .gitignore │ │ ├── Aptfile │ │ ├── Procfile │ │ ├── app.js │ │ ├── app │ │ ├── chatbot.js │ │ ├── config.js │ │ └── test │ │ │ ├── helpers.js │ │ │ └── test-chatbot.js │ │ ├── config │ │ ├── general.json │ │ ├── kik │ │ │ └── default.json │ │ ├── loggers │ │ │ ├── elasticsearch.json │ │ │ └── selection.json │ │ ├── messenger │ │ │ └── default.json │ │ ├── selection.json │ │ ├── skype │ │ │ └── default.json │ │ ├── slack │ │ │ └── default.json │ │ └── telegram │ │ │ └── default.json │ │ ├── docker │ │ ├── Dockerfile │ │ └── README.md │ │ ├── heroku_setup │ │ ├── package.json │ │ ├── res │ │ ├── dictionary.json │ │ ├── script.txt │ │ └── user_commands.js │ │ └── test-conversations │ │ ├── do-not-understand-item.txt │ │ ├── make-mistake-during-ordering.txt │ │ ├── order-hamburger.txt │ │ ├── order-pizza.txt │ │ └── order-salad.txt │ ├── src │ ├── SerializableChatbot.cpp │ ├── binding.gyp │ └── main.cpp │ ├── test-integration │ ├── CMakeLists.txt │ ├── Dockerfile │ ├── chatbot │ │ ├── Dockerfile │ │ ├── launch.sh │ │ └── test │ │ │ ├── package.json │ │ │ └── test.js │ ├── elasticsearch-logs │ │ ├── Dockerfile │ │ ├── launch.sh │ │ ├── res │ │ │ ├── dictionary.json │ │ │ ├── script.txt │ │ │ └── user_commands.js │ │ └── test │ │ │ ├── package.json │ │ │ └── test.js │ └── tutorial │ │ ├── Dockerfile │ │ ├── launch.sh │ │ ├── res │ │ ├── dictionary.json │ │ ├── script.txt │ │ └── user_commands.js │ │ └── test │ │ ├── package.json │ │ └── test.js │ └── test │ ├── bad-food-bot-model.js │ ├── chatbot-api │ ├── res │ │ ├── bad_interpreter_model.txt │ │ ├── chatbot.json │ │ ├── food_bot │ │ │ ├── bad_script.txt │ │ │ ├── dictionary.json │ │ │ ├── script.txt │ │ │ └── user_commands.js │ │ ├── interpreter_model.txt │ │ └── userCommands.js │ ├── test-chatbot-factory.js │ ├── test-chatbot-interface.js │ ├── test-chatbot.js │ ├── test-simpledriver.js │ ├── test-standalone-session-manager.js │ └── user-commands.js │ ├── food-bot-model.js │ ├── middleware │ ├── test-doc-publisher.expected.html │ ├── test-doc-publisher.js │ ├── test-irc.js │ ├── test-platforms.js │ └── test-rest.js │ ├── project-skeletons │ └── chatbot │ │ └── test-chatbot.js │ ├── project │ └── test-project.js │ ├── res │ └── food_bot │ │ ├── bad_script.txt │ │ ├── dictionary.json │ │ ├── script.txt │ │ └── user_commands.js │ ├── rest-client │ └── test-rest-client.js │ └── test-chatbot.js ├── cmake ├── CodeCoverage.cmake └── Custom.cmake ├── doc └── img │ ├── create_fb_app.png │ ├── create_fb_page.png │ ├── facebook.png │ ├── fb_app.png │ ├── fb_menu.png │ ├── logo.png │ ├── logo_128.png │ ├── ngrok.png │ ├── page_access_token.png │ └── subscribe_webhook.png ├── examples ├── BeerBar │ ├── BeerBar.cpp │ ├── BeerBar.hpp │ ├── CMakeLists.txt │ ├── chatbot.json │ ├── main.cpp │ └── test │ │ ├── BeerBarTest.cpp │ │ └── CMakeLists.txt ├── CMakeLists.txt ├── Domotic │ ├── CMakeLists.txt │ ├── Domotic.cpp │ ├── Domotic.hpp │ ├── intent.json │ ├── main.cpp │ └── test │ │ ├── CMakeLists.txt │ │ └── DomoticTest.cpp ├── IntentViz │ ├── CMakeLists.txt │ ├── chatbot.json │ └── main.cpp └── QueriesBar │ ├── CMakeLists.txt │ ├── chatbot.json │ └── main.cpp ├── include └── intent │ ├── OpenIntent.hpp │ ├── chatbot │ ├── Chatbot.hpp │ ├── ChatbotActionModel.hpp │ ├── ChatbotFactory.hpp │ ├── ChatbotFactory.inl.hpp │ ├── ChatbotModel.hpp │ ├── MultiSessionChatbot.hpp │ ├── MultiSessionChatbot.inl.hpp │ └── SingleSessionChatbot.hpp │ ├── intent_service │ ├── DictionaryModel.hpp │ ├── EntitiesMatcher.hpp │ ├── IntentEncoder.hpp │ ├── IntentMatcher.hpp │ ├── IntentModel.hpp │ ├── IntentService.hpp │ ├── IntentServiceModel.hpp │ ├── SentenceTokenizer.hpp │ ├── Term.hpp │ └── TermIndex.hpp │ ├── intent_story_service │ ├── IntentStoryModel.hpp │ ├── IntentStoryModelSerializer.hpp │ ├── IntentStoryService.hpp │ └── IntentStoryServiceModel.hpp │ ├── interpreter │ ├── EdgeParser.hpp │ ├── Interpreter.hpp │ ├── InterpreterException.hpp │ ├── LineTagger.hpp │ ├── ReplyTemplateInterpreter.hpp │ ├── ScenarioIndexer.hpp │ ├── ScenarioTrimmer.hpp │ └── SentenceToIntentTranslator.hpp │ └── utils │ ├── Deserializer.hpp │ ├── Exception.hpp │ ├── Graph.hpp │ ├── Graph.inl.hpp │ ├── Levenshtein.hpp │ ├── Logger.hpp │ ├── RegexMatcher.hpp │ ├── SingleCharacterDelimiterTokenizer.hpp │ ├── Tokenizer.hpp │ └── TrigramHelper.hpp ├── scripts ├── apply_format.sh ├── apply_format_and_license.sh ├── apply_license.sh ├── build_and_test.sh ├── build_and_test_with_docker.sh ├── deploy_npm.sh ├── remove_old.sh ├── run_tests.sh └── test_license.sh ├── src ├── CMakeLists.txt ├── chatbot │ ├── Chatbot.cpp │ ├── ChatbotFactory.cpp │ └── SingleSessionChatbot.cpp ├── intent_service │ ├── DictionaryModel.cpp │ ├── EntitiesMatcher.cpp │ ├── IntentEncoder.cpp │ ├── IntentMatcher.cpp │ ├── IntentModel.cpp │ ├── IntentService.cpp │ ├── SentenceTokenizer.cpp │ ├── Term.cpp │ └── TermIndex.cpp ├── intent_story_service │ ├── IntentStoryModelSerializer.cpp │ └── IntentStoryService.cpp ├── interpreter │ ├── EdgeParser.cpp │ ├── Interpreter.cpp │ ├── LineTagger.cpp │ ├── ReplyTemplateInterpreter.cpp │ ├── ScenarioIndexer.cpp │ ├── ScenarioTrimmer.cpp │ └── SentenceToIntentTranslator.cpp └── utils │ ├── Deserializer.cpp │ ├── Levenshtein.cpp │ ├── Logger.cpp │ ├── RegexMatcher.cpp │ ├── SingleCharacterDelimiterTokenizer.cpp │ ├── Tokenizer.cpp │ └── TrigramHelper.cpp ├── test ├── CMakeLists.txt ├── ChatbotFactoryTest.cpp ├── ChatbotTest.cpp ├── DeserializerTest.cpp ├── EntitiesMatcherTest.cpp ├── GraphTest.cpp ├── IntentMatcherTest.cpp ├── IntentServiceTest.cpp ├── IntentStoryModelSerializer.cpp ├── IntentStoryServiceTest.cpp ├── InterpreterTest.cpp ├── MultiSessionChatbotTest.cpp ├── SingleCharacterDelimiterTokenizerTest.cpp ├── SingleSessionChatbotTest.cpp ├── TermIndexTest.cpp ├── TokenizerTest.cpp ├── TrigramUtilsTest.cpp ├── launcher │ ├── ResourceManager.cpp │ ├── ResourceManager.hpp │ ├── TestContext.cpp │ ├── TestContext.hpp │ └── main.cpp ├── mock │ └── ChatbotMock.hpp ├── res │ ├── chatbot_model.json │ ├── chatbot_model_without_intent_story.json │ ├── intent_dictionary_deserialization_invalid_test.json │ ├── intent_dictionary_deserialization_test.json │ ├── interpreter_model.txt │ ├── interpreter_model_w_errors.txt │ ├── order_beverage_intent.json │ ├── queries_model.json │ └── template_replies.json └── same_successive_intents │ ├── SameSuccessiveIntentsTest.cpp │ └── res │ ├── dictionary.json │ ├── script.txt │ └── user_commands.js └── thirdparty └── CMakeLists.txt /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .idea/ 3 | build-dir/ 4 | build/ 5 | 6 | node_modules/ 7 | 8 | node_modules/ 9 | 10 | *.old 11 | *.user 12 | 13 | *.vscode 14 | 15 | npm-debug.log 16 | 17 | *.node 18 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "thirdparty/googletest"] 2 | path = thirdparty/googletest 3 | url = https://github.com/google/googletest.git 4 | [submodule "thirdparty/json"] 5 | path = thirdparty/json 6 | url = https://github.com/nlohmann/json.git 7 | [submodule "thirdparty/spdlog"] 8 | path = thirdparty/spdlog 9 | url = https://github.com/gabime/spdlog.git 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | services: 4 | - docker 5 | 6 | before_install: 7 | - docker build -t open-intent-build . 8 | 9 | script: 10 | - docker create --name open-intent-source-volume -v $(pwd):/src ubuntu:xenial /bin/false 11 | - docker run --rm --volumes-from open-intent-source-volume -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker open-intent-build /src/scripts/build_and_test.sh 12 | 13 | notifications: 14 | email: 15 | recipients: 16 | - clement.michaud34@gmail.com 17 | - sergei.kireev@hotmail.fr 18 | on_success: change 19 | on_failure: always 20 | -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | Changes for 1.0.0: 2 | 3 | * Initial Open Source release of open-intent 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | PROJECT(intent) 4 | 5 | set(VERSION "1.0.0") 6 | 7 | include(CheckCXXCompilerFlag) 8 | CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) 9 | CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) 10 | if(COMPILER_SUPPORTS_CXX11) 11 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-reorder") 12 | elseif(COMPILER_SUPPORTS_CXX0X) 13 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wno-reorder") 14 | else() 15 | message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") 16 | endif() 17 | 18 | set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) 19 | include(Custom) 20 | 21 | 22 | option(BINDINGS_ENABLED "Builds the bindings" ON) 23 | option(GCOV_ENABLED "Enable gcov for test coverage" OFF) 24 | 25 | ADD_SUBDIRECTORY(bindings) 26 | 27 | ADD_SUBDIRECTORY(examples) 28 | ADD_SUBDIRECTORY(src) 29 | ADD_SUBDIRECTORY(test) 30 | ADD_SUBDIRECTORY(thirdparty) 31 | 32 | 33 | find_package(Doxygen) 34 | if(DOXYGEN_FOUND) 35 | configure_file(Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) 36 | add_custom_target(doxygen 37 | ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile 38 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 39 | COMMENT "Generating API documentation with Doxygen" VERBATIM 40 | ) 41 | add_custom_command(TARGET doxygen POST_BUILD 42 | COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan 43 | "Open file://${CMAKE_CURRENT_BINARY_DIR}/html/index.html") 44 | endif(DOXYGEN_FOUND) 45 | 46 | 47 | 48 | 49 | ADD_CUSTOM_TARGET(run-all-tests 50 | DEPENDS run-unit-tests run-integration-tests 51 | ) 52 | ADD_CUSTOM_TARGET(run-unit-tests 53 | DEPENDS run-unit-tests-cpp run-unit-tests-js) 54 | 55 | ADD_CUSTOM_TARGET(run-integration-tests 56 | DEPENDS run-integration-tests-cpp run-integration-tests-js) 57 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | This file contains a list of people who've made non-trivial 2 | contribution to the OpenIntent Framework project. People 3 | who commit code to the project are encouraged to add their names 4 | here. Please keep the list sorted by first names 5 | 6 | Clement Michaud 7 | Sergei Kireev -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | 3 | RUN apt-get update && \ 4 | apt-get install -y libboost-system1.58-dev \ 5 | libboost-thread1.58-dev libboost-filesystem1.58-dev \ 6 | cmake g++ git \ 7 | doxygen node-gyp nodejs npm clang-format-3.7 8 | 9 | RUN apt-get install -y libltdl7 10 | 11 | VOLUME /src 12 | WORKDIR /src 13 | 14 | RUN ln -s /usr/bin/nodejs /usr/bin/node 15 | 16 | 17 | -------------------------------------------------------------------------------- /Doxyfile.in: -------------------------------------------------------------------------------- 1 | 2 | PROJECT_NAME = "OpenIntent" 3 | 4 | PROJECT_BRIEF = "The first open source user intent matching natural language processing framework." 5 | 6 | DOXYFILE_ENCODING = UTF-8 7 | 8 | PROJECT_NUMBER = @VERSION@ 9 | 10 | RECURSIVE = YES 11 | 12 | INPUT = @CMAKE_SOURCE_DIR@/src \ 13 | @CMAKE_SOURCE_DIR@/include 14 | 15 | OUTPUT_LANGUAGE = English 16 | 17 | SHOW_INCLUDE_FILES = YES 18 | 19 | WARN_IF_UNDOCUMENTED = YES 20 | 21 | GENERATE_TREEVIEW = YES 22 | 23 | FULL_PATH_NAMES = YES 24 | 25 | STRIP_FROM_PATH = @CMAKE_SOURCE_DIR@/include -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /bindings/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | ADD_SUBDIRECTORY(nodejs) -------------------------------------------------------------------------------- /bindings/nodejs/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | node_modules/ 3 | 4 | # IDE files 5 | .idea 6 | 7 | # Logs 8 | logs 9 | *.log 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | 16 | # Directory for instrumented libs generated by jscoverage/JSCover 17 | lib-cov 18 | 19 | # Coverage directory used by tools like istanbul 20 | coverage 21 | 22 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 23 | .grunt 24 | 25 | # Compiled binary addons (http://nodejs.org/api/addons.html) 26 | src/build 27 | 28 | # Dependency directory 29 | # Commenting this out is preferred by some people, see 30 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 31 | node_modules 32 | 33 | # Users Environment Variables 34 | .lock-wscript 35 | 36 | # Runtime configuration for swagger app 37 | ../config/runtime.yaml 38 | 39 | open-intent.tgz 40 | -------------------------------------------------------------------------------- /bindings/nodejs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | 4 | ADD_CUSTOM_TARGET(open-intent-js 5 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/chatbot-api/open-intent.node ${JS_SOURCE_FILES} 6 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 7 | ) 8 | 9 | SET(SOURCE_FILES 10 | ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp 11 | ${CMAKE_CURRENT_SOURCE_DIR}/src/SerializableChatbot.cpp 12 | ${CMAKE_CURRENT_SOURCE_DIR}/include/intentjs/SerializableChatbot.hpp 13 | ) 14 | 15 | file(GLOB_RECURSE JS_SOURCE_FILES LIST_DIRECTORIES false bin/* config/* 16 | lib/* project-skeletons/* test/* test-integration/* index.js package.json) 17 | 18 | ADD_CUSTOM_COMMAND( 19 | OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/open-intent.tgz 20 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/chatbot-api/open-intent.node ${JS_SOURCE_FILES} 21 | COMMAND echo "Packaging nodejs" 22 | COMMAND rm -f open-intent-*.tgz 23 | COMMAND npm pack 24 | COMMAND mv open-intent-*.tgz open-intent.tgz 25 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 26 | ) 27 | 28 | ADD_CUSTOM_COMMAND( 29 | OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/lib/chatbot-api/open-intent.node 30 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/binding.gyp intent-static ${SOURCE_FILES} 31 | COMMAND npm install node-gyp 32 | COMMAND node_modules/.bin/node-gyp configure -C src/ 33 | COMMAND export BINARY_DIR=${CMAKE_BINARY_DIR} && node_modules/.bin/node-gyp rebuild -j 4 -C src/ 34 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/src/build/Release/open-intent.node 35 | ${CMAKE_CURRENT_SOURCE_DIR}/lib/chatbot-api/open-intent.node 36 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 37 | ) 38 | 39 | 40 | 41 | FIND_PROGRAM( DOCKER_PATH docker ) 42 | 43 | IF(DOCKER_PATH) 44 | ADD_CUSTOM_TARGET(open-intent-docker 45 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/open-intent.tgz 46 | COMMAND docker build -t open-intent . 47 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 48 | ) 49 | ADD_SUBDIRECTORY(test-integration) 50 | ELSE() 51 | MESSAGE(WARNING "Docker has not been found. Please note that you will not be able to execute the integration tests.") 52 | ENDIF() 53 | 54 | 55 | ADD_CUSTOM_TARGET(run-unit-tests-js 56 | DEPENDS open-intent-js 57 | COMMAND npm install 58 | COMMAND npm test 59 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 60 | ) 61 | 62 | -------------------------------------------------------------------------------- /bindings/nodejs/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | MAINTAINER open-intent.io 3 | 4 | #nodejs 5 | RUN apt-get update; apt-get install -y nodejs npm 6 | RUN ln -s /usr/bin/nodejs /usr/bin/node 7 | 8 | COPY open-intent.tgz /tmp/open-intent.tgz 9 | RUN npm install -g /tmp/open-intent.tgz 10 | 11 | EXPOSE 5000 12 | EXPOSE 5001 13 | EXPOSE 5002 14 | 15 | #VOLUME /chatbot 16 | WORKDIR /chatbot 17 | 18 | ADD docker/entrypoint.sh /entrypoint.sh 19 | 20 | CMD ["/entrypoint.sh"] -------------------------------------------------------------------------------- /bindings/nodejs/bin/open-intent.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* 3 | |---------------------------------------------------------| 4 | | ___ ___ _ _ | 5 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 6 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 7 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 8 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 9 | | |_| | 10 | | | 11 | | - The users first... | 12 | | | 13 | | Authors: | 14 | | - Clement Michaud | 15 | | - Sergei Kireev | 16 | | | 17 | | Version: 1.0.0 | 18 | | | 19 | |---------------------------------------------------------| 20 | 21 | The MIT License (MIT) 22 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 23 | 24 | Permission is hereby granted, free of charge, to any person obtaining a copy 25 | of this software and associated documentation files (the "Software"), to deal 26 | in the Software without restriction, including without limitation the rights 27 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 28 | copies of the Software, and to permit persons to whom the Software is 29 | furnished to do so, subject to the following conditions: 30 | 31 | The above copyright notice and this permission notice shall be included in 32 | all copies or substantial portions of the Software. 33 | 34 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 35 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 36 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 37 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | var app = require('commander'); 42 | 43 | app 44 | .command('project ', 'project actions'); 45 | 46 | app.parse(process.argv); 47 | -------------------------------------------------------------------------------- /bindings/nodejs/config/config.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | 'use strict'; 41 | 42 | var path = require('path'); 43 | 44 | var config = {}; 45 | 46 | config.project = { 47 | skeletonsDir: path.resolve(__dirname, '..', 'project-skeletons') 48 | }; 49 | 50 | config.debug = false; 51 | 52 | module.exports = config 53 | -------------------------------------------------------------------------------- /bindings/nodejs/config/default.yaml: -------------------------------------------------------------------------------- 1 | # swagger configuration file 2 | 3 | # values in the swagger hash are system configuration for swagger-node 4 | swagger: 5 | 6 | fittingsDirs: [ api/fittings ] 7 | defaultPipe: null 8 | swaggerControllerPipe: swagger_controllers # defines the standard processing pipe for controllers 9 | 10 | # values defined in the bagpipes key are the bagpipes pipes and fittings definitions 11 | # (see https://github.com/apigee-127/bagpipes) 12 | bagpipes: 13 | 14 | _router: 15 | name: swagger_router 16 | mockMode: false 17 | mockControllersDirs: [ api/mocks ] 18 | controllersDirs: [ api/controllers ] 19 | 20 | _swagger_validate: 21 | name: swagger_validator 22 | validateResponse: true 23 | 24 | # pipe for all swagger-node controllers 25 | swagger_controllers: 26 | - onError: json_error_handler 27 | - cors 28 | - swagger_security 29 | - _swagger_validate 30 | - express_compatibility 31 | - _router 32 | 33 | # pipe to serve swagger (endpoint is in swagger.yaml) 34 | swagger_raw: 35 | name: swagger_raw 36 | 37 | # any other values in this file are just loaded into the config for application access... 38 | -------------------------------------------------------------------------------- /bindings/nodejs/docker/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PACKAGE_TARBALL=/tmp/open-intent.tgz 4 | 5 | if [ ! -n "$(ls -A /chatbot)" ] 6 | then 7 | echo "New chatbot detected, initializing resources..." 8 | 9 | cd /tmp 10 | 11 | echo "Creating chatbot project" 12 | open-intent project create --no-npm chatbot > /dev/null 2>&1 13 | 14 | cd chatbot 15 | 16 | echo "Install the packages" 17 | npm install ${PACKAGE_TARBALL} 18 | npm install 19 | 20 | echo "Move chatbot project to /chatbot" 21 | mv /tmp/chatbot/* /chatbot 22 | 23 | echo "Chatbot project is ready" 24 | else 25 | echo "Existing chatbot detected." 26 | fi 27 | -------------------------------------------------------------------------------- /bindings/nodejs/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | module.exports = { 41 | 'Chatbot': require('./lib/chatbot'), 42 | 'middleware': require('./lib/middleware/index') 43 | }; 44 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/chatbot-api/chatbot-factory.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | var OpenIntent = require('./open-intent.node'); 41 | var ChatbotInterface = require('./chatbot-with-logger'); 42 | 43 | function createFromOIML(dictionaryModel, openIntentMLModel, 44 | sessionManagerDriver, userCommandsDriver) { 45 | return new ChatbotInterface(OpenIntent.createSerializableChatbotFromOIML(JSON.stringify(dictionaryModel), openIntentMLModel), 46 | sessionManagerDriver, userCommandsDriver); 47 | } 48 | 49 | function createFromJsonModel(jsonModel, sessionManagerDriver, userCommandsDriver) { 50 | return new ChatbotInterface(OpenIntent.createSerializableChatbotFromJsonModel(JSON.stringify(jsonModel)), sessionManagerDriver, 51 | userCommandsDriver); 52 | } 53 | 54 | module.exports.fromOIML = createFromOIML; 55 | module.exports.fromJsonModel = createFromJsonModel; 56 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/chatbot-api/session-manager/standalone-driver.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | var Q = require('q'); 41 | 42 | module.exports = function() { 43 | 44 | this._sessions = {}; 45 | 46 | this.save = function(sessionId, context) { 47 | var deferred = Q.defer(); 48 | 49 | this._sessions[sessionId] = context; 50 | deferred.resolve(); 51 | return deferred.promise; 52 | }; 53 | 54 | this.load = function(sessionId) { 55 | var deferred = Q.defer(); 56 | 57 | if(sessionId in this._sessions) { 58 | deferred.resolve(this._sessions[sessionId]); 59 | } 60 | else { 61 | deferred.reject('No session ' + sessionId + ' stored'); 62 | } 63 | return deferred.promise; 64 | }; 65 | 66 | return this; 67 | }; 68 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/middleware/README.md: -------------------------------------------------------------------------------- 1 | make sure you fill all the json files in the config section, 2 | 3 | for the skype platform you will also have to download the file skype-sdk.tar.gz and move it here. 4 | 5 | npm install 6 | node app.js 7 | 8 | some platforms require you to setup a webhook, so copy the webhook displayed in the console next to the platform. 9 | 10 | voila! -------------------------------------------------------------------------------- /bindings/nodejs/lib/middleware/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | module.exports = { 41 | 'Irc': require('./irc'), 42 | 'Rest': require('./rest'), 43 | 'Platforms': require('./platforms'), 44 | 'DocPublisher': require('./doc-publisher'), 45 | 'Logger': require('./loggers/logger') 46 | } 47 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/middleware/platforms/controllers/slack.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | var RtmClient = require('@slack/client').RtmClient; 41 | var RTM_EVENTS = require('@slack/client').RTM_EVENTS; 42 | 43 | module.exports.attach = function (chatbotClient, slackConfig) { 44 | 45 | var token = process.env.SLACK_API_TOKEN || slackConfig.API_TOKEN; 46 | 47 | var rtm = new RtmClient(token, { logLevel: 'warning' }); 48 | rtm.start(); 49 | 50 | rtm.on(RTM_EVENTS.MESSAGE, function handleRtmMessage(message) { 51 | var channel = message.channel; 52 | var content = message.text; 53 | chatbotClient.talk(channel, content).then(function(replies) { 54 | var reply = replies.length ? replies[0] : "An error occured"; 55 | rtm.sendMessage(reply, channel); 56 | }); 57 | }); 58 | } 59 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/middleware/platforms/controllers/telegram.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | var TelegramBot = require('node-telegram-bot-api'); 41 | 42 | module.exports.attach = function (chatbot, telegramConfig) { 43 | var token = telegramConfig.API_TOKEN; 44 | 45 | var tlbot = new TelegramBot(token, { 46 | polling: true 47 | }); 48 | 49 | // Any kind of message 50 | tlbot.on('message', function (msg) { 51 | var senderId = msg.from.id; 52 | var content = msg.text; 53 | chatbot.talk(senderId, content).then(function(replies) { 54 | var reply = replies.length ? replies[0] : "An error occured"; 55 | bot.sendMessage(senderId, reply); 56 | }); 57 | }); 58 | } 59 | -------------------------------------------------------------------------------- /bindings/nodejs/lib/middleware/templates/intent-story.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Model 5 | 6 | 7 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /bindings/nodejs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "open-intent", 3 | "version": "1.0.27", 4 | "description": "An API for the open-intent chatbots", 5 | "main": "bindings/nodejs/index.js", 6 | "bin": { 7 | "open-intent": "bin/open-intent.js" 8 | }, 9 | "scripts": { 10 | "test": "./node_modules/.bin/mocha --reporter spec --recursive 'test/**/*.js'" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/open-intent-io/open-intent" 15 | }, 16 | "keywords": [ 17 | "chatbot", 18 | "NLP", 19 | "intent", 20 | "entity" 21 | ], 22 | "dependencies": { 23 | "bindings": "1.2.x", 24 | "body-parser": "^1.15.2", 25 | "commander": "^2.9.0", 26 | "crypto": "0.0.3", 27 | "elasticsearch": "^11.0.1", 28 | "express": "^4.14.0", 29 | "fs-extra": "^0.30.0", 30 | "lodash": "^4.13.1", 31 | "messenger-bot": "^2.4.0", 32 | "nan": "2.3.x", 33 | "nodemon": "^1.10.0", 34 | "q": "^1.4.1", 35 | "readline": "^1.3.0", 36 | "readline-sync": "^1.4.4", 37 | "redis": "^2.6.0-2", 38 | "request": "^2.73.0", 39 | "requestify": "^0.1.17", 40 | "rmdir": "^1.2.0", 41 | "seq-queue": "0.0.5", 42 | "tmp": "0.0.28" 43 | }, 44 | "devDependencies": { 45 | "proxyquire": "^1.7.10", 46 | "mock-utf8-stream": "^0.1.1", 47 | "should": "^7.1.0", 48 | "mocha": "^2.5.3", 49 | "supertest": "^1.0.0", 50 | "sinon": "^1.17.4", 51 | "chai": "^3.5.0" 52 | }, 53 | "author": "Clément Michaud, Sergei Kireev", 54 | "license": "MIT" 55 | } 56 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/.gitignore: -------------------------------------------------------------------------------- 1 | # IDE files 2 | .idea 3 | 4 | # Logs 5 | logs 6 | *.log 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | 13 | # Directory for instrumented libs generated by jscoverage/JSCover 14 | lib-cov 15 | 16 | # Coverage directory used by tools like istanbul 17 | coverage 18 | 19 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 20 | .grunt 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # Commenting this out is preferred by some people, see 27 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 28 | node_modules 29 | 30 | # Users Environment Variables 31 | .lock-wscript 32 | 33 | # Runtime configuration for swagger app 34 | config/runtime.yaml -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/Aptfile: -------------------------------------------------------------------------------- 1 | http://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/gcc-5_5.4.0-6ubuntu1~16.04.2_amd64.deb 2 | http://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/libstdc%2B%2B6_5.4.0-6ubuntu1~16.04.2_amd64.deb 3 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/Procfile: -------------------------------------------------------------------------------- 1 | web: npm start 2 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/app.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | 41 | var openintent = require('open-intent'); 42 | 43 | var Chatbot = require('./app/chatbot'); 44 | var config = require('./app/config'); 45 | 46 | var REST_PORT = process.env.REST_PORT || 5001; 47 | var DOC_PUBLISHER_PORT = process.env.DOC_PUBLISHER_PORT || 5002; 48 | 49 | var chatbot = new Chatbot(); 50 | 51 | chatbot.set('irc', openintent.middleware.Irc()); 52 | chatbot.set('rest', openintent.middleware.Rest(REST_PORT)); 53 | chatbot.set('platforms', openintent.middleware.Platforms(config)); 54 | 55 | chatbot.set('doc', openintent.middleware.DocPublisher(DOC_PUBLISHER_PORT)); 56 | chatbot.set('logger', openintent.middleware.Logger(config.loggers)); 57 | 58 | chatbot.start() 59 | .fail(function(err) { 60 | console.error('Error: ', err); 61 | }); 62 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/app/chatbot.js: -------------------------------------------------------------------------------- 1 | 2 | var path = require('path'); 3 | var fs = require('fs'); 4 | var openintent = require('open-intent'); 5 | 6 | function Chatbot() { 7 | this._chatbot = new openintent.Chatbot(); 8 | } 9 | 10 | Chatbot.prototype.set = function(key, middleware) { 11 | this._chatbot.set(key, middleware); 12 | }; 13 | 14 | Chatbot.prototype.get = function(key) { 15 | return this._chatbot.get(key); 16 | }; 17 | 18 | 19 | Chatbot.prototype.start = function() { 20 | var modelDirectory = path.join(__dirname, '..', 'res'); 21 | 22 | var dictionaryFilepath = path.join(modelDirectory, 'dictionary.json'); 23 | var oimlFilepath = path.join(modelDirectory, 'script.txt'); 24 | var userCommandsFilepath = path.join(modelDirectory, 'user_commands.js'); 25 | 26 | var botmodel = { 27 | dictionary: JSON.parse(fs.readFileSync(dictionaryFilepath, 'utf-8')), 28 | oiml: fs.readFileSync(oimlFilepath, 'utf-8'), 29 | user_commands: require(userCommandsFilepath) 30 | }; 31 | 32 | return this._chatbot.start(botmodel); 33 | }; 34 | 35 | Chatbot.prototype.stop = function() { 36 | return this._chatbot.stop(); 37 | }; 38 | 39 | module.exports = Chatbot; -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/app/config.js: -------------------------------------------------------------------------------- 1 | 2 | var path = require('path'); 3 | 4 | var configDirectory = path.resolve(__dirname, '..', 'config'); 5 | 6 | module.exports = { 7 | 'general': require(path.resolve(configDirectory, 'general.json')), 8 | 'selection': require(path.resolve(configDirectory, 'selection.json')), 9 | 'loggers': { 10 | 'selection': require(path.resolve(configDirectory, 'loggers', 'selection.json')), 11 | 'elasticsearch': require(path.resolve(configDirectory, 'loggers', 'elasticsearch.json')) 12 | }, 13 | 'kik': require(path.resolve(configDirectory, 'kik/default.json')), 14 | 'messenger': require(path.resolve(configDirectory, 'messenger/default.json')), 15 | 'skype': require(path.resolve(configDirectory, 'skype/default.json')), 16 | 'slack': require(path.resolve(configDirectory, 'slack/default.json')), 17 | 'telegram': require(path.resolve(configDirectory, 'telegram/default.json')) 18 | }; 19 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/config/general.json: -------------------------------------------------------------------------------- 1 | { 2 | "port": 5000 3 | } -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/config/kik/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "username": "", 3 | "apiKey": "", 4 | "baseUrl": "" 5 | } 6 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/config/loggers/elasticsearch.json: -------------------------------------------------------------------------------- 1 | { 2 | "host": "localhost", 3 | "port": 9200, 4 | "index": "conversations" 5 | } -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/config/loggers/selection.json: -------------------------------------------------------------------------------- 1 | { 2 | "elasticsearch": false 3 | } -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/config/messenger/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "MESSENGER_APP_SECRET": "", 3 | "MESSENGER_PAGE_ACCESS_TOKEN": "", 4 | "MESSENGER_VALIDATION_TOKEN": "" 5 | } 6 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/config/selection.json: -------------------------------------------------------------------------------- 1 | { 2 | "messenger": false, 3 | "kik": false, 4 | "skype": false, 5 | "slack": false, 6 | "telegram": false 7 | } 8 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/config/skype/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "APP_ID":"", 3 | "BOT_ID":"", 4 | "APP_SECRET":"" 5 | } 6 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/config/slack/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "API_TOKEN":"" 3 | } -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/config/telegram/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "API_TOKEN":"" 3 | } -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | MAINTAINER open-intent.io 3 | 4 | ENV LD_LIBRARY_PATH="/usr/local/lib:/usr/lib/x86_64-linux-gnu" 5 | 6 | #nodejs 7 | RUN apt-get update; apt-get install -y nodejs npm \ 8 | libboost-system1.58 \ 9 | libboost-regex1.58 \ 10 | libboost-log1.58 11 | 12 | RUN npm install -g open-intent 13 | 14 | RUN ln -s /usr/bin/nodejs /usr/bin/node 15 | 16 | 17 | WORKDIR /usr/src 18 | 19 | RUN open-intent project create chatbot 20 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/docker/README.md: -------------------------------------------------------------------------------- 1 | * General 2 | 3 | This is an example of REST chatbot with a debugging CLI. You can use it to build up your own bot model with the open-intent markup language. 4 | 5 | The program runs in a docker container and is monitoring the 3 model files 'script.txt', 'user_commands.js' and 'dictionary.json'. 6 | Just put those files in a directory and mount it in /usr/src/res in the docker container to use your own model. You can even modify them at runtime and the bot will consume them right away. 7 | 8 | 9 | * Run the example 10 | 11 | Install the nodejs dependencies with: 12 | 13 | npm install 14 | 15 | The following line will build the docker image 16 | 17 | docker build -t chatbot . 18 | 19 | The following line will start your chatbot service on port 8080 20 | 21 | docker run --rm -v /path/to/custom/res:/usr/src/chatbot/res -it -p 8080:8080 chatbot 22 | 23 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/heroku_setup: -------------------------------------------------------------------------------- 1 | heroku create && 2 | heroku buildpacks:add --index 1 https://github.com/ddollar/heroku-buildpack-apt.git && 3 | heroku buildpacks:add --index 2 heroku/nodejs 4 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "open-intent-chatbot", 3 | "version": "0.0.1", 4 | "private": true, 5 | "description": "Open-intent chatbot project", 6 | "keywords": [], 7 | "author": "", 8 | "license": "", 9 | "main": "app.js", 10 | "dependencies": { 11 | "chai": "^3.5.0", 12 | "nodemon": "^1.9.2", 13 | "open-intent": "^1.0.0", 14 | "q": "^1.4.1" 15 | }, 16 | "devDependencies": { 17 | "chai": "^3.5.0", 18 | "mock-utf8-stream": "^0.1.1", 19 | "should": "^7.1.0", 20 | "mocha": "^2.5.3" 21 | }, 22 | "scripts": { 23 | "start": "node app.js", 24 | "test": "./node_modules/.bin/mocha --reporter spec app/test/**" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/res/dictionary.json: -------------------------------------------------------------------------------- 1 | { 2 | "entities": { 3 | "greetings": { 4 | "hello": ["hi", "yep", "yo", "hey"] 5 | }, 6 | "food_type": { 7 | "pizza": [], 8 | "hamburger": ["big mac", "cheeseburger", "burger"], 9 | "salad": [] 10 | }, 11 | "yes": { 12 | "yes": [] 13 | }, 14 | "no": { 15 | "no": [] 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/res/script.txt: -------------------------------------------------------------------------------- 1 | { 2 | @root 3 | -Hello 4 | #greetings 5 | -Would you want to eat a pizza, a hamburger or a salad? 6 | @get_food_type 7 | -Pizza, please. 8 | #get_food_type 9 | *I did not understand. Pizza, hamburger or salad? 10 | -Got it, you want _, right? 11 | @yesno 12 | -Yes! 13 | #confirm 14 | -I'm ordering, it is gonna be _$. 15 | @end 16 | } 17 | 18 | { 19 | @yesno 20 | -No! 21 | #notunderstood 22 | -Tell me what you want. Pizza, hamburger or salad? 23 | @get_food_type 24 | } 25 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/res/user_commands.js: -------------------------------------------------------------------------------- 1 | var food_type; 2 | 3 | module.exports = function(handler) { 4 | handler.on("#get_food_type", function(intentVariables, sessionId, next) { 5 | var replyVariables = {}; 6 | food_type = intentVariables['food_type0']; 7 | replyVariables['0'] = food_type; 8 | next(replyVariables); 9 | }); 10 | 11 | handler.on("#confirm", function(intentVariables, sessionId, next) { 12 | var replyVariables = {}; 13 | if(food_type == 'pizza') { 14 | replyVariables['0'] = '8'; 15 | } 16 | else { 17 | replyVariables['0'] = '5'; 18 | } 19 | next(replyVariables); 20 | }); 21 | }; 22 | -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/test-conversations/do-not-understand-item.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | Would you want to eat a pizza, a hamburger or a salad? 3 | chicken 4 | I did not understand. Pizza, hamburger or salad? -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/test-conversations/make-mistake-during-ordering.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | Would you want to eat a pizza, a hamburger or a salad? 3 | Pizza 4 | Got it, you want pizza, right? 5 | No 6 | Tell me what you want. Pizza, hamburger or salad? 7 | Salad 8 | Got it, you want salad, right? 9 | yes 10 | I'm ordering, it is gonna be 5$. -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/test-conversations/order-hamburger.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | Would you want to eat a pizza, a hamburger or a salad? 3 | Hamburger 4 | Got it, you want hamburger, right? 5 | yes 6 | I'm ordering, it is gonna be 5$. -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/test-conversations/order-pizza.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | Would you want to eat a pizza, a hamburger or a salad? 3 | Pizza 4 | Got it, you want pizza, right? 5 | yes 6 | I'm ordering, it is gonna be 8$. -------------------------------------------------------------------------------- /bindings/nodejs/project-skeletons/chatbot/test-conversations/order-salad.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | Would you want to eat a pizza, a hamburger or a salad? 3 | Salad 4 | Got it, you want salad, right? 5 | yes 6 | I'm ordering, it is gonna be 5$. -------------------------------------------------------------------------------- /bindings/nodejs/src/binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "open-intent", 5 | "sources": [ 6 | "main.cpp", 7 | "SerializableChatbot.cpp", 8 | ], 9 | 'include_dirs': [ 10 | "../include", "../../../include", 11 | "../../../thirdparty/json/src", 12 | "../../../thirdparty/spdlog/include" 13 | ], 14 | "cflags": [ 15 | "-std=c++11", 16 | "-frtti", 17 | "-fexceptions" 18 | ], 19 | 'cflags_cc': [ 20 | "-std=c++11", 21 | "-frtti", 22 | "-fexceptions" 23 | ], 24 | 'libraries': [ 25 | '-L$(BINARY_DIR)/src', 26 | '-lintent-static' 27 | ] 28 | }] 29 | } 30 | -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | ADD_CUSTOM_TARGET(build-integration-test-docker 4 | COMMAND docker build -t open-intent-integration . 5 | DEPENDS open-intent-docker 6 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 7 | ) 8 | 9 | ADD_CUSTOM_TARGET(run-integration-tests-js 10 | DEPENDS run-integration-tests-js-chatbot 11 | run-integration-tests-js-tutorial 12 | run-integration-tests-js-elasticsearch-logs 13 | ) 14 | 15 | ADD_CUSTOM_TARGET(run-integration-tests-js-chatbot 16 | DEPENDS build-integration-test-docker 17 | COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/chatbot/launch.sh 18 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 19 | ) 20 | 21 | ADD_CUSTOM_TARGET(run-integration-tests-js-tutorial 22 | DEPENDS build-integration-test-docker 23 | COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tutorial/launch.sh 24 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 25 | ) 26 | 27 | ADD_CUSTOM_TARGET(run-integration-tests-js-elasticsearch-logs 28 | DEPENDS build-integration-test-docker 29 | COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/elasticsearch-logs/launch.sh 30 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 31 | ) -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM open-intent 2 | MAINTAINER open-intent.io 3 | 4 | RUN npm install -g mocha 5 | 6 | RUN /entrypoint.sh 7 | 8 | WORKDIR /chatbot 9 | 10 | CMD ["mocha"] -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/chatbot/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM open-intent-integration 2 | MAINTAINER open-intent.io 3 | 4 | ADD test /chatbot/test 5 | 6 | -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/chatbot/launch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o pipefail 4 | 5 | test_directory=chatbot 6 | 7 | image_name=open-intent-${test_directory}-test 8 | 9 | echo "Build docker image ${image_name}" 10 | docker build -t ${image_name} ${test_directory} 11 | 12 | echo "Run docker image ${image_name}" 13 | # Run the test 14 | docker run --rm -i --volumes-from open-intent-source-volume ${image_name} 15 | -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/chatbot/test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "test.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "should": "^10.0.0", 13 | "q": "^1.4.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/elasticsearch-logs/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM open-intent-integration 2 | MAINTAINER open-intent.io 3 | 4 | ADD res/ /chatbot/res 5 | ADD test/ /chatbot/test 6 | 7 | -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/elasticsearch-logs/launch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o pipefail 4 | 5 | test_directory=elasticsearch-logs 6 | 7 | image_name=open-intent-${test_directory}-test 8 | 9 | docker build -t ${image_name} ${test_directory} 10 | 11 | docker run -d -i -p 9200:9200 --name elasticsearch elasticsearch:2.4 12 | 13 | echo "Sleep 7 seconds during elasticsearch initialization to be sure everything is up and running." 14 | sleep 7 15 | 16 | # Run the test 17 | docker run --rm -i --volumes-from open-intent-source-volume --link elasticsearch:elasticsearch ${image_name} 18 | 19 | docker stop elasticsearch 20 | docker rm elasticsearch 21 | -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/elasticsearch-logs/res/dictionary.json: -------------------------------------------------------------------------------- 1 | { 2 | "entities": 3 | { 4 | "greetings": { 5 | "Hello": ["Hi", "Hey"], 6 | "What's up": [] 7 | }, 8 | "time": { 9 | "time": [] 10 | }, 11 | "question": { 12 | "what": [] 13 | }, 14 | "name": { 15 | "name": [] 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/elasticsearch-logs/res/script.txt: -------------------------------------------------------------------------------- 1 | { 2 | @root_state 3 | -Hello 4 | #greetings 5 | *Be gentle, say hello! 6 | -Hello, I can tell you what time it is if you ask. 7 | @ask_state 8 | -What time is it? 9 | #telltime 10 | *I don't understand what you mean... 11 | -It is _. 12 | @end_state 13 | } 14 | 15 | { 16 | @ask_state 17 | -What is your name? 18 | #tellname 19 | *I don't understand what you mean... 20 | -My name is Bob. 21 | @ask_state 22 | } -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/elasticsearch-logs/res/user_commands.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | function getDateTime() { 41 | return new Date().toString().substring(16,24); 42 | } 43 | 44 | module.exports = function(handler) { 45 | handler.on('#telltime', function(intentVariables, sessionId, next) { 46 | var replyVariables = {}; 47 | replyVariables['0'] = getDateTime(); 48 | next(replyVariables); 49 | }); 50 | }; 51 | -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/elasticsearch-logs/test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "test.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "should": "^10.0.0", 13 | "q": "^1.4.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/tutorial/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM open-intent-integration 2 | MAINTAINER open-intent.io 3 | 4 | ADD res/ /chatbot/res 5 | ADD test/ /chatbot/test 6 | 7 | -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/tutorial/launch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o pipefail 4 | 5 | test_directory=tutorial 6 | image_name=open-intent-${test_directory}-test 7 | 8 | docker build -t ${image_name} ${test_directory} 9 | 10 | # Run the test 11 | docker run --rm -i --volumes-from open-intent-source-volume ${image_name} 12 | -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/tutorial/res/dictionary.json: -------------------------------------------------------------------------------- 1 | { 2 | "entities": 3 | { 4 | "greetings": { 5 | "Hello": ["Hi", "Hey"], 6 | "What's up": [] 7 | }, 8 | "time": { 9 | "time": [] 10 | }, 11 | "question": { 12 | "what": [] 13 | }, 14 | "name": { 15 | "name": [] 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/tutorial/res/script.txt: -------------------------------------------------------------------------------- 1 | { 2 | @root_state 3 | -Hello 4 | #greetings 5 | *Be gentle, say hello! 6 | -Hello, I can tell you what time it is if you ask. 7 | @ask_state 8 | -What time is it? 9 | #telltime 10 | *I don't understand what you mean... 11 | -It is _. 12 | @end_state 13 | } 14 | 15 | { 16 | @ask_state 17 | -What is your name? 18 | #tellname 19 | *I don't understand what you mean... 20 | -My name is Bob. 21 | @ask_state 22 | } -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/tutorial/res/user_commands.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | function getDateTime() { 41 | return new Date().toString().substring(16,24); 42 | } 43 | 44 | module.exports = function(handler) { 45 | handler.on('#telltime', function(intentVariables, sessionId, next) { 46 | var replyVariables = {}; 47 | replyVariables['0'] = getDateTime(); 48 | next(replyVariables); 49 | }); 50 | }; 51 | -------------------------------------------------------------------------------- /bindings/nodejs/test-integration/tutorial/test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "test.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "should": "^10.0.0", 13 | "q": "^1.4.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /bindings/nodejs/test/bad-food-bot-model.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | var fs = require('fs'); 41 | var path = require('path'); 42 | 43 | var dictionaryFile = path.resolve(__dirname, 'res/food_bot/dictionary.json'); 44 | var scriptFile = path.resolve(__dirname, 'res/food_bot/bad_script.txt'); 45 | 46 | var botmodel = { 47 | dictionary: JSON.parse(fs.readFileSync(dictionaryFile, 'utf-8')), 48 | user_commands: require(path.resolve(__dirname, 'res/food_bot/user_commands.js')), 49 | oiml: fs.readFileSync(scriptFile, 'utf-8') 50 | }; 51 | 52 | module.exports = botmodel; 53 | -------------------------------------------------------------------------------- /bindings/nodejs/test/chatbot-api/res/bad_interpreter_model.txt: -------------------------------------------------------------------------------- 1 | { 2 | @root 3 | -Bob! 4 | #wake 5 | *Je n'ai pas compris votre demande 6 | -Que puis-je vous offrir ? 7 | 8 | @wait_order 9 | -No intent matching 10 | #append_order1 11 | *Soyez le plus précis possible 12 | -Vous-voulez quelque chose d'autre ? 13 | 14 | @wait_another_order 15 | -Je voudrais une kro et un coca 16 | #append_order2 17 | -Vous-voulez quelque chose d'autre ? 18 | 19 | @wait_another_order 20 | -Je voudrais une kro 21 | -Vous-voulez quelque chose d'autre ? 22 | 23 | @wait_another_order 24 | -Rien 25 | #grab_it 26 | -Veuillez récupérer vos consommations au bar. Vous devrez payer _. 27 | 28 | @bye 29 | } 30 | 31 | { 32 | @wait_order 33 | -Je voudrais une kro et un coca 34 | #append_order2 35 | -Vous-voulez quelque chose d'autre ? 36 | @wait_another_order 37 | } 38 | 39 | { 40 | @wait_order 41 | -Rien 42 | #bye 43 | -Au revoir et à bientôt. 44 | @bye 45 | } 46 | -------------------------------------------------------------------------------- /bindings/nodejs/test/chatbot-api/res/food_bot/bad_script.txt: -------------------------------------------------------------------------------- 1 | { 2 | @root 3 | -Hello 4 | #greetings 5 | -Would you want to eat a pizza, a hamburger or a salad? 6 | @get_food_type 7 | -Pizza, please. 8 | #get_food_type 9 | * I did not understand. Pizza, hamburger or salad? 10 | -Got it, you want _, right? 11 | @yesno 12 | -Oups! 13 | #confirm 14 | -I'm ordering, it is gonna be _$. 15 | @end 16 | } 17 | 18 | { 19 | @yesno 20 | -No 21 | #notunderstood 22 | -Tell me what you want. 23 | @get_food_type 24 | } -------------------------------------------------------------------------------- /bindings/nodejs/test/chatbot-api/res/food_bot/dictionary.json: -------------------------------------------------------------------------------- 1 | { 2 | "entities": { 3 | "greetings": { 4 | "hello": ["hi", "yep", "yo", "hey"] 5 | }, 6 | "food_type": { 7 | "pizza": [], 8 | "hamburger": ["big mac", "cheeseburger", "burger"], 9 | "salad": [] 10 | }, 11 | "yes_no": { 12 | "yes": [], 13 | "no": [] 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /bindings/nodejs/test/chatbot-api/res/food_bot/script.txt: -------------------------------------------------------------------------------- 1 | { 2 | @root 3 | -Hello 4 | #greetings 5 | -Would you want to eat a pizza, a hamburger or a salad? 6 | @get_food_type 7 | -Pizza, please. 8 | #get_food_type 9 | *I did not understand. Pizza, hamburger or salad? 10 | -Got it, you want _, right? 11 | @yesno 12 | -Yes! 13 | #confirm 14 | -I'm ordering, it is gonna be _$. 15 | @end 16 | } 17 | 18 | { 19 | @yesno 20 | -No 21 | #notunderstood 22 | -Tell me what you want. 23 | @get_food_type 24 | } -------------------------------------------------------------------------------- /bindings/nodejs/test/chatbot-api/res/food_bot/user_commands.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | module.exports = function(handler) { 41 | 42 | handler.on("#get_food_type", function(intentVariables, sessionId, next) { 43 | var replyVariables = {}; 44 | replyVariables['0'] = intentVariables['food_type0']; 45 | next(replyVariables); 46 | }); 47 | 48 | handler.on("#confirm", function(intentVariables, sessionId, next) { 49 | replyVariables['0'] = '5'; 50 | next(replyVariables); 51 | }); 52 | } 53 | -------------------------------------------------------------------------------- /bindings/nodejs/test/chatbot-api/res/interpreter_model.txt: -------------------------------------------------------------------------------- 1 | { 2 | @root 3 | -Bob! 4 | #wake 5 | *Je n'ai pas compris votre demande 6 | -Que puis-je vous offrir ? 7 | 8 | @wait_order 9 | -Je voudrais une kro 10 | #append_order1 11 | *Soyez le plus précis possible 12 | -Vous-voulez quelque chose d'autre ? 13 | 14 | @wait_another_order 15 | -Je voudrais une kro et un coca 16 | #append_order2 17 | -Vous-voulez quelque chose d'autre ? 18 | 19 | @wait_another_order 20 | -Je voudrais une kro 21 | #append_order1 22 | -Vous-voulez quelque chose d'autre ? 23 | 24 | @wait_another_order 25 | -Rien 26 | #grab_it 27 | -Veuillez récupérer vos consommations au bar. Vous devrez payer _. 28 | 29 | @bye 30 | } 31 | 32 | { 33 | @wait_order 34 | -Je voudrais une kro et un coca 35 | #append_order2 36 | -Vous-voulez quelque chose d'autre ? 37 | @wait_another_order 38 | } 39 | 40 | { 41 | @wait_order 42 | -Rien 43 | #bye 44 | -Au revoir et à bientôt. 45 | @bye 46 | } 47 | -------------------------------------------------------------------------------- /bindings/nodejs/test/chatbot-api/res/userCommands.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | module.exports = function(handler) { 41 | handler.on('wake', function(intentVariables, sessionId, next) { 42 | next(); 43 | }); 44 | 45 | handler.on('append_order1', function(intentVariables, sessionId, next) { 46 | var variables = {}; 47 | variables['0'] = 'variable0'; 48 | 49 | next(variables); 50 | }); 51 | 52 | handler.on('bye', function(intentVariables, sessionId, next) { 53 | next(); 54 | }); 55 | }; 56 | -------------------------------------------------------------------------------- /bindings/nodejs/test/chatbot-api/test-chatbot-factory.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | var expect = require("chai").expect; 41 | var assert = require("chai").assert; 42 | var sinon = require('sinon'); 43 | var Q = require('q'); 44 | var path = require('path'); 45 | 46 | var StandaloneSessionManager = require('../../lib/chatbot-api/session-manager/standalone-driver'); 47 | var SimpleUserCommandsDriver = require('../../lib/chatbot-api/user-defined-actions/simple-driver'); 48 | 49 | var OpenIntentChatbot = require('../../lib/chatbot-api/chatbot-factory'); 50 | 51 | var fs = require('fs'); 52 | var file = path.resolve(__dirname, 'res/chatbot.json'); 53 | var model = JSON.parse(fs.readFileSync(file, "utf-8")); 54 | 55 | var userCommands = require(path.resolve(__dirname, 'res/userCommands.js')); 56 | 57 | var file = path.resolve(__dirname, 'res/interpreter_model.txt'); 58 | var interpreterModel = fs.readFileSync(file, "utf-8"); 59 | 60 | describe("Test Open Intent chatbot factory", function() { 61 | 62 | }); 63 | -------------------------------------------------------------------------------- /bindings/nodejs/test/chatbot-api/user-commands.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | var state = 4; 41 | 42 | module.exports = function(handler) { 43 | var setup = false; 44 | var cleanup = false; 45 | 46 | handler.on('_setup', function(next) { 47 | setup = true; 48 | next(setup); 49 | }); 50 | 51 | handler.on('_cleanup', function(next) { 52 | cleanup = true; 53 | next(cleanup); 54 | }); 55 | 56 | handler.on('command1', function(intentVariables, sessionId, next) { 57 | state += 1; 58 | next({state: state}); 59 | }); 60 | 61 | handler.on('command2', function(intentVariables, sessionId, next) { 62 | state += 2; 63 | next({state: state}); 64 | }); 65 | }; 66 | -------------------------------------------------------------------------------- /bindings/nodejs/test/food-bot-model.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | var fs = require('fs'); 41 | var path = require('path'); 42 | 43 | var dictionaryFile = path.resolve(__dirname, 'res/food_bot/dictionary.json'); 44 | var scriptFile = path.resolve(__dirname, 'res/food_bot/script.txt'); 45 | 46 | var botmodel = { 47 | dictionary: JSON.parse(fs.readFileSync(dictionaryFile, 'utf-8')), 48 | user_commands: require(path.resolve(__dirname, 'res/food_bot/user_commands.js')), 49 | oiml: fs.readFileSync(scriptFile, 'utf-8') 50 | }; 51 | 52 | module.exports = botmodel; 53 | -------------------------------------------------------------------------------- /bindings/nodejs/test/middleware/test-doc-publisher.expected.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Model 5 | 6 | 7 | 8 | 25 | 26 | -------------------------------------------------------------------------------- /bindings/nodejs/test/project-skeletons/chatbot/test-chatbot.js: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 37 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 38 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | */ 40 | var proxyquire = require('proxyquire'); 41 | var oi = require('../../../index'); 42 | var path = require('path'); 43 | oi['@noCallThru'] = true; 44 | 45 | var chatbot = proxyquire(path.resolve(__dirname, '../../../project-skeletons/chatbot/app/chatbot'), { 46 | 'open-intent': oi 47 | }); 48 | 49 | 50 | var h = proxyquire('../../../project-skeletons/chatbot/app/test/helpers', { 51 | '../chatbot': chatbot, 52 | 'open-intent': oi 53 | }); 54 | 55 | proxyquire('../../../project-skeletons/chatbot/app/test/test-chatbot', { 56 | './helpers': h 57 | }); 58 | -------------------------------------------------------------------------------- /bindings/nodejs/test/res/food_bot/bad_script.txt: -------------------------------------------------------------------------------- 1 | { 2 | @root 3 | -Hello 4 | #greetings 5 | -Would you want to eat a pizza, a hamburger or a salad? 6 | @get_food_type 7 | -Pizza, please. 8 | #get_food_type 9 | * I did not understand. Pizza, hamburger or salad? 10 | -Got it, you want _, right? 11 | @yesno 12 | -Oups! 13 | #confirm 14 | -I'm ordering, it is gonna be _$. 15 | @end 16 | } 17 | 18 | { 19 | @yesno 20 | -No 21 | #notunderstood 22 | -Tell me what you want. 23 | @get_food_type 24 | } -------------------------------------------------------------------------------- /bindings/nodejs/test/res/food_bot/dictionary.json: -------------------------------------------------------------------------------- 1 | { 2 | "entities": { 3 | "greetings": { 4 | "hello": ["hi", "yep", "yo", "hey"] 5 | }, 6 | "food_type": { 7 | "pizza": [], 8 | "hamburger": ["big mac", "cheeseburger", "burger"], 9 | "salad": [] 10 | }, 11 | "yes": { 12 | "yes": [] 13 | }, 14 | "no": { 15 | "no": [] 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /bindings/nodejs/test/res/food_bot/script.txt: -------------------------------------------------------------------------------- 1 | { 2 | @root 3 | -Hello 4 | #greetings 5 | -Would you want to eat a pizza, a hamburger or a salad? 6 | @get_food_type 7 | -Pizza, please. 8 | #get_food_type 9 | *I did not understand _. Pizza, hamburger or salad? 10 | -Got it, you want _, right? 11 | @yesno 12 | -Yes! 13 | #confirm 14 | -I'm ordering, it is gonna be _$. 15 | @end 16 | } 17 | 18 | { 19 | @yesno 20 | -No! 21 | #notunderstood 22 | -Tell me what you want. Pizza, hamburger or salad? 23 | @get_food_type 24 | } 25 | 26 | { 27 | @specialoffer 28 | -Yes! 29 | #confirm 30 | -Congratulations on the special offer, it is gonna be _$. 31 | @end 32 | } 33 | 34 | { 35 | @specialoffer 36 | -No! 37 | #notunderstood 38 | -Tell me what you want. Pizza, hamburger or salad? 39 | @get_food_type 40 | } 41 | -------------------------------------------------------------------------------- /cmake/Custom.cmake: -------------------------------------------------------------------------------- 1 | 2 | include(CMakeParseArguments) 3 | 4 | FUNCTION(COPY_RES_FILES) 5 | set(options "") 6 | set(oneValueArgs DEST_DIR SRC_DIR) 7 | set(multiValueArgs RES_FILES) 8 | cmake_parse_arguments(COPY_RES_FILES "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 9 | 10 | MESSAGE("${COPY_RES_FILES_RES_FILES}") 11 | 12 | FOREACH(SRC_FILE ${COPY_RES_FILES_RES_FILES}) 13 | SET(DEST_FILE ${COPY_RES_FILES_DEST_DIR}/${SRC_FILE}) 14 | 15 | configure_file(${COPY_RES_FILES_SRC_DIR}${SRC_FILE} ${DEST_FILE} COPYONLY) 16 | 17 | MESSAGE("Copying ${SRC_FILE} to ${DEST_FILE}") 18 | ENDFOREACH() 19 | 20 | ENDFUNCTION() 21 | 22 | FUNCTION(GENERATE_RUN_SCRIPT) 23 | 24 | SET(RUN_SCRIPT " 25 | #!/bin/bash 26 | 27 | export LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src 28 | 29 | cd ${CMAKE_CURRENT_SOURCE_DIR} 30 | nodejs with_json_model.js 31 | ") 32 | 33 | set(options "") 34 | set(oneValueArgs SCRIPT_NAME DESTINATION) 35 | set(multiValueArgs "") 36 | cmake_parse_arguments(GENERATE_RUN_SCRIPT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 37 | 38 | FILE(WRITE ${GENERATE_RUN_SCRIPT_SCRIPT_NAME} ${RUN_SCRIPT}) 39 | 40 | FILE(INSTALL ${GENERATE_RUN_SCRIPT_SCRIPT_NAME} DESTINATION ${GENERATE_RUN_SCRIPT_DESTINATION} 41 | FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE) 42 | ENDFUNCTION() 43 | -------------------------------------------------------------------------------- /doc/img/create_fb_app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-intent-io/open-intent/57d8c4fc89c038f51138d51e776880e728152194/doc/img/create_fb_app.png -------------------------------------------------------------------------------- /doc/img/create_fb_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-intent-io/open-intent/57d8c4fc89c038f51138d51e776880e728152194/doc/img/create_fb_page.png -------------------------------------------------------------------------------- /doc/img/facebook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-intent-io/open-intent/57d8c4fc89c038f51138d51e776880e728152194/doc/img/facebook.png -------------------------------------------------------------------------------- /doc/img/fb_app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-intent-io/open-intent/57d8c4fc89c038f51138d51e776880e728152194/doc/img/fb_app.png -------------------------------------------------------------------------------- /doc/img/fb_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-intent-io/open-intent/57d8c4fc89c038f51138d51e776880e728152194/doc/img/fb_menu.png -------------------------------------------------------------------------------- /doc/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-intent-io/open-intent/57d8c4fc89c038f51138d51e776880e728152194/doc/img/logo.png -------------------------------------------------------------------------------- /doc/img/logo_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-intent-io/open-intent/57d8c4fc89c038f51138d51e776880e728152194/doc/img/logo_128.png -------------------------------------------------------------------------------- /doc/img/ngrok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-intent-io/open-intent/57d8c4fc89c038f51138d51e776880e728152194/doc/img/ngrok.png -------------------------------------------------------------------------------- /doc/img/page_access_token.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-intent-io/open-intent/57d8c4fc89c038f51138d51e776880e728152194/doc/img/page_access_token.png -------------------------------------------------------------------------------- /doc/img/subscribe_webhook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-intent-io/open-intent/57d8c4fc89c038f51138d51e776880e728152194/doc/img/subscribe_webhook.png -------------------------------------------------------------------------------- /examples/BeerBar/BeerBar.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clement on 29/05/16. 3 | // 4 | 5 | #ifndef INTENT_BEERBAR_HPP 6 | #define INTENT_BEERBAR_HPP 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | class InputReader 19 | { 20 | public: 21 | virtual InputReader& operator>>(std::string &input) = 0; 22 | }; 23 | 24 | class OutputWriter 25 | { 26 | public: 27 | virtual OutputWriter& operator<<(const std::string &output) = 0; 28 | virtual OutputWriter& operator<<(const std::vector &replies) = 0; 29 | }; 30 | 31 | class BeerBar 32 | { 33 | public: 34 | static void run(InputReader &inputReader, OutputWriter &outputWriter); 35 | }; 36 | 37 | 38 | #endif //INTENT_BEERBAR_HPP 39 | -------------------------------------------------------------------------------- /examples/BeerBar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | SET(TARGET beerbar) 4 | 5 | ADD_DEFINITIONS(-DRESSOURCES_DIRECTORY="${CMAKE_CURRENT_SOURCE_DIR}") 6 | 7 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) 8 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thirdparty/json/src) 9 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thirdparty/spdlog/include) 10 | 11 | ADD_EXECUTABLE(${TARGET} main.cpp BeerBar.cpp) 12 | TARGET_LINK_LIBRARIES(${TARGET} intent-static ${Boost_LIBRARIES}) 13 | 14 | ADD_SUBDIRECTORY(test) 15 | -------------------------------------------------------------------------------- /examples/BeerBar/main.cpp: -------------------------------------------------------------------------------- 1 | #include "BeerBar.hpp" 2 | 3 | class StdOutputWriter : public OutputWriter 4 | { 5 | public: 6 | StdOutputWriter& operator<<(const std::string &output) 7 | { 8 | std::cout << output; 9 | return *this; 10 | } 11 | 12 | StdOutputWriter& operator<<(const std::vector &replies) 13 | { 14 | for(const std::string &reply: replies) { 15 | std::cout << reply << "\n"; 16 | } 17 | return *this; 18 | } 19 | }; 20 | 21 | class StdInputReader : public InputReader 22 | { 23 | public: 24 | StdInputReader& operator>>(std::string &input) 25 | { 26 | std::getline(std::cin, input); 27 | return *this; 28 | } 29 | }; 30 | 31 | int main(int argc, char **argv) 32 | { 33 | StdOutputWriter outputWriter; 34 | StdInputReader inputReader; 35 | 36 | BeerBar::run(inputReader, outputWriter); 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /examples/BeerBar/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | SET(TARGET beerbar-test) 4 | 5 | SET(RES_FILES chatbot.json) 6 | 7 | COPY_RES_FILES(RES_FILES ${RES_FILES} SRC_DIR ../ DEST_DIR ${CMAKE_CURRENT_BINARY_DIR}) 8 | 9 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) 10 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thirdparty/json/src) 11 | INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/..) 12 | 13 | ADD_EXECUTABLE(${TARGET} ../BeerBar.cpp BeerBarTest.cpp) 14 | TARGET_LINK_LIBRARIES(${TARGET} gtest gmock gmock_main intent-static) 15 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | ADD_SUBDIRECTORY(BeerBar) 4 | ADD_SUBDIRECTORY(QueriesBar) 5 | ADD_SUBDIRECTORY(Domotic) 6 | ADD_SUBDIRECTORY(IntentViz) 7 | 8 | ADD_CUSTOM_TARGET(run-integration-tests-cpp 9 | DEPENDS run-integration-tests-cpp-domotic run-integration-tests-cpp-beerbar 10 | ) 11 | 12 | ADD_CUSTOM_TARGET(run-integration-tests-cpp-domotic 13 | DEPENDS domotic-test 14 | COMMAND ${CMAKE_BINARY_DIR}/examples/Domotic/test/domotic-test 15 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/examples/Domotic/test 16 | ) 17 | 18 | ADD_CUSTOM_TARGET(run-integration-tests-cpp-beerbar 19 | DEPENDS beerbar-test 20 | COMMAND ${CMAKE_BINARY_DIR}/examples/BeerBar/test/beerbar-test 21 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/examples/BeerBar/test 22 | ) -------------------------------------------------------------------------------- /examples/Domotic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | SET(TARGET domotic) 4 | 5 | SET(RES_FILES 6 | intent.json) 7 | 8 | COPY_RES_FILES(RES_FILES ${RES_FILES} DEST_DIR ${CMAKE_CURRENT_BINARY_DIR}) 9 | 10 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) 11 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thirdparty/json/src) 12 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thirdparty/spdlog/include) 13 | 14 | ADD_EXECUTABLE(${TARGET} main.cpp Domotic.cpp) 15 | TARGET_LINK_LIBRARIES(${TARGET} intent-static ${Boost_LIBRARIES}) 16 | 17 | ADD_SUBDIRECTORY(test) 18 | -------------------------------------------------------------------------------- /examples/Domotic/Domotic.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clement on 29/05/16. 3 | // 4 | 5 | #include "Domotic.hpp" 6 | 7 | #include "intent/OpenIntent.hpp" 8 | 9 | #include 10 | 11 | using namespace intent; 12 | 13 | void treatIntent(const IntentService::Result &intentResult, OutputWriter &ostream) 14 | { 15 | if(intentResult.intent.intentId == "turn_the_light_X") 16 | { 17 | if(intentResult.intent.entityMatches[1].term == "on") 18 | { 19 | ostream << "Light is on."; 20 | } 21 | else 22 | { 23 | ostream << "Light is off."; 24 | } 25 | } 26 | else if(intentResult.intent.intentId == "turn_X_the_light") 27 | { 28 | if(intentResult.intent.entityMatches[0].term == "on") 29 | { 30 | ostream << "Light is on."; 31 | } 32 | else 33 | { 34 | ostream << "Light is off."; 35 | } 36 | } 37 | else if(intentResult.intent.intentId == "open_close_window") 38 | { 39 | if(intentResult.intent.entityMatches[0].term == "open") 40 | { 41 | ostream << "Window is open."; 42 | } 43 | else 44 | { 45 | ostream << "Window is closed."; 46 | } 47 | } 48 | else if(intentResult.intent.intentId == "lower_higher_heating") 49 | { 50 | if(intentResult.intent.entityMatches[0].term == "lower") 51 | { 52 | ostream << "Heating system has been lowered."; 53 | } 54 | else 55 | { 56 | ostream << "Heating system has been highered."; 57 | } 58 | } 59 | } 60 | 61 | void Domotic::run(InputReader &istream, OutputWriter &ostream) 62 | { 63 | ostream << "###########################\n"; 64 | ostream << "####### Domotic #######\n"; 65 | ostream << "###########################\n"; 66 | 67 | std::string dictionaryFilename = "intent.json"; 68 | std::ifstream f(dictionaryFilename); 69 | intent::Deserializer deserializer; 70 | 71 | IntentServiceModel intentServiceModel = deserializer.deserialize(f); 72 | intent::IntentService intentService(intentServiceModel); 73 | 74 | std::string inputLine; 75 | 76 | ostream << "Hello I'm Bob\n" 77 | "I'm your virtual assistant and I will help you " 78 | "open or close the window, turn on and off the light " 79 | "or still lower or higher the heating system"; 80 | ostream << "Type 'q' and 'Enter' to quit.\n\n"; 81 | while(inputLine != "q") 82 | { 83 | ostream << "What do you want me to do?\n"; 84 | istream >> inputLine; 85 | 86 | if(inputLine != "q") 87 | { 88 | IntentService::Result result = intentService.evaluate(inputLine); 89 | if(result.found) 90 | { 91 | treatIntent(result, ostream); 92 | ostream << "\n"; 93 | } 94 | else 95 | { 96 | ostream << "I did not understand, please make it understandable to me :)\n"; 97 | } 98 | } 99 | } 100 | ostream << "See ya!"; 101 | } -------------------------------------------------------------------------------- /examples/Domotic/Domotic.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clement on 29/05/16. 3 | // 4 | 5 | #ifndef INTENT_DOMOTIC_HPP 6 | #define INTENT_DOMOTIC_HPP 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | class InputReader 13 | { 14 | public: 15 | virtual InputReader& operator>>(std::string &input) = 0; 16 | }; 17 | 18 | class OutputWriter 19 | { 20 | public: 21 | virtual OutputWriter& operator<<(const std::string &output) = 0; 22 | }; 23 | 24 | class Domotic 25 | { 26 | public: 27 | static void run(InputReader &inputReader, OutputWriter &outputWriter); 28 | }; 29 | 30 | 31 | #endif //INTENT_DOMOTIC_HPP 32 | -------------------------------------------------------------------------------- /examples/Domotic/intent.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "entities": { 4 | "@light": 5 | { 6 | "ligth": ["lamp", "lightbulb"] 7 | }, 8 | "@window": { 9 | "window": [] 10 | }, 11 | "@thermostat": { 12 | "thermostat": ["temperature", "heating", "heater"] 13 | }, 14 | "@higher_lower": { 15 | "lower": [], 16 | "higher": [] 17 | }, 18 | "@open_close": { 19 | "open": [], 20 | "close": [] 21 | }, 22 | "@on_off": { 23 | "on": [], 24 | "off": [] 25 | } 26 | }, 27 | 28 | "intents": [ 29 | { 30 | "id": "turn_the_light_X", 31 | "intent": [ 32 | "@light", 33 | "@on_off" 34 | ], 35 | "example": "Turn the light on" 36 | }, 37 | { 38 | "id": "turn_X_the_light", 39 | "intent": [ 40 | "@on_off", 41 | "@light" 42 | ], 43 | "example": "Turn on the light" 44 | }, 45 | { 46 | "id": "open_close_window", 47 | "intent": [ 48 | "@open_close", 49 | "@window" 50 | ], 51 | "example": "Open the window" 52 | }, 53 | { 54 | "id": "lower_higher_heating", 55 | "intent": [ 56 | "@higher_lower", 57 | "@thermostat" 58 | ], 59 | "example": "Lower the heating" 60 | } 61 | ] 62 | } 63 | 64 | -------------------------------------------------------------------------------- /examples/Domotic/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "intent/OpenIntent.hpp" 7 | 8 | #include "Domotic.hpp" 9 | 10 | using namespace intent; 11 | 12 | class StdOutputWriter : public OutputWriter 13 | { 14 | public: 15 | StdOutputWriter& operator<<(const std::string &output) 16 | { 17 | std::cout << output; 18 | return *this; 19 | } 20 | }; 21 | 22 | class StdInputReader : public InputReader 23 | { 24 | public: 25 | StdInputReader& operator>>(std::string &input) 26 | { 27 | std::getline(std::cin, input); 28 | return *this; 29 | } 30 | }; 31 | 32 | int main(int argc, char **argv) 33 | { 34 | StdOutputWriter outputWriter; 35 | StdInputReader inputReader; 36 | 37 | 38 | Domotic::run(inputReader, outputWriter); 39 | return 0; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /examples/Domotic/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | SET(TARGET domotic-test) 4 | 5 | SET(RES_FILES intent.json) 6 | 7 | COPY_RES_FILES(RES_FILES ${RES_FILES} SRC_DIR ../ DEST_DIR ${CMAKE_CURRENT_BINARY_DIR}) 8 | 9 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) 10 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thirdparty/json/src) 11 | INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/..) 12 | 13 | ADD_EXECUTABLE(${TARGET} ../Domotic.cpp DomoticTest.cpp) 14 | TARGET_LINK_LIBRARIES(${TARGET} gtest gmock gmock_main intent-static) 15 | -------------------------------------------------------------------------------- /examples/IntentViz/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | 4 | SET(TARGET intent-viz) 5 | 6 | SET(RES_FILES 7 | chatbot.json) 8 | 9 | COPY_RES_FILES(RES_FILES ${RES_FILES} DEST_DIR ${CMAKE_CURRENT_BINARY_DIR}) 10 | 11 | 12 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) 13 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thirdparty/json/src) 14 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thirdparty/spdlog/include) 15 | 16 | ADD_EXECUTABLE(${TARGET} main.cpp) 17 | TARGET_LINK_LIBRARIES(${TARGET} intent-static ${Boost_LIBRARIES}) 18 | -------------------------------------------------------------------------------- /examples/IntentViz/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "intent/OpenIntent.hpp" 7 | 8 | using namespace intent; 9 | 10 | 11 | 12 | int main(int argc, char **argv) 13 | { 14 | Deserializer deserializer; 15 | std::ifstream chatbot_json("chatbot.json"); 16 | 17 | ChatbotModel chatbotModel = deserializer.deserialize(chatbot_json); 18 | 19 | std::ofstream output_dot("output.dot"); 20 | 21 | intent::IntentStoryModelSerializer serializer; 22 | serializer.serialize(output_dot, chatbotModel.intentStoryServiceModel); 23 | 24 | std::cout << "Dot file generated!"; 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /examples/QueriesBar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | 4 | SET(TARGET queries-bar) 5 | 6 | SET(RES_FILES 7 | chatbot.json) 8 | 9 | COPY_RES_FILES(RES_FILES ${RES_FILES} DEST_DIR ${CMAKE_CURRENT_BINARY_DIR}) 10 | 11 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) 12 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thirdparty/json/src) 13 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thirdparty/spdlog/include) 14 | 15 | ADD_EXECUTABLE(${TARGET} main.cpp) 16 | TARGET_LINK_LIBRARIES(${TARGET} intent-static ${Boost_LIBRARIES}) 17 | -------------------------------------------------------------------------------- /examples/QueriesBar/chatbot.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "entities": { 4 | "@beverage": 5 | { 6 | "Coca-Cola": ["Coca", "Cola", "Coke"], 7 | "Kronenbourg": ["Kro"], 8 | "Heineken": ["Hein"], 9 | "Leffe": [], 10 | "Hoegarden": [], 11 | "1664": [], 12 | "Mojito": [], 13 | "Bloody-Mary":[] 14 | }, 15 | "@number": 16 | { 17 | "0": ["zero"], 18 | "1": ["un", "une"], 19 | "2": ["deux"], 20 | "3": ["trois"], 21 | "4": ["quatre"], 22 | "5": ["cinq"], 23 | "6": ["six"], 24 | "7": ["sept"], 25 | "8": ["huit"], 26 | "9": ["neuf"] 27 | }, 28 | "@quant": 29 | { 30 | "<": ["moins", "-"], 31 | ">": ["plus", "+"] 32 | }, 33 | "@question": 34 | { 35 | "Quel":["quoi", "quels"], 36 | "Combien":["cmb"] 37 | }, 38 | "@category": 39 | { 40 | "soft":["boisson non alcoolisées"], 41 | "biere":["mousse"], 42 | "cocktail":[] 43 | }, 44 | "@attribute": 45 | { 46 | "prix":["cout"] 47 | }, 48 | "@yes": 49 | { 50 | "ok":["yes"] 51 | } 52 | }, 53 | 54 | "intents": [ 55 | { 56 | "id": "beverage_query", 57 | "intent": [ 58 | "@quant", 59 | "@number" 60 | ], 61 | "example": "moins de 100 €" 62 | }, 63 | { 64 | "id": "price_query", 65 | "intent": [ 66 | "@question", 67 | "@number", 68 | "@beverage" 69 | ], 70 | "example": "Quel prix pour 1 biere?" 71 | }, 72 | { 73 | "id": "category_query", 74 | "intent": ["@question","@category", "@quant", "@number"], 75 | "example": "Quel sont les softs pour moins de 100" 76 | }, 77 | { 78 | "id": "ack", 79 | "intent":["@yes"], 80 | "example":"yes" 81 | } 82 | ], 83 | 84 | "chatbot": { 85 | "replies": { 86 | "beveragelist_reply": "Voici les boissons : ${beverages}", 87 | "price_reply": "Le prix est : ${price}€." 88 | }, 89 | "commands": ["#beveragequery", "#pricequery", "#categoryquery"], 90 | "actions": { 91 | "price_action": ["#pricequery", "price_reply"], 92 | "beverage_action": ["#beveragequery", "beveragelist_reply"], 93 | "category_action": ["#categoryquery", "beveragelist_reply"] 94 | } 95 | }, 96 | 97 | "intent_story": { 98 | "root": "init", 99 | "graph": 100 | { 101 | "init": 102 | { 103 | "price_query": "price_action", 104 | "beverage_query": "beverage_action", 105 | "category_query": "category_action" 106 | }, 107 | "price_action": 108 | { 109 | "ack":"init" 110 | }, 111 | "beverage_action": 112 | { 113 | "ack":"init" 114 | }, 115 | "category_action": 116 | { 117 | "ack":"init" 118 | } 119 | 120 | } 121 | } 122 | } 123 | 124 | -------------------------------------------------------------------------------- /include/intent/OpenIntent.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_OPENINTENT_HPP 42 | #define INTENT_OPENINTENT_HPP 43 | 44 | #include "intent/utils/Deserializer.hpp" 45 | #include "intent/utils/Logger.hpp" 46 | 47 | /* 48 | * Intent Service module 49 | */ 50 | #include "intent_service/IntentService.hpp" 51 | #include "intent_service/IntentServiceModel.hpp" 52 | 53 | /* 54 | * Intent Story Service module 55 | */ 56 | #include "intent/intent_story_service/IntentStoryService.hpp" 57 | #include "intent/intent_story_service/IntentStoryServiceModel.hpp" 58 | #include "intent/intent_story_service/IntentStoryModelSerializer.hpp" 59 | 60 | /* 61 | * Chatbot module 62 | */ 63 | #include "intent/chatbot/ChatbotFactory.hpp" 64 | #include "intent/chatbot/MultiSessionChatbot.hpp" 65 | #include "intent/chatbot/SingleSessionChatbot.hpp" 66 | 67 | #endif // INTENT_OPENINTENT_HPP 68 | -------------------------------------------------------------------------------- /include/intent/chatbot/ChatbotModel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_CHATBOTMODEL_HPP 42 | #define INTENT_CHATBOTMODEL_HPP 43 | 44 | #include "ChatbotActionModel.hpp" 45 | #include "intent/intent_story_service/IntentStoryServiceModel.hpp" 46 | 47 | namespace intent { 48 | /** 49 | * \brief A Chatbot model is a struct that combines a ChatbotActionModel and an 50 | * IntentStoryServiceModel. 51 | */ 52 | struct ChatbotModel { 53 | ChatbotActionModel::SharedPtr chatbotActionModel; 54 | IntentStoryServiceModel intentStoryServiceModel; 55 | }; 56 | } 57 | 58 | #endif // INTENT_CHATBOTMODEL_HPP 59 | -------------------------------------------------------------------------------- /include/intent/intent_service/IntentEncoder.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_INTENT_ENCODER_HPP 42 | #define INTENT_INTENT_ENCODER_HPP 43 | 44 | #include 45 | #include 46 | #include "IntentModel.hpp" 47 | 48 | namespace intent { 49 | 50 | /** 51 | * \brief Helper that encodes a list of entities into string. 52 | */ 53 | class IntentEncoder { 54 | public: 55 | /** 56 | * \brief Encodes the list of entities into a string. 57 | * \param entities The list of entities to encode. 58 | * \return The encoded string. 59 | */ 60 | static std::string encode(const std::vector& entities); 61 | static std::string encode(const IntentModel::Intent& intent); 62 | }; 63 | } 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /include/intent/intent_service/IntentServiceModel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_INTENTSERVICEMODEL_HPP 42 | #define INTENT_INTENTSERVICEMODEL_HPP 43 | 44 | #include "intent/intent_service/DictionaryModel.hpp" 45 | #include "intent/intent_service/IntentModel.hpp" 46 | 47 | namespace intent { 48 | /** 49 | * \brief Combination of a dictionary data model and an intent data model used 50 | * by the IntentService service. 51 | */ 52 | struct IntentServiceModel { 53 | /** 54 | * \brief The dictionary data model. 55 | */ 56 | DictionaryModel::SharedPtr dictionaryModel; 57 | 58 | /** 59 | * \brief The intent data model. 60 | */ 61 | IntentModel::SharedPtr intentModel; 62 | }; 63 | } 64 | 65 | #endif // INTENT_INTENTSERVICEMODEL_HPP 66 | -------------------------------------------------------------------------------- /include/intent/intent_service/SentenceTokenizer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_SENTENCE_TOKENIZER_HPP 42 | #define INTENT_SENTENCE_TOKENIZER_HPP 43 | 44 | #include 45 | #include 46 | 47 | #include "intent/intent_service/DictionaryModel.hpp" 48 | 49 | namespace intent { 50 | 51 | class SentenceTokenizer { 52 | public: 53 | SentenceTokenizer(const DictionaryModel& dictionaryModel); 54 | 55 | void tokenize(const std::string sentence, 56 | std::vector& tokens) const; 57 | 58 | private: 59 | std::vector m_regexpList; 60 | }; 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /include/intent/intent_story_service/IntentStoryModelSerializer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_INTENT_STORY_MODEL_SERIALIZER_HPP 42 | #define INTENT_INTENT_STORY_MODEL_SERIALIZER_HPP 43 | 44 | #include 45 | #include 46 | #include "intent/intent_story_service/IntentStoryServiceModel.hpp" 47 | 48 | namespace intent { 49 | class IntentStoryModelSerializer { 50 | public: 51 | void serialize(std::ostream& stream, 52 | const IntentStoryServiceModel& intentStoryServiceModel) const; 53 | }; 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/intent/intent_story_service/IntentStoryServiceModel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_INTENTSTORYSERVICEMODEL_HPP 42 | #define INTENT_INTENTSTORYSERVICEMODEL_HPP 43 | 44 | #include "intent/intent_service/IntentServiceModel.hpp" 45 | #include "IntentStoryModel.hpp" 46 | 47 | namespace intent { 48 | /** 49 | * \brief Combination of an intent service model and an intent story model used 50 | * by the IntentStoryService service. 51 | */ 52 | struct IntentStoryServiceModel { 53 | /** 54 | * \brief The intent service data model. 55 | */ 56 | IntentServiceModel intentServiceModel; 57 | 58 | /** 59 | * \brief The intent story data model. 60 | */ 61 | IntentStoryModel::SharedPtr intentStoryModel; 62 | }; 63 | } 64 | 65 | #endif // INTENT_INTENTSTORYSERVICEMODEL_HPP 66 | -------------------------------------------------------------------------------- /include/intent/interpreter/LineTagger.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_INTERPRETER_LINETAGGER_HPP 42 | #define INTENT_INTERPRETER_LINETAGGER_HPP 43 | 44 | #include "intent/interpreter/Interpreter.hpp" 45 | 46 | namespace intent { 47 | 48 | enum MARKER { 49 | ACTION = '#', 50 | SAYING = '-', 51 | STATE = '@', 52 | START_SCENARIO = '{', 53 | CLOSE_SCENARIO = '}', 54 | PLACE_HOLDER = '_', 55 | FALLBACK = '*' 56 | }; 57 | 58 | template 59 | bool isLine(const ScriptLine& line) { 60 | return line.content[0] == marker; 61 | } 62 | 63 | bool isMarkedLine(const ScriptLine& line); 64 | 65 | bool isLineComment(const ScriptLine& line); 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /include/intent/interpreter/ReplyTemplateInterpreter.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_REPLY_TEMPLATE_INTERPRETER_HPP 42 | #define INTENT_REPLY_TEMPLATE_INTERPRETER_HPP 43 | 44 | #include 45 | 46 | namespace intent { 47 | 48 | /** 49 | * \brief Interpreter for the reply templates of the OpenIntent chatbot 50 | * language. 51 | * 52 | * This helper adapt a reply template with OpenIntent chatbot language format 53 | * into reply template with 54 | * Chatbot model format. 55 | */ 56 | struct ReplyTemplateInterpreter { 57 | static const std::string ARG_MARKER; 58 | 59 | /** 60 | * \brief Replace placeholders ('_') by reply template variables ${i} 61 | * \param replyTemplate : reply template in interpreter format 62 | */ 63 | static void adapt(std::string& replyTemplate); 64 | }; 65 | } 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /include/intent/interpreter/ScenarioIndexer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_INTERPRETER_SCENARIOINDEXER_HPP 42 | #define INTENT_INTERPRETER_SCENARIOINDEXER_HPP 43 | 44 | #include "intent/interpreter/Interpreter.hpp" 45 | 46 | namespace intent { 47 | 48 | void indexScenario(const Scenario& scenario, 49 | InquiryToReplies& inquiryToReplies); 50 | 51 | void extractScenarios(const std::string& script, Scenarios& scenarios); 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/intent/interpreter/ScenarioTrimmer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_INTERPRETER_SCENARIOTRIMMER_HPP 42 | #define INTENT_INTERPRETER_SCENARIOTRIMMER_HPP 43 | 44 | #include "intent/interpreter/Interpreter.hpp" 45 | 46 | namespace intent { 47 | 48 | void trimComments(Scenarios& scenarios); 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/intent/interpreter/SentenceToIntentTranslator.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_SENTENCE_TO_INTENT_TRANSLATOR_HPP 42 | #define INTENT_SENTENCE_TO_INTENT_TRANSLATOR_HPP 43 | 44 | #include "Interpreter.hpp" 45 | 46 | namespace intent { 47 | /** 48 | * \brief Translator transforming sentences into intents by implicitly matching 49 | * entities. 50 | */ 51 | class SentenceToIntentTranslator { 52 | public: 53 | typedef IntentModel::IndexType IndexType; 54 | typedef IntentModel::Intent Intent; 55 | 56 | /** 57 | * \brief this method extracts entities from a sentence and returns a 58 | * signature 59 | * based on the set of entities 60 | * 61 | * \param line the string to match entities on 62 | * \param dictionaryModel the dictionary to match entities upon 63 | * \return 64 | */ 65 | 66 | static std::pair translate( 67 | const std::string& sentence, const DictionaryModel& dictionaryModel); 68 | }; 69 | } 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /include/intent/utils/Exception.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_EXCEPTION_HPP 42 | #define INTENT_EXCEPTION_HPP 43 | 44 | /** 45 | * @brief Exception class used by chatbot-api 46 | */ 47 | class Exception { 48 | public: 49 | /** 50 | * \brief The exception does not contain any error message. 51 | */ 52 | Exception() {} 53 | 54 | /** 55 | * \brief The exception does contain an error message. 56 | * \param errorMessage is the error message that caused the exception. 57 | */ 58 | Exception(const std::string errorMessage) : m_errorMessage(errorMessage) {} 59 | 60 | /** 61 | * \brief Returns the error message. 62 | * \return the error message. 63 | */ 64 | const std::string& message() const { return m_errorMessage; } 65 | 66 | private: 67 | std::string m_errorMessage; 68 | }; 69 | 70 | #endif // INTENT_EXCEPTION_HPP 71 | -------------------------------------------------------------------------------- /include/intent/utils/Levenshtein.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_LEVENSHTEIN_HPP 42 | #define INTENT_LEVENSHTEIN_HPP 43 | 44 | #include 45 | 46 | namespace intent { 47 | /** 48 | * \brief Implementation of the Levenshtein distance. 49 | * You can ask wikipedia for the details 50 | * https://en.wikipedia.org/wiki/Levenshtein_distance. 51 | */ 52 | class Levenshtein { 53 | public: 54 | /** 55 | * \brief Compute the Levenshtein distance between s1 and s2. 56 | * 57 | * \param s1 The first string to compute the Levenshtein distance against. 58 | * \param s2 The second string to compute the Levenshtein distance against. 59 | * \return The Levenshtein distance between s1 and s2. 60 | * 61 | * The implementation has been found on wikibooks: 62 | * https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance 63 | * 64 | */ 65 | static unsigned int distance(const std::string& s1, const std::string& s2); 66 | }; 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /include/intent/utils/Tokenizer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_TOKENIZER_HPP 42 | #define INTENT_TOKENIZER_HPP 43 | 44 | #include 45 | #include 46 | 47 | namespace intent { 48 | 49 | class Tokenizer { 50 | public: 51 | /* 52 | * \brief A string token. 53 | */ 54 | typedef std::string Token; 55 | 56 | /** 57 | * \brief A list of Tokens. 58 | */ 59 | typedef std::vector Tokens; 60 | 61 | Tokenizer(const std::string& m_delimiters, 62 | const std::vector& regexpList); 63 | 64 | void tokenize(const std::string& message, Tokens& tokens); 65 | 66 | private: 67 | const std::string m_delimiters; 68 | const std::vector m_regexpList; 69 | }; 70 | } 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /include/intent/utils/TrigramHelper.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #ifndef INTENT_TRIGRAMHELPER_HPP 42 | #define INTENT_TRIGRAMHELPER_HPP 43 | 44 | #include 45 | #include 46 | 47 | namespace intent { 48 | /** 49 | * \brief Helper class to perform operation on trigrams. 50 | */ 51 | class TrigramHelper { 52 | public: 53 | static void padLeft(std::string& s, size_t size, char c); 54 | 55 | static void padRight(std::string& s, size_t size, char c); 56 | 57 | /** 58 | * \brief Generate trigrams from input string 59 | * \param s The input string 60 | * \param out The output list of trigrams. 61 | */ 62 | static void generateTrigrams(const std::string& s, 63 | std::vector& out); 64 | }; 65 | } 66 | 67 | #endif // INTENT_TRIGRAMHELPER_HPP 68 | -------------------------------------------------------------------------------- /scripts/apply_format.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | CLANG='clang-format-3.7' 5 | CLANG_STYLE=Google 6 | 7 | directories=" 8 | src/ 9 | include/ 10 | " 11 | 12 | # script to copy the headers to all the source files and header files 13 | for f in $(find ${directories} -name '*.cpp' -or -name '*.hpp' ); do 14 | echo "Processed file $f" 15 | 16 | content=`${CLANG} -style=${CLANG_STYLE} $f` 17 | echo "$content" > $f 18 | 19 | done 20 | 21 | -------------------------------------------------------------------------------- /scripts/apply_format_and_license.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./scripts/apply_license.sh 4 | ./scripts/apply_format.sh 5 | 6 | cp README.md bindings/nodejs 7 | -------------------------------------------------------------------------------- /scripts/apply_license.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | license_file='./LICENSE' 4 | 5 | directories=" 6 | src/ 7 | include/ 8 | bindings/nodejs/src 9 | bindings/nodejs/include 10 | bindings/nodejs/lib 11 | bindings/nodejs/test 12 | test/tests 13 | test/mock 14 | " 15 | 16 | no_pattern="node_modules 17 | project-skeletons/chatbot/res/" 18 | 19 | license=`cat ${license_file}` 20 | header="/* 21 | |---------------------------------------------------------| 22 | | ___ ___ _ _ | 23 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 24 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 25 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 26 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 27 | | |_| | 28 | | | 29 | | - The users first... | 30 | | | 31 | | Authors: | 32 | | - Clement Michaud | 33 | | - Sergei Kireev | 34 | | | 35 | | Version: 1.0.0 | 36 | | | 37 | |---------------------------------------------------------| 38 | 39 | ${license} 40 | */ 41 | " 42 | 43 | # script to copy the headers to all the source files and header files 44 | for f in $(find ${directories} -name '*.cpp' -or -name '*.hpp' -or -name '*.js' ); do 45 | 46 | no_process=0 47 | 48 | # Filter out some files 49 | while read -r line; do 50 | no=`echo $f | grep "${line}"` 51 | 52 | if [ "$no" != "" ] 53 | then 54 | no_process=1 55 | fi 56 | done <<< "$no_pattern"; 57 | 58 | if [ "$no_process" -gt "0" ]; 59 | then 60 | #echo "$f skipped" 61 | continue; 62 | fi 63 | 64 | echo "Processed file $f" 65 | file_content=`cat $f` 66 | 67 | shebang=`echo "$file_content" | head -n 1 | grep "^#\!"` 68 | 69 | filtered=`echo "$file_content"` 70 | if [ ! -z "$shebang" ] 71 | then 72 | echo "Shebang detected" 73 | shebang=`echo "${shebang}"` 74 | filtered=`echo "$file_content" | tail -n +2` 75 | fi 76 | 77 | filtered=`echo "$filtered" | sed -r ':a;$!{N;ba};s|/\*[^*]*\*+([^/*][^*]*\*+)*/||'` 78 | filtered=`echo "$filtered" | sed ':a;N;$!ba;s/^\s*\([^\s]\)/\1/g'` 79 | 80 | #mv $f $f.old 81 | if [ ! -z "$shebang" ] 82 | then 83 | (echo "${shebang}"; echo "${header}${filtered}") > $f 84 | else 85 | echo "${header}${filtered}" > $f 86 | fi 87 | echo "License Header copied to $f" 88 | done 89 | 90 | -------------------------------------------------------------------------------- /scripts/build_and_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BUILD_DIR=build-dir 4 | 5 | FLAGS=$1 6 | 7 | 8 | if [ "$FLAGS" != "--skip-format" ] 9 | then 10 | 11 | # Apply license and format to check if it has been applied correctly before pushing the branch 12 | echo "Check format and license" 13 | ./scripts/apply_format_and_license.sh 14 | MODIFIED_FILES_COUNT=`git diff --name-only | wc -l` 15 | 16 | if [ "$MODIFIED_FILES_COUNT" -gt "0" ] 17 | then 18 | MODIFIED_FILES=`git diff --name-only` 19 | echo "Format or license has not been applied to the following files:" 20 | echo -e "${MODIFIED_FILES}" 21 | exit 1 22 | fi 23 | 24 | fi 25 | 26 | 27 | mkdir -p ${BUILD_DIR} 28 | cd ${BUILD_DIR} 29 | 30 | echo "Configuring..." 31 | cmake -G "Unix Makefiles" .. 32 | 33 | echo "Building..." 34 | make -j 4 35 | 36 | make run-all-tests 37 | 38 | 39 | -------------------------------------------------------------------------------- /scripts/build_and_test_with_docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker create --name open-intent-source-volume -v $(pwd):/src ubuntu:xenial /bin/false 4 | 5 | docker run --rm --volumes-from open-intent-source-volume -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker open-intent-build /src/scripts/build_and_test.sh 6 | -------------------------------------------------------------------------------- /scripts/deploy_npm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd bindings/nodejs 4 | 5 | version=`npm version patch --git-tag-version -m"Update npm version to %s"` 6 | 7 | git commit -m"npm version $version" package.json 8 | 9 | npm publish 10 | -------------------------------------------------------------------------------- /scripts/remove_old.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | directories=" 4 | src/ 5 | include/ 6 | bindings/nodejs/src 7 | bindings/nodejs/include 8 | bindings/nodejs/examples 9 | test/tests 10 | test/mock 11 | " 12 | 13 | # script to copy the headers to all the source files and header files 14 | for f in $(find ${directories} -name '*.old' ); do 15 | echo "Processed file $f" 16 | 17 | rm -rf $f 18 | 19 | done 20 | 21 | -------------------------------------------------------------------------------- /scripts/run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BUILD_DIR=build-dir 4 | 5 | cd ${BUILD_DIR} 6 | 7 | echo "Running tests" 8 | make run-all-tests 9 | 10 | echo "Running integration tests" 11 | make run-nodejs-integration-tests -------------------------------------------------------------------------------- /scripts/test_license.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | license_file='./LICENSE' 4 | 5 | license=`cat ${license_file}` 6 | header="/* 7 | |---------------------------------------------------------| 8 | | ___ ___ _ _ | 9 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 10 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 11 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 12 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 13 | | |_| | 14 | | | 15 | | - The users first... | 16 | | | 17 | | Authors: | 18 | | - Clement Michaud | 19 | | - Sergei Kireev | 20 | | | 21 | | Version: 1.0.0 | 22 | | | 23 | |---------------------------------------------------------| 24 | 25 | ${license} 26 | */ 27 | " 28 | 29 | f=$1 30 | 31 | echo "File selected $f" 32 | 33 | if [ ! -f "$f" ]; then 34 | echo "File not found!" 35 | exit 1 36 | fi 37 | 38 | remove_first_comment=`cat $f | sed -r ':a;$!{N;ba};s|/\*[^*]*\*+([^/*][^*]*\*+)*/||'` 39 | filtered=`echo "$remove_first_comment" | sed ':a;N;$!ba;s/^\s*\([^\s]\)/\1/g'` 40 | 41 | echo "${header}${filtered}" | tee test.file 42 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thirdparty/json/src) 4 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thirdparty/spdlog/include) 5 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) 6 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) 7 | 8 | SET(Boost_USE_STATIC_LIBS ON) 9 | set(Boost_USE_MULTITHREADED ON) 10 | set(Boost_USE_STATIC_RUNTIME OFF) 11 | FIND_PACKAGE(Boost COMPONENTS system thread filesystem REQUIRED) 12 | 13 | SET(COMMON_SOURCE_FILES 14 | chatbot/Chatbot.cpp 15 | chatbot/ChatbotFactory.cpp 16 | chatbot/SingleSessionChatbot.cpp 17 | interpreter/EdgeParser.cpp 18 | interpreter/SentenceToIntentTranslator.cpp 19 | interpreter/Interpreter.cpp 20 | interpreter/LineTagger.cpp 21 | interpreter/ReplyTemplateInterpreter.cpp 22 | interpreter/ScenarioIndexer.cpp 23 | interpreter/ScenarioTrimmer.cpp 24 | intent_service/EntitiesMatcher.cpp 25 | utils/Deserializer.cpp 26 | utils/Levenshtein.cpp 27 | utils/Logger.cpp 28 | utils/RegexMatcher.cpp 29 | utils/SingleCharacterDelimiterTokenizer.cpp 30 | utils/Tokenizer.cpp 31 | utils/TrigramHelper.cpp 32 | intent_service/Term.cpp 33 | intent_service/TermIndex.cpp 34 | intent_service/IntentEncoder.cpp 35 | intent_service/DictionaryModel.cpp 36 | intent_service/IntentModel.cpp 37 | intent_service/IntentMatcher.cpp 38 | intent_service/IntentService.cpp 39 | intent_service/SentenceTokenizer.cpp 40 | intent_story_service/IntentStoryService.cpp 41 | intent_story_service/IntentStoryModelSerializer.cpp 42 | ) 43 | 44 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -static") 45 | 46 | ADD_LIBRARY(${PROJECT_NAME}-static STATIC ${COMMON_SOURCE_FILES} ${HEADER_FILES}) 47 | TARGET_LINK_LIBRARIES(${PROJECT_NAME}-static pthread ${Boost_LIBRARIES}) 48 | 49 | if(GCOV_ENABLED AND CMAKE_BUILD_TYPE STREQUAL "Debug") 50 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -O0 -Wall -fprofile-arcs -ftest-coverage") 51 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -g -O0 -Wall -W -fprofile-arcs -ftest-coverage") 52 | SET(CMAKE_EXE_LINKER_FLAGS "-fprofile-arcs -ftest-coverage") 53 | 54 | SET(GCOV_LIBRARIES_OPTIONAL "gcov") 55 | TARGET_LINK_LIBRARIES(${PROJECT_NAME}-static ${GCOV_LIBRARIES_OPTIONAL}) 56 | ENDIF() 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/intent_service/DictionaryModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #include "intent/intent_service/DictionaryModel.hpp" 42 | #include "intent/utils/RegexMatcher.hpp" 43 | 44 | namespace intent { 45 | 46 | void DictionaryModel::initBuiltInEntities() { 47 | size_t numberOfRegexMarkers = RegexMatcher::REGEX_MARKERS.size(); 48 | for (size_t pos = 0; pos < numberOfRegexMarkers; ++pos) { 49 | Term term; 50 | term.entityId = 0xFFFF - pos; 51 | term.termId = 0xFFFF - pos; 52 | term.term = RegexMatcher::REGEX_MARKERS.substr(pos, 1); 53 | dictionary.pushTerm(term); 54 | } 55 | } 56 | 57 | DictionaryModel::DictionaryModel() { initBuiltInEntities(); } 58 | } 59 | -------------------------------------------------------------------------------- /src/intent_service/IntentModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | // 42 | // Created by clement on 10/05/16. 43 | // 44 | 45 | #include "intent/intent_service/IntentModel.hpp" 46 | 47 | #include 48 | #include 49 | #include 50 | 51 | namespace intent { 52 | std::ostream& operator<<(std::ostream& os, const IntentModel::Intent& intent) { 53 | std::stringstream ss; 54 | std::copy(intent.entities.begin(), intent.entities.end(), 55 | std::ostream_iterator(ss, ", ")); 56 | 57 | return os << "{ intent: \"" << ss.str() << "\"" 58 | << "example: \"" << intent.example << " }"; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/intent_service/SentenceTokenizer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #include "intent/intent_service/SentenceTokenizer.hpp" 42 | 43 | #include "boost/range/algorithm/copy.hpp" 44 | #include "boost/range/adaptor/map.hpp" 45 | 46 | #include "intent/utils/Tokenizer.hpp" 47 | 48 | namespace intent { 49 | SentenceTokenizer::SentenceTokenizer(const DictionaryModel& dictionaryModel) { 50 | boost::copy(dictionaryModel.regexesByEntityId | boost::adaptors::map_keys, 51 | std::back_inserter(m_regexpList)); 52 | } 53 | 54 | void SentenceTokenizer::tokenize(const std::string sentence, 55 | std::vector& tokens) const { 56 | Tokenizer tokenizer(".,:;!? '", m_regexpList); 57 | tokenizer.tokenize(sentence, tokens); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/intent_service/Term.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #include "intent/intent_service/Term.hpp" 42 | 43 | #include 44 | #include 45 | 46 | namespace intent { 47 | 48 | std::ostream& operator<<(std::ostream& os, const Term& obj) { 49 | std::stringstream ss; 50 | std::copy(obj.alias.begin(), obj.alias.end(), 51 | std::ostream_iterator(ss, ", ")); 52 | 53 | return os << "{ termId: " << obj.termId << ", " 54 | << "entityId: \"" << obj.entityId << "\", " 55 | << "term: \"" << obj.term << "\", " 56 | << "lowerCaseTerm: \"" << obj.lowerCaseTerm << "\", " 57 | << "alias: { " << ss.str() << " } }"; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/interpreter/LineTagger.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #include "intent/interpreter/LineTagger.hpp" 42 | 43 | namespace intent { 44 | 45 | bool isMarkedLine(const ScriptLine& line) { 46 | return isLine(line) || isLine(line) || 47 | isLine(line) || isLine(line) || 48 | isLine(line) || isLine(line) || 49 | isLine(line); 50 | } 51 | 52 | bool isLineComment(const ScriptLine& line) { 53 | if (line.content.size() < 2) return false; 54 | if (line.content.substr(0, 2) == "//") return true; 55 | return false; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/interpreter/ReplyTemplateInterpreter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #include "intent/interpreter/ReplyTemplateInterpreter.hpp" 42 | #include "intent/interpreter/Interpreter.hpp" 43 | 44 | namespace intent { 45 | 46 | const std::string ReplyTemplateInterpreter::ARG_MARKER("_"); 47 | 48 | void ReplyTemplateInterpreter::adapt(std::string& replyTemplate) { 49 | int counter = 0; 50 | for (size_t i = 0; i < replyTemplate.size(); ++i) { 51 | std::string templateArgMarker = "${" + std::to_string(counter) + "}"; 52 | if (replyTemplate.substr(i, ARG_MARKER.size()) == ARG_MARKER) { 53 | replyTemplate.replace(i, ARG_MARKER.size(), templateArgMarker); 54 | ++counter; 55 | i += templateArgMarker.size() - ARG_MARKER.size() - 1; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/interpreter/ScenarioTrimmer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #include "intent/interpreter/ScenarioTrimmer.hpp" 42 | 43 | #include 44 | 45 | #include "intent/interpreter/LineTagger.hpp" 46 | #include "intent/utils/SingleCharacterDelimiterTokenizer.hpp" 47 | 48 | namespace intent { 49 | 50 | void _trimComments(Scenario& scenario) { 51 | Scenario::iterator toEraseBegin = 52 | std::remove_if(scenario.begin(), scenario.end(), isLineComment); 53 | scenario.erase(toEraseBegin, scenario.end()); 54 | } 55 | 56 | void trimComments(Scenarios& scenarios) { 57 | std::for_each(scenarios.begin(), scenarios.end(), _trimComments); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/utils/Levenshtein.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | |---------------------------------------------------------| 3 | | ___ ___ _ _ | 4 | | / _ \ _ __ ___ _ __ |_ _|_ __ | |_ ___ _ __ | |_ | 5 | | | | | | '_ \ / _ \ '_ \ | || '_ \| __/ _ \ '_ \| __| | 6 | | | |_| | |_) | __/ | | || || | | | || __/ | | | |_ | 7 | | \___/| .__/ \___|_| |_|___|_| |_|\__\___|_| |_|\__| | 8 | | |_| | 9 | | | 10 | | - The users first... | 11 | | | 12 | | Authors: | 13 | | - Clement Michaud | 14 | | - Sergei Kireev | 15 | | | 16 | | Version: 1.0.0 | 17 | | | 18 | |---------------------------------------------------------| 19 | 20 | The MIT License (MIT) 21 | Copyright (c) 2016 - Clement Michaud, Sergei Kireev 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to deal 25 | in the Software without restriction, including without limitation the rights 26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, 38 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40 | */ 41 | #include "intent/utils/Levenshtein.hpp" 42 | #include 43 | 44 | namespace intent { 45 | 46 | unsigned int Levenshtein::distance(const std::string& s1, 47 | const std::string& s2) { 48 | const std::size_t len1 = s1.size(), len2 = s2.size(); 49 | std::vector> d(len1 + 1, 50 | std::vector(len2 + 1)); 51 | 52 | d[0][0] = 0; 53 | for (unsigned int i = 1; i <= len1; ++i) d[i][0] = i; 54 | for (unsigned int i = 1; i <= len2; ++i) d[0][i] = i; 55 | 56 | for (unsigned int i = 1; i <= len1; ++i) 57 | for (unsigned int j = 1; j <= len2; ++j) 58 | d[i][j] = std::min({d[i - 1][j] + 1, d[i][j - 1] + 1, 59 | d[i - 1][j - 1] + (s1[i - 1] == s2[j - 1] ? 0 : 1)}); 60 | return d[len1][len2]; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) 4 | 5 | ENABLE_TESTING() 6 | 7 | SET(UNIT_TEST_TARGET ${PROJECT_NAME}-test) 8 | SET(INTEGRATION_TEST_TARGET ${PROJECT_NAME}-integration-test) 9 | 10 | # JSON thirdparty 11 | INCLUDE_DIRECTORIES(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) 12 | INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) 13 | 14 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thirdparty/json/src) 15 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thirdparty/spdlog/include) 16 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) 17 | 18 | ADD_CUSTOM_TARGET(run-unit-tests-cpp 19 | DEPENDS intent-test 20 | COMMAND ${CMAKE_BINARY_DIR}/test/intent-test 21 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test 22 | ) 23 | 24 | SET(SOURCE_FILES 25 | launcher/main.cpp 26 | launcher/ResourceManager.cpp 27 | launcher/TestContext.cpp 28 | 29 | same_successive_intents/SameSuccessiveIntentsTest.cpp 30 | 31 | ChatbotFactoryTest.cpp 32 | ChatbotTest.cpp 33 | EntitiesMatcherTest.cpp 34 | DeserializerTest.cpp 35 | GraphTest.cpp 36 | IntentServiceTest.cpp 37 | IntentStoryServiceTest.cpp 38 | MultiSessionChatbotTest.cpp 39 | SingleCharacterDelimiterTokenizerTest.cpp 40 | TermIndexTest.cpp 41 | TokenizerTest.cpp 42 | TrigramUtilsTest.cpp 43 | SingleSessionChatbotTest.cpp 44 | IntentMatcherTest.cpp 45 | InterpreterTest.cpp 46 | IntentStoryModelSerializer.cpp 47 | ) 48 | 49 | SET(HEADER_FILES) 50 | 51 | INCLUDE_DIRECTORIES(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) 52 | 53 | if(GCOV_ENABLED) 54 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -Wall -fprofile-arcs -ftest-coverage") 55 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -Wall -W -fprofile-arcs -ftest-coverage") 56 | SET(CMAKE_EXE_LINKER_FLAGS "-fprofile-arcs -ftest-coverage") 57 | 58 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") 59 | include(CodeCoverage) 60 | setup_target_for_coverage(${UNIT_TEST_TARGET}_coverage ${UNIT_TEST_TARGET} coverage) 61 | endif() 62 | endif() 63 | 64 | add_definitions(-DRESSOURCES_DIRECTORY="${CMAKE_CURRENT_SOURCE_DIR}") 65 | 66 | ADD_EXECUTABLE(${UNIT_TEST_TARGET} ${SOURCE_FILES}) 67 | TARGET_LINK_LIBRARIES(${UNIT_TEST_TARGET} ${PROJECT_NAME}-static 68 | gtest 69 | gmock 70 | gcov 71 | ) 72 | 73 | -------------------------------------------------------------------------------- /test/launcher/ResourceManager.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clement on 05/05/16. 3 | // 4 | 5 | #include "ResourceManager.hpp" 6 | 7 | #include 8 | #include 9 | 10 | namespace intent 11 | { 12 | namespace test 13 | { 14 | ResourceManager::ResourceManager(const std::string &resourceDirectory) 15 | : m_resourceDirectory(resourceDirectory) 16 | { 17 | 18 | } 19 | 20 | std::string readFile(const boost::filesystem::path& filepath) 21 | { 22 | std::ifstream f(filepath.c_str()); 23 | bool exists = f.good(); 24 | 25 | if(exists) 26 | { 27 | f.open(filepath.c_str(), std::ifstream::in); 28 | std::istreambuf_iterator eos; 29 | std::string content(std::istreambuf_iterator(f), eos); 30 | return content; 31 | } 32 | else 33 | { 34 | throw ResourceManagerException(std::string("File \"") + filepath.c_str() + "\" does not exist"); 35 | } 36 | } 37 | 38 | void ResourceManager::registerFile(const ResourceId::Id &ressourceId, const std::string &filename) 39 | { 40 | boost::filesystem::path file(filename); 41 | boost::filesystem::path fullPath = m_resourceDirectory / file; 42 | 43 | m_resourcePaths[ressourceId] = fullPath.c_str(); 44 | m_fileResources[ressourceId] = readFile(fullPath); 45 | } 46 | 47 | const std::string& ResourceManager::getResource(const ResourceId::Id &ressourceId) const 48 | { 49 | std::unordered_map::const_iterator it = m_fileResources.find(ressourceId); 50 | if(it != m_fileResources.end()) 51 | { 52 | return it->second; 53 | } 54 | else 55 | { 56 | std::stringstream ss; 57 | ss << "Resource \"" << ressourceId << "\" not found"; 58 | throw ResourceManagerException(ss.str()); 59 | } 60 | } 61 | 62 | const std::string& ResourceManager::getResourcePath(const ResourceId::Id &ressourceId) const 63 | { 64 | std::unordered_map::const_iterator it = m_resourcePaths.find(ressourceId); 65 | if(it != m_fileResources.end()) 66 | { 67 | return it->second; 68 | } 69 | else 70 | { 71 | std::stringstream ss; 72 | ss << "Resource \"" << ressourceId << "\" not found"; 73 | throw ResourceManagerException(ss.str()); 74 | } 75 | } 76 | 77 | std::string ResourceManager::read(const std::string& filepath) const 78 | { 79 | boost::filesystem::path file(filepath); 80 | boost::filesystem::path fullPath = m_resourceDirectory / file; 81 | return readFile(fullPath); 82 | } 83 | 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /test/launcher/ResourceManager.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clement on 05/05/16. 3 | // 4 | 5 | #ifndef INTENT_RESSOURCEMANAGER_HPP 6 | #define INTENT_RESSOURCEMANAGER_HPP 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | namespace intent 14 | { 15 | namespace test 16 | { 17 | 18 | class ResourceManager 19 | { 20 | public: 21 | 22 | struct ResourceId 23 | { 24 | enum Id 25 | { 26 | INTENT_DICTIONARY_DESERIALIZATION_JSON_EXAMPLE, 27 | INTENT_DICTIONARY_DESERIALIZATION_INVALID_JSON_EXAMPLE, 28 | ORDER_BEVERAGE_INTENT_JSON, 29 | CHATBOT_MODEL_JSON, 30 | TEMPLATE_REPLIES_JSON, 31 | QUERY_MODE_JSON, 32 | INTERPRETER_MODEL, 33 | INTERPRETER_MODEL_W_ERRORS, 34 | CHATBOT_MODEL_JSON_WITHOUT_INTENT_STORY 35 | }; 36 | }; 37 | 38 | ResourceManager(const std::string &resourceDirectory); 39 | 40 | void registerFile(const ResourceId::Id &ressourceId, const std::string &filename); 41 | 42 | const std::string &getResource(const ResourceId::Id &ressourceId) const; 43 | const std::string &getResourcePath(const ResourceId::Id &ressourceId) const; 44 | 45 | std::string read(const std::string& filename) const; 46 | private: 47 | boost::filesystem::path m_resourceDirectory; 48 | std::unordered_map m_fileResources; 49 | std::unordered_map m_resourcePaths; 50 | }; 51 | 52 | 53 | class ResourceManagerException 54 | { 55 | public: 56 | ResourceManagerException(const std::string &message) 57 | : m_message(message) 58 | { 59 | }; 60 | 61 | const std::string message() const 62 | { 63 | return m_message; 64 | } 65 | 66 | private: 67 | std::string m_message; 68 | }; 69 | } 70 | } 71 | 72 | 73 | #endif //INTENT_RESSOURCEMANAGER_HPP 74 | -------------------------------------------------------------------------------- /test/launcher/TestContext.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clement on 05/05/16. 3 | // 4 | 5 | #include "TestContext.hpp" 6 | 7 | namespace intent 8 | { 9 | namespace test 10 | { 11 | const intent::test::TestContext *gTestContext = NULL; 12 | 13 | TestContext::TestContext(const std::string &resourceDirectory) 14 | : m_resourceManager(resourceDirectory) 15 | { 16 | } 17 | 18 | void TestContext::SetUp() 19 | { 20 | try 21 | { 22 | registerResources(); 23 | } 24 | catch(const intent::test::ResourceManagerException &e) 25 | { 26 | std::cout << e.message() << std::endl; 27 | throw e; 28 | } 29 | } 30 | 31 | void TestContext::TearDown() 32 | { 33 | } 34 | 35 | void TestContext::registerResources() 36 | { 37 | m_resourceManager.registerFile(ResourceManager::ResourceId::INTENT_DICTIONARY_DESERIALIZATION_JSON_EXAMPLE, 38 | "res/intent_dictionary_deserialization_test.json"); 39 | m_resourceManager.registerFile(ResourceManager::ResourceId::INTENT_DICTIONARY_DESERIALIZATION_INVALID_JSON_EXAMPLE, 40 | "res/intent_dictionary_deserialization_invalid_test.json"); 41 | m_resourceManager.registerFile(ResourceManager::ResourceId::ORDER_BEVERAGE_INTENT_JSON, 42 | "res/order_beverage_intent.json"); 43 | m_resourceManager.registerFile(ResourceManager::ResourceId::CHATBOT_MODEL_JSON, 44 | "res/chatbot_model.json"); 45 | m_resourceManager.registerFile(ResourceManager::ResourceId::QUERY_MODE_JSON, "res/queries_model.json"); 46 | m_resourceManager.registerFile(ResourceManager::ResourceId::TEMPLATE_REPLIES_JSON, 47 | "res/template_replies.json"); 48 | m_resourceManager.registerFile(ResourceManager::ResourceId::INTERPRETER_MODEL, 49 | "res/interpreter_model.txt"); 50 | m_resourceManager.registerFile(ResourceManager::ResourceId::INTERPRETER_MODEL_W_ERRORS, 51 | "res/interpreter_model_w_errors.txt"); 52 | m_resourceManager.registerFile(ResourceManager::ResourceId::CHATBOT_MODEL_JSON_WITHOUT_INTENT_STORY, 53 | "res/chatbot_model_without_intent_story.json"); 54 | } 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/launcher/TestContext.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clement on 05/05/16. 3 | // 4 | 5 | #ifndef INTENT_TEST_TESTCONTEXT_HPP 6 | #define INTENT_TEST_TESTCONTEXT_HPP 7 | 8 | #include 9 | 10 | #include "ResourceManager.hpp" 11 | 12 | namespace intent 13 | { 14 | namespace test 15 | { 16 | class TestContext : public ::testing::Environment 17 | { 18 | public: 19 | TestContext(const std::string &resourceDirectory); 20 | void SetUp(); 21 | void TearDown(); 22 | 23 | inline const intent::test::ResourceManager &getResourceManager() const { return m_resourceManager; } 24 | 25 | private: 26 | void registerResources(); 27 | 28 | intent::test::ResourceManager m_resourceManager; 29 | }; 30 | 31 | extern const intent::test::TestContext *gTestContext; 32 | } 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /test/launcher/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "TestContext.hpp" 4 | 5 | #include "intent/utils/Logger.hpp" 6 | 7 | int main(int argc, char **argv) 8 | { 9 | ::testing::InitGoogleTest(&argc, argv); 10 | 11 | // Adding environment that loads resource files 12 | const ::testing::Environment * env = ::testing::AddGlobalTestEnvironment(new intent::test::TestContext(RESSOURCES_DIRECTORY)); 13 | intent::test::gTestContext = static_cast(env); 14 | return RUN_ALL_TESTS(); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /test/res/chatbot_model_without_intent_story.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "entities": { 4 | "@waiter": 5 | { 6 | "Bob": ["Bobby"] 7 | }, 8 | "@beverage": 9 | { 10 | "Coca-Cola": ["Coca", "Cola", "Coke"], 11 | "Kronenbourg": ["Kro"], 12 | "Heineken": ["Hein"], 13 | "Café": [], 14 | "Arabica": [], 15 | "Mocha": [] 16 | }, 17 | "@number": 18 | { 19 | "0": ["zero"], 20 | "1": ["un", "une"], 21 | "2": ["deux"], 22 | "3": ["trois"], 23 | "4": ["quatre"], 24 | "5": ["cinq"], 25 | "6": ["six"], 26 | "7": ["sept"], 27 | "8": ["huit"], 28 | "9": ["neuf"] 29 | }, 30 | "@yes": 31 | { 32 | "oui": [] 33 | }, 34 | "@no": 35 | { 36 | "non": [] 37 | }, 38 | "@nothing": 39 | { 40 | "rien": [] 41 | }, 42 | "@price": 43 | { 44 | "regex":"^[0-9]+€$" 45 | } 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /test/res/intent_dictionary_deserialization_invalid_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1 3 | "entities": { 4 | "@beverage": { 5 | "Coca-Cola": [ 6 | "Coca", 7 | "Cola", 8 | "Coke" 9 | ], 10 | "Kronenbourg": ["Kro"], 11 | "Heineken": ["Hein"] 12 | } 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /test/res/intent_dictionary_deserialization_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "entities": { 4 | "@beverage": { 5 | "Coca-Cola": [ 6 | "Coca", 7 | "Cola", 8 | "Coke" 9 | ], 10 | "Kronenbourg": ["Kro"], 11 | "Heineken": ["Hein"] 12 | }, 13 | "@number": { 14 | "0": ["zero"], 15 | "1": ["un", "une"], 16 | "2": ["deux"], 17 | "3": ["trois"], 18 | "4": ["quatre"], 19 | "5": ["cinq"], 20 | "6": ["six"], 21 | "7": ["sept"], 22 | "8": ["huit"], 23 | "9": ["neuf"] 24 | }, 25 | "@phonenumber": { 26 | "regex":"^[0-9]{10,}$" 27 | } 28 | }, 29 | 30 | "intents": [ 31 | { 32 | "id": "order1", 33 | "intent": [ 34 | "@number", 35 | "@beverage" 36 | ], 37 | "example": "Je veux 1 Coca." 38 | }, 39 | { 40 | "id": "order2", 41 | "intent": [ 42 | "@number:softnumber", 43 | "@beverage:soft", 44 | "@number:alcoholnumber", 45 | "@beverage:alcohol" 46 | ], 47 | "example": "Je veux 1 Coca et 1 bière" 48 | }, 49 | { 50 | "id": "order_no_number", 51 | "intent": [ 52 | "@beverage", 53 | "@beverage" 54 | ], 55 | "example": "Je veux du @beverage et du @beverage" 56 | }, 57 | { 58 | "id": "order3", 59 | "intent": [ 60 | "@number", 61 | "@number", 62 | "@beverage" 63 | ], 64 | "example": "Je veux 1 1 Heineken" 65 | } 66 | ], 67 | 68 | 69 | "replies": [ 70 | { 71 | "id": "pay_2_conso", 72 | "reply": "Veuillez régler vos 2 consommations." 73 | }, 74 | { 75 | "id": "credit_card", 76 | "reply": "Sortez votre carte bancaire." 77 | }, 78 | { 79 | "id": "how_many", 80 | "reply": "Combien en voulez-vous ?" 81 | } 82 | ], 83 | 84 | "intent_story": { 85 | "root": "root", 86 | "graph": { 87 | "root": { 88 | "order1": "credit_card", 89 | "order2": "pay_2_conso", 90 | "order_no_number": "how_many" 91 | } 92 | } 93 | } 94 | } 95 | 96 | -------------------------------------------------------------------------------- /test/res/interpreter_model.txt: -------------------------------------------------------------------------------- 1 | { 2 | @root 3 | -Bob! 4 | #wake 5 | *Je n'ai pas compris votre demande 6 | -Que puis-je vous offrir ? 7 | 8 | @wait_order 9 | -Je voudrais une kro 10 | 11 | //Roses are red 12 | #append_order1 13 | 14 | //Violets are blue 15 | *Soyez le plus précis possible 16 | 17 | //This is a comment 18 | -Vous-voulez quelque chose d'autre ? 19 | //and this is too! 20 | 21 | @wait_another_order 22 | -Je voudrais une kro 23 | et un coca 24 | #append_order2 25 | -Vous-voulez quelque 26 | chose d'autre ? 27 | 28 | @wait_another_order 29 | -Je voudrais une kro 30 | #append_order1 31 | -Vous-voulez quelque chose d'autre ? 32 | 33 | @wait_another_order 34 | -Rien 35 | #grab_it 36 | -Veuillez récupérer vos consommations au bar. Vous devrez payer _. 37 | 38 | @bye 39 | } 40 | 41 | { 42 | @wait_order 43 | -Je voudrais une kro et un coca 44 | #append_order2 45 | -Vous-voulez quelque chose d'autre ? 46 | @wait_another_order 47 | } 48 | 49 | { 50 | @wait_order 51 | -Rien 52 | #bye 53 | -Au revoir et à bientôt. 54 | @bye 55 | } 56 | -------------------------------------------------------------------------------- /test/res/interpreter_model_w_errors.txt: -------------------------------------------------------------------------------- 1 | { 2 | _root 3 | -Bob! 4 | _wake 5 | *Je n'ai pas compris votre demande 6 | -Que puis-je vous offrir ? 7 | @bye 8 | } 9 | 10 | -------------------------------------------------------------------------------- /test/res/order_beverage_intent.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "entities": { 4 | "@waiter": 5 | { 6 | "Bob": ["Bobby"] 7 | }, 8 | "@beverage": 9 | { 10 | "Coca-Cola": ["Coca", "Cola", "Coke"], 11 | "Kronenbourg": ["Kro"], 12 | "Heineken": ["Hein"], 13 | "Café": [], 14 | "Arabica": [], 15 | "Mocha": [], 16 | "Eau de vie": [], 17 | "Eau de Zilia": [] 18 | }, 19 | "@number": 20 | { 21 | "0": ["zero"], 22 | "1": ["un", "une"], 23 | "2": ["deux"], 24 | "3": ["trois"], 25 | "4": ["quatre"], 26 | "5": ["cinq"], 27 | "6": ["six"], 28 | "7": ["sept"], 29 | "8": ["huit"], 30 | "9": ["neuf"] 31 | }, 32 | "@yes": 33 | { 34 | "oui": [] 35 | }, 36 | "@no": 37 | { 38 | "non": [] 39 | }, 40 | "@nothing": 41 | { 42 | "rien": [] 43 | } 44 | }, 45 | 46 | 47 | "intents": [ 48 | { 49 | "id": "order1", 50 | "intent": [ 51 | "@number", 52 | "@beverage" 53 | ], 54 | "example": "Je veux 1 Coca." 55 | }, 56 | { 57 | "id": "order2", 58 | "intent": [ 59 | "@number", 60 | "@beverage", 61 | "@number", 62 | "@beverage" 63 | ], 64 | "example": "Je veux 1 Coca et 1 bière" 65 | }, 66 | { 67 | "id": "yes", 68 | "intent": ["@yes"], 69 | "example": "Oui" 70 | }, 71 | { 72 | "id": "no", 73 | "intent": ["@no"], 74 | "example": "Non" 75 | }, 76 | { 77 | "id": "nothing", 78 | "intent": ["@nothing"], 79 | "example": "Rien" 80 | }, 81 | { 82 | "id": "ask_waiter", 83 | "intent": ["@waiter"], 84 | "example": "Bob!" 85 | } 86 | ], 87 | 88 | "intent_story": { 89 | "root": "init", 90 | "graph": { 91 | "init": { 92 | "ask_waiter": "wait_order" 93 | }, 94 | "wait_order": { 95 | "order1:append_order1": "wait_another_order", 96 | "order2:append_order2": "wait_another_order", 97 | "nothing": "init" 98 | }, 99 | "wait_another_order": { 100 | "order1:append_order1": "wait_another_order", 101 | "order2:append_order2": "wait_another_order", 102 | "nothing": "init" 103 | } 104 | } 105 | } 106 | } 107 | 108 | -------------------------------------------------------------------------------- /test/res/queries_model.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "entities": { 4 | "@beverage": 5 | { 6 | "Coca-Cola": ["Coca", "Cola", "Coke"], 7 | "Kronenbourg": ["Kro"], 8 | "Heineken": ["Hein"], 9 | "Leffe": [], 10 | "Hoegarden": [], 11 | "1664": [], 12 | "Mojito": [], 13 | "Bloody-Mary":[] 14 | }, 15 | "@number": 16 | { 17 | "0": ["zero"], 18 | "1": ["un", "une"], 19 | "2": ["deux"], 20 | "3": ["trois"], 21 | "4": ["quatre"], 22 | "5": ["cinq"], 23 | "6": ["six"], 24 | "7": ["sept"], 25 | "8": ["huit"], 26 | "9": ["neuf"] 27 | }, 28 | "@less": 29 | { 30 | "<": ["moins", "-"], 31 | ">": ["plus", "+"] 32 | }, 33 | "@question": 34 | { 35 | "Quel":["quoi"], 36 | "Combien":["cmb"] 37 | }, 38 | "@category": 39 | { 40 | "soft":["boisson non alcoolisées"], 41 | "biere":["mousse"], 42 | "cocktail":[] 43 | }, 44 | "@attribute": 45 | { 46 | "prix":["cout"] 47 | }, 48 | "@yes": 49 | { 50 | "ok":["yes"] 51 | } 52 | }, 53 | 54 | "intents": [ 55 | { 56 | "id": "beverage_query", 57 | "intent": [ 58 | "@less", 59 | "@number" 60 | ], 61 | "example": "moins de 100 €" 62 | }, 63 | { 64 | "id": "price_query", 65 | "intent": [ 66 | "@question", 67 | "@number", 68 | "@beverage" 69 | ], 70 | "example": "Quel prix pour 1 biere?" 71 | }, 72 | { 73 | "id": "category_query", 74 | "intent": ["@question", "@category", "@less", "@number"], 75 | "example": "Quels sont les softs pour moins de 100" 76 | }, 77 | { 78 | "id": "ack", 79 | "intent":["@yes"], 80 | "example":"yes" 81 | } 82 | ], 83 | 84 | "chatbot": { 85 | "replies": { 86 | "beveragelist_reply": "Voici les boissons : ${beverages}", 87 | "price_reply": "Le prix est : ${price}€." 88 | }, 89 | "replies_by_state_action": { 90 | "init": { 91 | "price_action": ["price_reply"], 92 | "beverage_action": ["beveragelist_reply"], 93 | "category_action": ["beveragelist_reply"] 94 | } 95 | } 96 | }, 97 | 98 | "intent_story": { 99 | "root": "init", 100 | "graph": 101 | { 102 | "init": 103 | { 104 | "price_query:price_action": "init", 105 | "beverage_query:beverage_action": "init", 106 | "category_query:category_action": "init" 107 | } 108 | } 109 | } 110 | } 111 | 112 | -------------------------------------------------------------------------------- /test/same_successive_intents/SameSuccessiveIntentsTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "launcher/TestContext.hpp" 5 | #include "json.hpp" 6 | 7 | #include "intent/utils/Deserializer.hpp" 8 | #include "intent/chatbot/SingleSessionChatbot.hpp" 9 | #include "intent/interpreter/Interpreter.hpp" 10 | 11 | #include "mock/ChatbotMock.hpp" 12 | 13 | using namespace ::testing; 14 | 15 | namespace intent 16 | { 17 | namespace test 18 | { 19 | class SameSuccessiveIntentsTest : public ::testing::Test 20 | { 21 | public: 22 | void SetUp() 23 | { 24 | const intent::test::ResourceManager &resourceManager = intent::test::gTestContext->getResourceManager(); 25 | 26 | std::string dictionary = resourceManager.read("same_successive_intents/res/dictionary.json"); 27 | std::string script = resourceManager.read("same_successive_intents/res/script.txt"); 28 | 29 | std::stringstream ss; 30 | ss << dictionary; 31 | 32 | Deserializer deserializer; 33 | m_chatbotModel.intentStoryServiceModel.intentServiceModel.dictionaryModel = 34 | deserializer.deserialize(ss); 35 | 36 | //finally we build the model 37 | InterpreterFeedback feedback; 38 | m_chatbotModel = Interpreter::build( 39 | script, m_chatbotModel.intentStoryServiceModel.intentServiceModel.dictionaryModel, feedback); 40 | } 41 | 42 | ChatbotModel m_chatbotModel; 43 | }; 44 | 45 | 46 | TEST_F(SameSuccessiveIntentsTest, do_not_skip_any_intent) 47 | { 48 | Chatbot::UserDefinedActionHandler::SharedPtr userDefinedActionHandler( 49 | new NiceMock()); 50 | 51 | SingleSessionChatbot chatbot(m_chatbotModel, userDefinedActionHandler); 52 | 53 | std::vector reply1 = chatbot.treatMessage("Salut"); 54 | std::vector reply2 = chatbot.treatMessage("Coucou"); 55 | std::vector reply3 = chatbot.treatMessage("Coucou"); 56 | 57 | EXPECT_THAT(reply1, ElementsAre("Salut, je suis dans l'état 1")); 58 | EXPECT_THAT(reply2, ElementsAre("Salut, je suis dans l'état 2")); 59 | EXPECT_THAT(reply3, ElementsAre("Salut, je suis dans l'état 1")); 60 | } 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /test/same_successive_intents/res/dictionary.json: -------------------------------------------------------------------------------- 1 | { 2 | "entities": { 3 | "greetings": { 4 | "bonjour": ["hello", "hi", "salut", "hey", "coucou"] 5 | }, 6 | "yes": { 7 | "yes": [] 8 | }, 9 | "no": { 10 | "no": [] 11 | }, 12 | "exhibition": { 13 | "salon": [] 14 | }, 15 | "eat": { 16 | "manger": [] 17 | }, 18 | "drink": { 19 | "boire": [] 20 | }, 21 | "information": { 22 | "information": [] 23 | }, 24 | "prices": { 25 | "prix": ["tarifs"] 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /test/same_successive_intents/res/script.txt: -------------------------------------------------------------------------------- 1 | { 2 | @root 3 | -Salut 4 | #no_action 5 | *Pas compris 6 | -Salut, je suis dans l'état 1 7 | @search 8 | -Coucou 9 | #no_action 10 | -Salut, je suis dans l'état 2 11 | @root 12 | } 13 | 14 | -------------------------------------------------------------------------------- /test/same_successive_intents/res/user_commands.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = {} 3 | 4 | -------------------------------------------------------------------------------- /thirdparty/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | 3 | ADD_SUBDIRECTORY(googletest) 4 | ADD_SUBDIRECTORY(json) --------------------------------------------------------------------------------