BotSharp/BotSharp.Core/Engines/BotTrainer.cs

72 lines
2.3 KiB
C#
Raw Normal View History

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-08-02 21:14:46 +00:00
using Microsoft.Extensions.Configuration;
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;
public BotTrainer(string agentId, Database dc)
2018-06-13 12:23:03 +00:00
{
this.dc = dc;
this.agentId = agentId;
}
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
2018-08-02 21:14:46 +00:00
var config = (IConfiguration)AppDomain.CurrentDomain.GetData("Configuration");
var assemblies = (string[])AppDomain.CurrentDomain.GetData("Assemblies");
var platform = config.GetSection($"BotPlatform").Value;
string providerName = config.GetSection($"{platform}:Provider").Value;
2018-08-02 21:14:46 +00:00
var provider = TypeHelper.GetInstance(providerName, assemblies) as INlpPipeline;
provider.Configuration = config.GetSection(platform);
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
var pipelines = provider.Configuration.GetSection($"Pipe").Value
2018-06-14 15:03:01 +00:00
.Split(',')
.Select(x => x.Trim())
.ToList();
pipelines.ForEach(pipeName =>
{
2018-08-02 21:14:46 +00:00
var pipe = TypeHelper.GetInstance(pipeName, assemblies) as INlpPipeline;
2018-06-14 15:03:01 +00:00
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 "";
}
}
}