agent, intent, entity persist completed.

This commit is contained in:
Oceania2018 2018-10-01 08:36:39 -05:00
parent 7b97e22088
commit a5d90db155
26 changed files with 80 additions and 31 deletions

View file

@ -54,6 +54,15 @@ namespace BotSharp.Core
return true;
}
public int PurgeAllAgents()
{
int count = agents.Count;
agents.Clear();
return count;
}
public List<TAgent> Query()
{
return agents.Select(x => x.Value).ToList();

View file

@ -1,6 +1,7 @@
using BotSharp.Platform.Abstraction;
using BotSharp.Platform.Models;
using CSRedis;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@ -13,12 +14,19 @@ namespace BotSharp.Core
where TAgent : AgentBase
{
private static CSRedisClient csredis;
private string prefix = String.Empty;
public AgentStorageInRedis()
{
if (csredis == null)
{
csredis = new CSRedisClient("127.0.0.1:6379,defaultDatabase=botsharp,poolsize=50,ssl=false,writeBuffer=10240,prefix=agent.");
IConfiguration config = (IConfiguration)AppDomain.CurrentDomain.GetData("Configuration");
var db = config.GetSection("Database:Default").Value;
var dbConnStr = config.GetSection($"Database:ConnectionStrings:{db}").Value;
prefix = dbConnStr.Split(',').First(x => x.StartsWith("prefix=")).Split('=')[1];
csredis = new CSRedisClient(dbConnStr);
}
}
@ -39,10 +47,10 @@ namespace BotSharp.Core
{
var agents = new List<TAgent>();
var keys = csredis.Keys("agent.*");
var keys = csredis.Keys($"{prefix }*");
foreach (string key in keys)
{
var data = csredis.Get(key.Split('.')[1]);
var data = csredis.Get(key.Substring(prefix.Length));
var agent = JsonConvert.DeserializeObject<TAgent>(data);
if(agent.Name == agentName)
@ -66,14 +74,23 @@ namespace BotSharp.Core
return true;
}
public int PurgeAllAgents()
{
var keys = csredis.Keys($"{prefix}*");
csredis.Remove(keys.Select(x => x.Substring(prefix.Length)).ToArray());
return keys.Count();
}
public List<TAgent> Query()
{
var agents = new List<TAgent>();
var keys = csredis.Keys("agent.*");
var keys = csredis.Keys($"{prefix}*");
foreach (string key in keys)
{
var data = csredis.Get(key.Split('.')[1]);
var data = csredis.Get(key.Substring(prefix.Length));
var agent = JsonConvert.DeserializeObject<TAgent>(data);
agents.Add(agent);
}

View file

@ -1,6 +1,7 @@
using BotSharp.Core.Engines;
using BotSharp.Core.Entities;
using BotSharp.Core.Intents;
using BotSharp.Platform.Models;
using EntityFrameworkCore.BootKit;
using Newtonsoft.Json;
using System;

View file

@ -5,6 +5,7 @@ using BotSharp.Core.Entities;
using BotSharp.Core.Intents;
using BotSharp.Core.Models;
using BotSharp.Models.NLP;
using BotSharp.Platform.Models;
using DotNetToolkit;
using EntityFrameworkCore.BootKit;
using Microsoft.EntityFrameworkCore;

View file

@ -13,6 +13,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BotSharp.Platform.Models;
namespace BotSharp.Core.Engines.BotSharp
{

View file

@ -8,6 +8,7 @@ using BotSharp.Core.Agents;
using BotSharp.Core.Entities;
using BotSharp.Core.Intents;
using BotSharp.Core.Models;
using BotSharp.Platform.Models;
using DotNetToolkit;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

View file

@ -7,6 +7,7 @@ using BotSharp.Core.Agents;
using BotSharp.Core.Entities;
using BotSharp.Core.Intents;
using BotSharp.Core.Models;
using BotSharp.Platform.Models;
using DotNetToolkit;
using Newtonsoft.Json;

View file

@ -129,7 +129,7 @@ namespace BotSharp.Core.Engines
});
usedEntities = usedEntities.Distinct().ToList();
var entity_synonyms = corpus.Entities.Where(x => usedEntities.Contains(x.EntityType)).ToList();
var entity_synonyms = corpus.Entities.Where(x => usedEntities.Contains(x.Entity)).ToList();
var data = new RasaTrainingData
{

View file

@ -1,5 +1,6 @@
using BotSharp.Core.Adapters.Rasa;
using BotSharp.Core.Engines;
using BotSharp.Platform.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

View file

@ -1,4 +1,5 @@
using BotSharp.Core.Engines;
using BotSharp.Platform.Models;
using System;
using System.Collections.Generic;
using System.Text;

View file

@ -1,4 +1,5 @@
using BotSharp.Core.Engines;
using BotSharp.Platform.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@ -8,10 +9,7 @@ namespace BotSharp.Core.Adapters.Rasa
{
public sealed class RasaTrainingEntity : TrainingEntity
{
[JsonIgnore]
public override String EntityType { get; set; }
[JsonProperty("value")]
public override String EntityValue { get; set; }
public override String Entity { get; set; }
}
}

View file

@ -9,6 +9,7 @@ using BotSharp.Core.Agents;
using BotSharp.Core.Entities;
using BotSharp.Core.Intents;
using BotSharp.Core.Models;
using BotSharp.Platform.Models;
using DotNetToolkit;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using BotSharp.Core.Engines;
using BotSharp.Platform.Models;
namespace BotSharp.Core.Adapters.Sebis
{

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using BotSharp.Core.Engines;
using BotSharp.Platform.Models;
using Newtonsoft.Json;
namespace BotSharp.Core.Adapters.Sebis

View file

@ -37,5 +37,11 @@ namespace BotSharp.Platform.Abstraction
/// </summary>
/// <returns></returns>
List<TAgent> Query();
/// <summary>
/// Delete agents
/// </summary>
/// <returns></returns>
int PurgeAllAgents();
}
}

View file

@ -19,11 +19,11 @@ namespace BotSharp.Platform.Abstraction
// DialogRequestOptions RequestOptions { get; set; }
/// <summary>
/// Convert platform specific agent to standard agent format
/// Convert platform specific data to standard training corpus format
/// </summary>
/// <param name="agent"></param>
/// <returns></returns>
StandardAgent StandardizeAgent(TAgent agent);
TrainingCorpus ExtractorCorpus(TAgent agent);
/// <summary>
///
@ -32,5 +32,7 @@ namespace BotSharp.Platform.Abstraction
/// <param name="agent"></param>
/// <returns></returns>
bool SaveAgent(TAgent agent);
bool Train(TrainingCorpus corpus);
}
}

View file

@ -1,14 +1,16 @@
using BotSharp.Core.Models;
using System;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Core.Engines
namespace BotSharp.Platform.Models
{
public class TrainingCorpus
{
public List<TrainingIntentExpression<TrainingIntentExpressionPart>> UserSays { get; set; }
/// <summary>
/// User custom entities
/// </summary>
public List<TrainingEntity> Entities { get; set; }
}
}

View file

@ -2,13 +2,11 @@
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Core.Engines
namespace BotSharp.Platform.Models
{
public class TrainingEntity
{
public virtual String EntityType { get; set; }
public virtual String EntityValue { get; set; }
public virtual String Entity { get; set; }
public List<String> Synonyms { get; set; }
}

View file

@ -1,16 +1,14 @@
using Newtonsoft.Json;
using System;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Core.Engines
namespace BotSharp.Platform.Models
{
public class TrainingIntentExpression<TPart> where TPart : TrainingIntentExpressionPart
{
public String Text { get; set; }
public String Intent { get; set; }
[JsonIgnore]
public String ContextHash { get; set; }
public List<TPart> Entities { get; set; }

View file

@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Core.Engines
namespace BotSharp.Platform.Models
{
public class TrainingIntentExpressionPart
{

View file

@ -1,8 +1,9 @@
{
"Database": {
"Default": "Sqlite",
"Default": "Redis",
"ConnectionStrings": {
"InMemory": "DataSource=:memory:",
"Redis": "127.0.0.1:6379,defaultDatabase=BotSharp,poolsize=50,ssl=false,writeBuffer=10240,prefix=agent_",
"Sqlite": "Data Source=|DataDirectory|BotSharp.db;",
"SqlServer": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=BotSharp;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
}

View file

@ -80,7 +80,7 @@ namespace Platform.Articulate
return intents;
}
public StandardAgent StandardizeAgent(TAgent specificAgent)
public TrainingCorpus ExtractorCorpus(TAgent specificAgent)
{
var agent1 = specificAgent as AgentModel;
@ -91,7 +91,12 @@ namespace Platform.Articulate
Description = agent1.Description
};
return standardAgent;
return new TrainingCorpus();
}
public bool Train(TrainingCorpus corpus)
{
throw new NotImplementedException();
}
}
}

View file

@ -57,7 +57,7 @@ namespace Platform.Articulate.Controllers
public List<AgentModel> GetAgent()
{
var results = builder.GetAllAgents();
var agents = results.Select(x => x as AgentModel).ToList();
var agents = results.ToList();
return agents;
}

View file

@ -9,8 +9,8 @@ namespace Platform.Articulate.Controllers
[Route("[controller]")]
public class ParseControllercs : ControllerBase
{
[HttpGet("/agent/{agentId}/parse")]
public void ParseText([FromRoute] string agentId, [FromQuery] string text)
[HttpGet("/agent/{agentId}/converse")]
public void ParseText([FromRoute] string agentId, [FromQuery] string text, [FromQuery] string sessionId)
{
}

View file

@ -23,7 +23,9 @@ namespace Platform.Articulate.Controllers
{
var agent = builder.GetAgentById(agentId);
agent.Status = "ready";
agent.Status = "Ready";
return agent;
}

View file

@ -1,4 +1,5 @@
using BotSharp.Core.Engines;
using BotSharp.Platform.Models;
using System;
using System.Collections.Generic;
using System.Text;