diff --git a/BotSharp.Core/Engines/BotEngineBase.cs b/BotSharp.Core/Engines/BotEngineBase.cs index 62251799..6445072b 100644 --- a/BotSharp.Core/Engines/BotEngineBase.cs +++ b/BotSharp.Core/Engines/BotEngineBase.cs @@ -120,10 +120,12 @@ namespace BotSharp.Core.Engines { intent.UserSays.ForEach(exp => { + exp.Data = exp.Data.OrderBy(x => x.UpdatedTime).ToList(); + var say = new TrainingIntentExpression { Intent = intent.Name, - Text = String.Join("", exp.Data.OrderBy(x => x.UpdatedTime).Select(x => x.Text)), + Text = String.Join("", exp.Data.Select(x => x.Text)), ContextHash = intent.ContextHash }; diff --git a/BotSharp.Core/Engines/CRFsuite/CRFsuiteEntityRecognizer.cs b/BotSharp.Core/Engines/CRFsuite/CRFsuiteEntityRecognizer.cs index 7058db0e..d601eb33 100644 --- a/BotSharp.Core/Engines/CRFsuite/CRFsuiteEntityRecognizer.cs +++ b/BotSharp.Core/Engines/CRFsuite/CRFsuiteEntityRecognizer.cs @@ -27,9 +27,10 @@ namespace BotSharp.Core.Engines.CRFsuite List> tags = data["Tags"].ToObject>>(); List> tokens = data["Tokens"].ToObject>>(); List> userSays = corpus.UserSays; - List> list =new List>(); + List> list = new List>(); - FileStream fs = new FileStream("/home/bolo/Desktop/BotSharp/TrainingFiles/rawTrain.txt", FileMode.Create); + var dir = Path.Join(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "TrainingFiles"); + FileStream fs = new FileStream(Path.Join(dir, "rawTrain.txt"), FileMode.Create); StreamWriter sw = new StreamWriter(fs); for (int i = 0 ; i < tags.Count; i++) @@ -56,7 +57,10 @@ namespace BotSharp.Core.Engines.CRFsuite public void Runcmd () { - string cmd = "/home/bolo/Desktop/BotSharp/TrainingFiles/crfsuite learn -m /home/bolo/Desktop/BotSharp/TrainingFiles/crfsuite/bolo.model /home/bolo/Desktop/BotSharp/TrainingFiles/crfsuite/1.txt"; + var algorithmDir = Path.Join(AppDomain.CurrentDomain.GetData("ContentRootPath").ToString(), "Algorithms"); + var dataDir = Path.Join(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "TrainingFiles"); + + string cmd = $"{algorithmDir}/crfsuite learn -m {dataDir}/crfsuite/bolo.model {dataDir}/crfsuite/1.txt"; System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = "sh"; p.StartInfo.UseShellExecute = false; diff --git a/BotSharp.Core/Engines/Sebis/AgentImporterInSebis.cs b/BotSharp.Core/Engines/Sebis/AgentImporterInSebis.cs index 1f59dd62..ba849bfd 100644 --- a/BotSharp.Core/Engines/Sebis/AgentImporterInSebis.cs +++ b/BotSharp.Core/Engines/Sebis/AgentImporterInSebis.cs @@ -78,7 +78,7 @@ namespace BotSharp.Core.Engines say.Entities.ForEach(x => { ConvertWordPosToCharPos(say.Text, x, pos); - pos = x.End; + pos = x.End + 1; }); expression.Data = new List(); @@ -89,10 +89,13 @@ namespace BotSharp.Core.Engines var entity = say.Entities[entityIdx]; // previous - expression.Data.Add(new IntentExpressionPart + if(entity.Start > 0) { - Text = say.Text.Substring(pos, entity.Start - pos) - }); + expression.Data.Add(new IntentExpressionPart + { + Text = say.Text.Substring(pos, entity.Start - pos) + }); + } // self expression.Data.Add(new IntentExpressionPart @@ -102,7 +105,7 @@ namespace BotSharp.Core.Engines Text = say.Text.Substring(entity.Start, entity.Value.Length) }); - pos = entity.End; + pos = entity.End + 1; if (pos < say.Text.Length && entityIdx == say.Entities.Count - 1) { @@ -114,6 +117,9 @@ namespace BotSharp.Core.Engines } } + int second = 0; + expression.Data.ForEach(x => x.UpdatedTime = DateTime.UtcNow.AddSeconds(second++)); + intent.UserSays.Add(expression); }); } @@ -121,7 +127,7 @@ namespace BotSharp.Core.Engines private void ConvertWordPosToCharPos(string text, SebisIntentExpressionPart entity, int start) { entity.Start = text.IndexOf(entity.Value, start); - entity.End = entity.Start + entity.Value.Length; + entity.End = entity.Start + entity.Value.Length - 1; } public void LoadBuildinEntities(Agent agent, string agentDir) diff --git a/BotSharp.Core/Engines/SpaCy/SpaCyTagger.cs b/BotSharp.Core/Engines/SpaCy/SpaCyTagger.cs index 272cb843..46305e6f 100644 --- a/BotSharp.Core/Engines/SpaCy/SpaCyTagger.cs +++ b/BotSharp.Core/Engines/SpaCy/SpaCyTagger.cs @@ -11,12 +11,12 @@ using BotSharp.MachineLearning.NLP; namespace BotSharp.Core.Engines.SpaCy { - class SpaCyTagger : INlpPipeline + public class SpaCyTagger : INlpPipeline { public IConfiguration Configuration { get; set; } -public bool Process(Agent agent, JObject data) + public bool Process(Agent agent, JObject data) { var client = new RestClient(Configuration.GetSection("SpaCyProvider:Url").Value); var request = new RestRequest("tagger", Method.GET); diff --git a/BotSharp.WebHost/BotSharp.WebHost.csproj b/BotSharp.WebHost/BotSharp.WebHost.csproj index 458f02fd..757b271d 100644 --- a/BotSharp.WebHost/BotSharp.WebHost.csproj +++ b/BotSharp.WebHost/BotSharp.WebHost.csproj @@ -57,6 +57,7 @@ +