2017-12-30 20:26:35 +00:00
|
|
|
|
using Bot.Rasa.Entities;
|
2018-01-02 18:05:35 +00:00
|
|
|
|
using Bot.Rasa.Intents;
|
2017-12-30 20:26:35 +00:00
|
|
|
|
using Bot.Rasa.Models;
|
|
|
|
|
|
using EntityFrameworkCore.BootKit;
|
2017-12-18 13:31:15 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Bot.Rasa.Agents
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class AgentExtension
|
|
|
|
|
|
{
|
2018-01-02 18:05:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get agent header row from Agent table
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="dc"></param>
|
|
|
|
|
|
/// <param name="agentId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static Agent Agent(this Database dc, string agentId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return dc.Table<Agent>().Find(agentId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-30 20:26:35 +00:00
|
|
|
|
public static String CreateEntity(this Agent agent, EntityType entity, Database dc)
|
|
|
|
|
|
{
|
|
|
|
|
|
return entity.Id;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static RasaTrainingData GrabCorpus(this Agent agent, Database dc)
|
2017-12-18 13:31:15 +00:00
|
|
|
|
{
|
|
|
|
|
|
var trainingData = new RasaTrainingData
|
|
|
|
|
|
{
|
|
|
|
|
|
UserSays = new List<UserSay>()
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-01-02 18:05:35 +00:00
|
|
|
|
var intents = dc.Table<Intent>().Include(x => x.Expressions).ToList();
|
2017-12-18 13:31:15 +00:00
|
|
|
|
|
|
|
|
|
|
intents.ForEach(intent => {
|
|
|
|
|
|
|
|
|
|
|
|
trainingData.UserSays.AddRange(intent.Expressions
|
|
|
|
|
|
.Select(exp => new UserSay
|
|
|
|
|
|
{
|
|
|
|
|
|
Intent = intent.Name,
|
|
|
|
|
|
Text = exp.Text
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return trainingData;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|