chatscript
by Giorgio Robino
通过乔治·罗宾诺(Giorgio Robino)
如何使用ChatScript构建您的第一个聊天机器人 (How to build your first chatbot using ChatScript)
10–10–2018: article updated with new github repo url.
2018年10月10日:文章更新为新的github repo url 。
Chatbots can help you get things done right inside chat tools like Facebook Messenger, Telegram Messenger, Slack, etc, etc. Just say the word and your chatbot will deploy your latest build, or order you a pizza.
聊天机器人可以帮助您在诸如Facebook Messenger,Telegram Messenger,Slack等聊天工具中完成工作。只需说出单词,您的聊天机器人就会部署您的最新版本,或为您订购披萨。
And there’s a special tool for building chatbots that’s been around for quite some time. It’s called ChatScript. And like Slack, it started out as just a small part of a video game.
还有一个用于构建聊天机器人的特殊工具已经存在了很长时间。 它称为ChatScript。 和Slack一样,它最初只是视频游戏的一小部分。
Back in 2009, Bruce Wilcox was working as a game developer and artificial intelligence researcher. His wife, Sue Wilcox, wanted to model virtual characters for her interactive fiction games. Together, they built what ultimately became ChatScript.
早在2009年, 布鲁斯·威尔科克斯 ( Bruce Wilcox )担任游戏开发人员和人工智能研究员。 他的妻子苏·威尔科克斯 ( Sue Wilcox )希望为她的互动小说游戏建模虚拟角色。 他们一起建立了最终成为ChatScript的文件。
This natural language processing engine + dialog flow scripting platform helped Bruce win the Loebner AI Prize three times.
这个自然语言处理引擎+对话流程脚本平台帮助布鲁斯三度获得了Loebner AI奖 。
Bruce still develops and maintains the project today. It’s written in C and C++, and is open source. In fact, version 6.8 just came out a few weeks ago.
布鲁斯今天仍在开发和维护该项目。 它是用C和C ++编写的,并且是开源的。 实际上,6.8版本是几周前发布的。
ChatScript is one of few OPENSOURCE chatbots NLProc engines!
ChatScript是少数OPENSOURCE聊天机器人NLProc引擎之一!
Let’s dive into the basics of ChatScript and meet a chatbot named Harry.
让我们深入探讨ChatScript的基础知识,并遇到一个名为Harry的聊天机器人。
安装ChatScript (Installing ChatScript)
Some of these steps may be a bit different depending on what operating system you’re using. I’m using Linux. You don’t actually have to go through these steps to enjoy this article if you don’t want to. Just read along.
其中某些步骤可能会有所不同,具体取决于您所使用的操作系统。 我正在使用Linux 。 如果不想,您实际上不必执行这些步骤即可享受本文的乐趣。 只是阅读。
步骤1:在本地计算机上安装系统组件 (Step 1: Install the system components on your local computer)
First of all clone the ChatScript GitHub repository:
首先克隆ChatScript GitHub存储库:
$ git clone https://github.com/ChatScript/ChatScript
This will create a ChatScript directory, which will contain these subdirectories:
这将创建一个ChatScript目录,其中将包含以下子目录:
$ cd ChatScript/$ ls -d1 */
BINARIES/DICT/DOCUMENTATION/LINUX/LIVEDATA/LOEBNERVS2010/LOGS/MAC/RAWDATA/REGRESS/SERVER BATCH FILES/SRC/SUBLIME TEXT EDITOR/TMP/TOPIC/USERS/VERIFY/VS2010/VS2015/WEBINTERFACE/
DOCUMENTATION contains wiki documentation files.
文档包含Wiki文档文件 。
BTW, I personally contributed to update all the original documentation in markdown format to be read online and from command line when developing.❤
顺便说一句,我个人致力于以markdown格式更新所有原始文档,以便在开发时从命令行和命令行读取。
- RAWDATA contains a subdirectory for each bot. By default, the platform comes with a default bot named Harry, who is located at RAWDATA/HARRY. RAWDATA包含每个bot的子目录。 默认情况下,该平台附带一个名为Harry的默认bot,该机器人位于RAWDATA / HARRY。
BTW, please remember to set LinuxChatScript64 executable:
顺便说一句,请记住设置LinuxChatScript64可执行文件:
$ chmod +x ChatScript/BINARIES/LinuxChatScript64
Note: obviously here above I’ considering the Linux OS environment.
注意:显然,在上面我在考虑Linux OS环境。
More info about Linux, MacOS or Windows installation here.
有关Linux,MacOS或Windows安装的更多信息,请参见此处 。
步骤2:以独立模式运行CS引擎: (Step 2: To run CS engine in standalone mode:)
$ BINARIES/LinuxChatScript64 local
Running the engine will launch Harry, with whom we can then talk:
运行引擎将启动Harry,然后我们可以与他交谈:
ChatScript EVSERVER Version 6.8 64 bit LINUX compiled Aug 16 2016 17:35:43 host=localParams: dict:720895 fact:800000 text:70000kb hash:50000 buffer:22x80kb cache:1x5000kb userfacts:100WordNet: dict=201350 fact=85710 stext=12703744 Jul26'16-21:58:46Build0: dict=67726 fact=130289 stext=1145656 Jul31'16-13:45:49 0Build1: dict=167 fact=15 stext=211304 Jul31'16-13:45:44 harryUsed 53MB: dict 269,244 (23693kb) hashdepth 18/1 fact 216,014 (8640kb) text 14183kb buffer (1760kb) cache (5000kb) POS: 918 (29kb)Free 79MB: dict 451,651 hash 924 fact 583,986 text 55,816KB
Enter user name: giorgio
HARRY: Welcome backgiorgio: > what is your name ?HARRY: My name is Harry.giorgio: > who is Bruce Wilcox?HARRY: Bruce Wilcox (born 1951) is an artificial intelligence programmer.giorgio: > ok, I have to goHARRY: Indeed.giorgio: > :quitExiting ChatScript via Quit$
步骤3:编码和调试您的chatbot脚本 (Step 3: Code and debug your chatbot scripts)
Standalone mode makes for an excellent ChatScript development environment. It allows you to run interactive conversations, then interact with them using :commands. This is a special set of interactive command tools for testing and debugging your dialogs during the development and debug phase.
独立模式可提供出色的ChatScript开发环境。 它允许您运行交互式对话,然后使用:commands与之交互。 这是一组特殊的交互式命令工具,用于在开发和调试阶段测试和调试对话框。
Here are a few example commands:
以下是一些示例命令:
# recompile the bot Harry and reset the status of conversations with user giorgio
giorgio: > :build Harry giorgio: > :reset
# request statistics about topic ~pets
giorgio: > :topicstats ~pets ~pets gambits 2 responders 2 rejoinders 5 empties 0Concepts 1860 Topics 1 rules 9 empties 0 gambits 2 responders 2 (?: 2 s: 0 u: 0) rejoinders 5
# conversation ...
giorgio: > do you like snakes?HARRY: I love pythons except ^"Python" (the programming language)
# ask the reason why a rule fired
giorgio: > :why~pets.2.0.5.9.0 ?: ( << you like snake >> ) I love pythons except Python ( the programming language ) via ~control.5.9.0 u: ( ) $$currenttopic = %topic ^if 00m( %response 0 ) 00I{ ^nofail ( TOPIC ^rejoinder ( ) ...
Note that you can run :commands to show the full list of available commands.
请注意,您可以运行:commands以显示可用命令的完整列表。
Topics are contained in specific files. For example, the ~pets topic code is contained in pets.top file, which looks like this:
主题包含在特定文件中。 例如,〜 宠物主题代码包含在pets.top文件,它看起来像这样:
topic: ~pets (dog cat pet animal bird fish snake)
?: ( << you like snake >> ) I love pythons except ^"Python" (the programming language)
?: ( << you ~like ~animals >> ) I love all animals.
t: Do you have any pets? #! yes a: ( ~yes ) Great. You like animals.
#! no a: ( ~no ) You don’t like animals?
#! I have two parrots a: ( parrots ) Birds are nice.
#! I have a cat a: ( cat ) I prefer dogs
#! I have a canary a: ( [parrot bird canary finch swallow] ) Birds are nice.
t: I have a dog.
ChatScript is a rule-based engine, where rules are created by humans writers in program scripts through a process called dialog flow scripting. These use a scripting metalanguage (simply called a “script”) as their source code.
ChatScript是一个基于规则的引擎,其中的规则是由人类编写者通过称为对话框流脚本的过程在程序脚本中创建的。 它们使用脚本语言(简称为“脚本”)作为其源代码。
Here what a ChatScript script file looks like:
这里的ChatScript脚本文件如下所示:
## file: food.top#
topic: ~food []
#! I like spinachss: ( I like spinach ) Are you a fan of the Popeye cartoons?
a: ( ~yes ) I used to watch him as a child. Did you lust after Olive Oyl? b: ( ~no ) Me neither. She was too skinny. b: ( ~yes ) You probably like skinny models.
a: ( ~no ) What cartoons do you watch? b: ( none ) You lead a deprived life. b: ( Mickey Mouse ) The Disney icon.
#! I often eat chickenu: ( ![ not never rarely ] I * ~ingest * ~meat ) You eat meat.
u: ( !~negativeWords I * ~like * ~meat ) You like meat.
?: (do you eat _ [ ham eggs bacon]) I eat ‘_0
?: (do you like _* or _*) I don’t like ‘_0 so I guess that means I prefer ‘_1.
s: ( ~like ~fruit ![~animal _bear] ) Vegan, you too...
?: (do you eat _~meat) No, I hate _0.
s: ( I eat _*1 >) $food = ‘_0 I eat oysters.
You can define your bot’s dialog flows with a script stored as a normal text file. This is much simpler than methods that other chatbot tools use, which often involve browser-based user interfaces, JSON, or XML.
您可以使用存储为普通文本文件的脚本来定义机器人的对话框流。 这比其他chatbot工具使用的方法要简单得多,其他聊天机器人工具通常使用基于浏览器的用户界面,JSON或XML。
Writing your scripts as a text files gives you full control over your dialog flows. You a can easily process and upgrade your conversational code with back-end scripts and tools.
将脚本编写为文本文件可让您完全控制对话框流。 您可以使用后端脚本和工具轻松地处理和升级会话代码。
For example, you could automatically update ChatScript dialog rules based on records in your database.
例如,您可以根据数据库中的记录自动更新ChatScript对话框规则。
You could even use machine learning tools to mine conversations logs. This could reveal all kinds of opportunities for you to improve your dialog flows.
您甚至可以使用机器学习工具来挖掘对话日志。 这可以为您揭示各种改善对话流程的机会。
But these are topics for a future ChatScript article. I’ll leave you to go play with ChatScript on your own.
但是,这些是以后的ChatScript文章的主题。 我会让你自己去玩ChatScript。
Please contribute to its open source codebase, and star it on GitHub!?????
ChatScript/ChatScriptContribute to ChatScript/ChatScript development by creating an account on GitHub.github.com
ChatScript / ChatScript 通过在GitHub上创建一个帐户来促进ChatScript / ChatScript的开发。 github.com
翻译自: https://www.freecodecamp.org/news/chatscript-for-beginners-chatbots-developers-c58bb591da8/
chatscript