Support multiple models for one agent.

This commit is contained in:
Oceania2018 2018-08-15 06:34:27 -05:00
parent 51f96a64ed
commit cd72868f38
9 changed files with 28 additions and 15 deletions

View file

@ -35,7 +35,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetToolkit" Version="1.5.3" />
<PackageReference Include="DotNetToolkit" Version="1.5.4" />
<PackageReference Include="EntityFrameworkCore.BootKit" Version="1.8.0" />
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="2.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />

View file

@ -173,14 +173,11 @@ namespace BotSharp.Core.Engines
.ToList()
.ForEach(x =>
{
int start = say.Text.IndexOf(x.Text);
var part = new TrainingIntentExpressionPart
{
Value = x.Text,
Entity = $"{x.Meta}:{x.Alias}",
Start = start,
End = start + x.Text.Length
Start = x.Start
};
if (say.Entities == null) say.Entities = new List<TrainingIntentExpressionPart>();

View file

@ -30,7 +30,7 @@ namespace BotSharp.Core.Engines
public Agent LoadAgent(AgentImportHeader agentHeader)
{
// load agent profile
string data = File.ReadAllText(Path.Join(AgentDir, "Dialogflow", $"agentHeader.Name{Path.DirectorySeparatorChar}agent.json"));
string data = File.ReadAllText(Path.Join(AgentDir, "Dialogflow", $"{agentHeader.Name}{Path.DirectorySeparatorChar}agent.json"));
var agent = JsonConvert.DeserializeObject<DialogflowAgent>(data);
agent.Name = agentHeader.Name;
agent.Id = agentHeader.Id;
@ -155,6 +155,12 @@ namespace BotSharp.Core.Engines
// remove @
say.Data.Where(x => x.Meta != null && x.Meta.StartsWith("@")).ToList().ForEach(x => x.Meta = x.Meta.Substring(1));
// calculate offset
for(int i = 1; i < say.Data.Count; i++)
{
say.Data[i].Start = String.Join("", say.Data.Select(x => x.Text).Take(i)).Length;
}
});
}
}

View file

@ -9,6 +9,7 @@ namespace BotSharp.Core.Adapters.Dialogflow
public String Text { get; set; }
public String Alias { get; set; }
public String Meta { get; set; }
public int Start { get; set; }
public Boolean UserDefined { get; set; }
}
}

View file

@ -122,7 +122,8 @@ namespace BotSharp.Core.Engines.Rasa
{
expression.Data.Add(new IntentExpressionPart
{
Text = say.Text.Substring(pos, entity.Start - pos)
Text = say.Text.Substring(pos, entity.Start - pos),
Start = pos
});
}
@ -131,7 +132,8 @@ namespace BotSharp.Core.Engines.Rasa
{
Alias = entity.Entity,
Meta = entity.Entity,
Text = say.Text.Substring(entity.Start, entity.Value.Length)
Text = say.Text.Substring(entity.Start, entity.Value.Length),
Start = entity.Start
});
pos = entity.End + 1;
@ -141,7 +143,8 @@ namespace BotSharp.Core.Engines.Rasa
// end
expression.Data.Add(new IntentExpressionPart
{
Text = say.Text.Substring(pos)
Text = say.Text.Substring(pos),
Start = pos
});
}
}
@ -181,7 +184,8 @@ namespace BotSharp.Core.Engines.Rasa
.Select(x => new TrainingIntentExpressionPart
{
Value = x.Text,
Entity = x.Meta
Entity = x.Meta,
Start = x.Start
})
.ToList()
});

View file

@ -95,7 +95,8 @@ namespace BotSharp.Core.Engines
{
expression.Data.Add(new IntentExpressionPart
{
Text = say.Text.Substring(pos, entity.Start - pos)
Text = say.Text.Substring(pos, entity.Start - pos),
Start = pos
});
}
@ -104,7 +105,8 @@ namespace BotSharp.Core.Engines
{
Alias = entity.Entity,
Meta = entity.Entity,
Text = say.Text.Substring(entity.Start, entity.Value.Length)
Text = say.Text.Substring(entity.Start, entity.Value.Length),
Start = entity.Start
});
pos = entity.End + 1;
@ -114,7 +116,8 @@ namespace BotSharp.Core.Engines
// end
expression.Data.Add(new IntentExpressionPart
{
Text = say.Text.Substring(pos)
Text = say.Text.Substring(pos),
Start = pos
});
}
}

View file

@ -7,7 +7,7 @@ namespace BotSharp.Core.Engines
public class TrainingIntentExpressionPart
{
public int Start { get; set; }
public int End { get; set; }
public int End { get { return Start + Value.Length; } }
public String Value { get; set; }
public String Entity { get; set; }
}

View file

@ -24,6 +24,8 @@ namespace BotSharp.Core.Intents
[MaxLength(64)]
public String Meta { get; set; }
public int Start { get; set; }
public Boolean UserDefined { get; set; }
}
}

View file

@ -53,7 +53,7 @@ namespace BotSharp.RestApi
var rasa = new BotSharpAi();
var agentHeader = agents.First(x => x.Id == agentId);
rasa.RestoreAgent<AgentImporterInSebis>(agentHeader);
rasa.RestoreAgent<AgentImporterInDialogflow>(agentHeader);
return Ok();
}