NLP Code Snippets NodeJS
我正在使用talkify库在NodeJS中编写应用程序。应用程序的要点是成为聊天机器人。机器人的部分功能是获取代码(一种封闭的源语言)片段,通过REST API处理它们,并返回结果。
我已经能够使用talkify创建一些简单的技能,它工作正常。我的主要问题是如何实现我的机器人来解释给定技能中单引号之间的代码片段?
我无论如何都不会与talkify联系在一起。如果某人有一个更适合我的用例的建议,那么我愿意改变。
我到目前为止的守则
// Core dependency
const talkify = require('talkify');
const Bot = talkify.Bot;
// Types dependencies
const BotTypes = talkify.BotTypes;
const Message = BotTypes.Message;
const SingleLineMessage = BotTypes.SingleLineMessage;
const MultiLineMessage = BotTypes.MultiLineMessage;
// Skills dependencies
const Skill = BotTypes.Skill;
// Training dependencies
const TrainingDocument = BotTypes.TrainingDocument;
const bot = new Bot();
bot.trainAll([
new TrainingDocument('how_many_endpoints', 'How many endpoints are there?'),
new TrainingDocument('how_many_endpoints', 'How many endpoints are there')
], function() {});
var howManyAction = function(context, request, response, next) {
response.message = new SingleLineMessage(function() {
var x = someWork();
return x;
});
next();
};
var howSkill = new Skill('how_skill', 'how_are_you', howAction);
bot.addSkill(howSkill);
var resolved = function(err, messages) {
if(err) return console.error(err);
return console.log(messages);
};
bot.resolve(123, TEXT_FROM_CHAT, resolved);
当我问到我想要多少个端点时,上面的工作有效但是对于更复杂的句子它不起作用,例如,我可能想说
“执行以下'这是封闭的源代码,我将解析它的服务器端'”
如何将“执行以下内容”与规则匹配并将单引号内的字符串作为另一个变量?据我所知,talkify库培训文档必须与其解析的文本相匹配。
例
培训文件
execute the following
要匹配的文字
execute the following <~ Match
execute the following 'foo bar' <~ No match
execute the following, <~ No match
回答如下:
您可以使用简单的正则表达式预处理文本以提取和删除任何引用的短语:
/\'[^\']*\'/g
看到它在这里运行:https://regex101/r/eUe7n3/1
希望能帮助到你。
NLP Code Snippets NodeJS
我正在使用talkify库在NodeJS中编写应用程序。应用程序的要点是成为聊天机器人。机器人的部分功能是获取代码(一种封闭的源语言)片段,通过REST API处理它们,并返回结果。
我已经能够使用talkify创建一些简单的技能,它工作正常。我的主要问题是如何实现我的机器人来解释给定技能中单引号之间的代码片段?
我无论如何都不会与talkify联系在一起。如果某人有一个更适合我的用例的建议,那么我愿意改变。
我到目前为止的守则
// Core dependency
const talkify = require('talkify');
const Bot = talkify.Bot;
// Types dependencies
const BotTypes = talkify.BotTypes;
const Message = BotTypes.Message;
const SingleLineMessage = BotTypes.SingleLineMessage;
const MultiLineMessage = BotTypes.MultiLineMessage;
// Skills dependencies
const Skill = BotTypes.Skill;
// Training dependencies
const TrainingDocument = BotTypes.TrainingDocument;
const bot = new Bot();
bot.trainAll([
new TrainingDocument('how_many_endpoints', 'How many endpoints are there?'),
new TrainingDocument('how_many_endpoints', 'How many endpoints are there')
], function() {});
var howManyAction = function(context, request, response, next) {
response.message = new SingleLineMessage(function() {
var x = someWork();
return x;
});
next();
};
var howSkill = new Skill('how_skill', 'how_are_you', howAction);
bot.addSkill(howSkill);
var resolved = function(err, messages) {
if(err) return console.error(err);
return console.log(messages);
};
bot.resolve(123, TEXT_FROM_CHAT, resolved);
当我问到我想要多少个端点时,上面的工作有效但是对于更复杂的句子它不起作用,例如,我可能想说
“执行以下'这是封闭的源代码,我将解析它的服务器端'”
如何将“执行以下内容”与规则匹配并将单引号内的字符串作为另一个变量?据我所知,talkify库培训文档必须与其解析的文本相匹配。
例
培训文件
execute the following
要匹配的文字
execute the following <~ Match
execute the following 'foo bar' <~ No match
execute the following, <~ No match
回答如下:
您可以使用简单的正则表达式预处理文本以提取和删除任何引用的短语:
/\'[^\']*\'/g
看到它在这里运行:https://regex101/r/eUe7n3/1
希望能帮助到你。