From 722e6482feb9d9914cd73fd1c52db3b583b68949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Parra=20dos=20santos?= Date: Wed, 27 Nov 2019 14:58:10 -0300 Subject: [PATCH] for loop crf_out var to extract entities --- BotSharp.Core/Engines/BotSharp/BotSharpNER.cs | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) 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);