diff --git a/BotSharp.Core/Engines/BotSharp/BotSharpNER.cs b/BotSharp.Core/Engines/BotSharp/BotSharpNER.cs index 2bc6e2f09..a1d1887dc 100644 --- a/BotSharp.Core/Engines/BotSharp/BotSharpNER.cs +++ b/BotSharp.Core/Engines/BotSharp/BotSharpNER.cs @@ -189,15 +189,24 @@ public async Task Predict(AgentBase agent, NlpDoc doc, PipeModel meta) for (int i = 0; i < sent.Tokens.Count; i++) { - var entity = crf_out[0].result_; - entities.Add(new NlpEntity + for (int crf_index = 0; crf_index < crf_out.Length; crf_index++) { - Entity = entity[i], - Start = doc.Sentences[0].Tokens[i].Start, - Value = doc.Sentences[0].Tokens[i].Text, - Confidence = 0, - Extrator = "BotSharpNER" - }); + //entity can be extract in more than 1 run/index + //var entity = crf_out[0].result_; + var entity = crf_out[crf_index].result_; + var contains = entities.Exists(x => x.Entity == entity[i]); + if (!contains) + { + entities.Add(new NlpEntity + { + Entity = entity[i], + Start = doc.Sentences[0].Tokens[i].Start, + Value = doc.Sentences[0].Tokens[i].Text, + Confidence = 0, + Extrator = "BotSharpNER" + }); + } + } } sent.Entities = MergeEntity(doc.Sentences[0].Text, entities);