updated code from Oceania

This commit is contained in:
Bolo 2018-08-06 13:44:22 -05:00
commit fa0152cc18
5 changed files with 27 additions and 11 deletions

View file

@ -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<TrainingIntentExpressionPart>
{
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
};

View file

@ -27,9 +27,10 @@ namespace BotSharp.Core.Engines.CRFsuite
List<List<String>> tags = data["Tags"].ToObject<List<List<String>>>();
List<List<NlpToken>> tokens = data["Tokens"].ToObject<List<List<NlpToken>>>();
List<TrainingIntentExpression<TrainingIntentExpressionPart>> userSays = corpus.UserSays;
List<List<TrainingData>> list =new List<List<TrainingData>>();
List<List<TrainingData>> list = new List<List<TrainingData>>();
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;

View file

@ -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<IntentExpressionPart>();
@ -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
@ -114,6 +117,12 @@ namespace BotSharp.Core.Engines
}
}
<<<<<<< HEAD
=======
int second = 0;
expression.Data.ForEach(x => x.UpdatedTime = DateTime.UtcNow.AddSeconds(second++));
>>>>>>> b389d837f25afa256b35d0418274967557fb06f9
intent.UserSays.Add(expression);
});
}
@ -121,7 +130,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)

View file

@ -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);

View file

@ -57,6 +57,7 @@
<ItemGroup>
<Folder Include="App_Data\DbInitializer\Agents\Rasa\" />
<Folder Include="Algorithms\" />
</ItemGroup>
<ItemGroup>