Fix Sebis import expression data sequence issue.
This commit is contained in:
parent
6b7f9671f3
commit
b389d837f2
|
|
@ -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
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\DbInitializer\Agents\Rasa\" />
|
||||
<Folder Include="Algorithms\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
Loading…
Reference in a new issue