2018-06-13 12:23:03 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2018-06-14 15:03:01 +00:00
|
|
|
|
using System.Linq;
|
2018-06-13 12:23:03 +00:00
|
|
|
|
using System.Text;
|
2018-06-14 15:03:01 +00:00
|
|
|
|
using BotSharp.Core.Abstractions;
|
2018-06-15 17:39:24 +00:00
|
|
|
|
using BotSharp.Core.Agents;
|
|
|
|
|
|
using BotSharp.Core.Intents;
|
2018-06-13 12:23:03 +00:00
|
|
|
|
using DotNetToolkit;
|
|
|
|
|
|
using EntityFrameworkCore.BootKit;
|
2018-06-15 17:39:24 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2018-06-14 15:03:01 +00:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2018-06-13 12:23:03 +00:00
|
|
|
|
|
|
|
|
|
|
namespace BotSharp.Core.Engines
|
|
|
|
|
|
{
|
|
|
|
|
|
public class BotTrainer
|
|
|
|
|
|
{
|
|
|
|
|
|
private Database dc;
|
|
|
|
|
|
|
|
|
|
|
|
private string agentId;
|
|
|
|
|
|
|
|
|
|
|
|
private string config;
|
|
|
|
|
|
|
|
|
|
|
|
public BotTrainer(string agentId, Database dc, string config = "BotSharpAi")
|
|
|
|
|
|
{
|
|
|
|
|
|
this.dc = dc;
|
|
|
|
|
|
this.agentId = agentId;
|
|
|
|
|
|
this.config = config;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-15 17:39:24 +00:00
|
|
|
|
public string Train(Agent agent)
|
2018-06-13 12:23:03 +00:00
|
|
|
|
{
|
2018-06-15 17:39:24 +00:00
|
|
|
|
agent.Intents = dc.Table<Intent>()
|
|
|
|
|
|
.Include(x => x.Contexts)
|
|
|
|
|
|
.Include(x => x.Responses).ThenInclude(x => x.Contexts)
|
|
|
|
|
|
.Include(x => x.Responses).ThenInclude(x => x.Parameters).ThenInclude(x => x.Prompts)
|
|
|
|
|
|
.Include(x => x.Responses).ThenInclude(x => x.Messages)
|
|
|
|
|
|
.Include(x => x.UserSays).ThenInclude(x => x.Data)
|
|
|
|
|
|
.Where(x => x.AgentId == agentId)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var data = JObject.FromObject(new
|
|
|
|
|
|
{
|
|
|
|
|
|
});
|
2018-06-14 15:03:01 +00:00
|
|
|
|
|
2018-06-13 12:23:03 +00:00
|
|
|
|
// Get NLP Provider
|
|
|
|
|
|
string providerName = Database.Configuration.GetSection($"{config}:Provider").Value;
|
2018-06-14 15:03:01 +00:00
|
|
|
|
var provider = TypeHelper.GetInstance(providerName, Database.Assemblies) as INlpPipeline;
|
2018-06-13 22:17:35 +00:00
|
|
|
|
provider.Configuration = Database.Configuration.GetSection("BotSharpAi");
|
2018-06-15 17:39:24 +00:00
|
|
|
|
provider.Process(agent, data);
|
2018-06-13 12:23:03 +00:00
|
|
|
|
|
2018-07-11 15:36:27 +00:00
|
|
|
|
//var corpus = agent.GrabCorpus(dc);
|
2018-06-13 12:23:03 +00:00
|
|
|
|
|
2018-06-13 22:17:35 +00:00
|
|
|
|
// pipe process
|
2018-06-14 15:03:01 +00:00
|
|
|
|
var pipelines = Database.Configuration.GetSection($"{config}:Pipe").Value
|
|
|
|
|
|
.Split(',')
|
|
|
|
|
|
.Select(x => x.Trim())
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
pipelines.ForEach(pipeName =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var pipe = TypeHelper.GetInstance(pipeName, Database.Assemblies) as INlpPipeline;
|
|
|
|
|
|
pipe.Configuration = provider.Configuration;
|
2018-06-15 17:39:24 +00:00
|
|
|
|
pipe.Process(agent, data);
|
2018-06-14 15:03:01 +00:00
|
|
|
|
});
|
2018-06-13 12:23:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|