From 09282234e43e9876bb092d47277166ec65f227cf Mon Sep 17 00:00:00 2001 From: botsharp2018 Date: Wed, 24 Oct 2018 23:54:26 -0500 Subject: [PATCH] add response parameters. --- BotSharp.Core/Engines/BotEngineBase.cs | 10 ++-------- .../BotSharp/{BotSharpCRFNer.cs => BotSharpNER.cs} | 7 +++---- BotSharp.Core/Engines/NlpDoc.cs | 2 +- BotSharp.Core/PlatformBuilderBase.cs | 8 +++----- BotSharp.Platform.Models/AiResponse/AIResponse.cs | 12 ++++++++++-- .../Entities}/NlpEntity.cs | 2 +- BotSharp.WebHost/Settings/BotSharpNLU.json | 8 ++++---- 7 files changed, 24 insertions(+), 25 deletions(-) rename BotSharp.Core/Engines/BotSharp/{BotSharpCRFNer.cs => BotSharpNER.cs} (98%) rename {BotSharp.NLP => BotSharp.Platform.Models/Entities}/NlpEntity.cs (93%) diff --git a/BotSharp.Core/Engines/BotEngineBase.cs b/BotSharp.Core/Engines/BotEngineBase.cs index 0f8d8d52..51c6aae6 100644 --- a/BotSharp.Core/Engines/BotEngineBase.cs +++ b/BotSharp.Core/Engines/BotEngineBase.cs @@ -1,14 +1,8 @@ -using BotSharp.Models.NLP; -using BotSharp.Platform.Abstraction; -using BotSharp.Platform.Models; +using BotSharp.Platform.Models; using BotSharp.Platform.Models.AiRequest; using BotSharp.Platform.Models.AiResponse; -using BotSharp.Platform.Models.Intents; -using DotNetToolkit; +using BotSharp.Platform.Models.Entities; using EntityFrameworkCore.BootKit; -using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; using System; using System.Collections.Generic; using System.Drawing; diff --git a/BotSharp.Core/Engines/BotSharp/BotSharpCRFNer.cs b/BotSharp.Core/Engines/BotSharp/BotSharpNER.cs similarity index 98% rename from BotSharp.Core/Engines/BotSharp/BotSharpCRFNer.cs rename to BotSharp.Core/Engines/BotSharp/BotSharpNER.cs index 9e6c6a90..284529e7 100644 --- a/BotSharp.Core/Engines/BotSharp/BotSharpCRFNer.cs +++ b/BotSharp.Core/Engines/BotSharp/BotSharpNER.cs @@ -2,9 +2,7 @@ using Bigtree.Algorithm.CRFLite; using Bigtree.Algorithm.CRFLite.Decoder; using Bigtree.Algorithm.CRFLite.Encoder; -using BotSharp.Models.NLP; using BotSharp.NLP.Tokenize; -using DotNetToolkit; using Microsoft.Extensions.Configuration; using System; using System.Collections.Generic; @@ -14,10 +12,11 @@ using System.Text; using System.Threading.Tasks; using BotSharp.Platform.Models; using BotSharp.Platform.Models.MachineLearning; +using BotSharp.Platform.Models.Entities; namespace BotSharp.Core.Engines.BotSharp { - public class BotSharpCRFNer : INlpTrain, INlpPredict + public class BotSharpNER : INlpTrain, INlpPredict { public IConfiguration Configuration { get; set; } public PipeSettings Settings { get; set; } @@ -197,7 +196,7 @@ namespace BotSharp.Core.Engines.BotSharp Start = doc.Sentences[0].Tokens[i].Start, Value = doc.Sentences[0].Tokens[i].Text, Confidence = 0, - Extrator = "BotSharpCRFNer" + Extrator = "BotSharpNER" }); } diff --git a/BotSharp.Core/Engines/NlpDoc.cs b/BotSharp.Core/Engines/NlpDoc.cs index 5538601b..e6155b09 100644 --- a/BotSharp.Core/Engines/NlpDoc.cs +++ b/BotSharp.Core/Engines/NlpDoc.cs @@ -1,6 +1,6 @@ using BotSharp.Core.Abstractions; -using BotSharp.Models.NLP; using BotSharp.NLP.Tokenize; +using BotSharp.Platform.Models.Entities; using System; using System.Collections.Generic; using System.Text; diff --git a/BotSharp.Core/PlatformBuilderBase.cs b/BotSharp.Core/PlatformBuilderBase.cs index 2becc2b3..fbd30c42 100644 --- a/BotSharp.Core/PlatformBuilderBase.cs +++ b/BotSharp.Core/PlatformBuilderBase.cs @@ -1,12 +1,11 @@ using BotSharp.Core.Engines; -using BotSharp.Models.NLP; using BotSharp.Platform.Abstraction; using BotSharp.Platform.Models; using BotSharp.Platform.Models.AiRequest; using BotSharp.Platform.Models.AiResponse; +using BotSharp.Platform.Models.Entities; using BotSharp.Platform.Models.MachineLearning; using DotNetToolkit; -using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -152,12 +151,10 @@ namespace BotSharp.Core var preditor = new BotPredictor(); var doc = await preditor.Predict(Agent, request); - var parameters = new Dictionary(); if (doc.Sentences[0].Entities == null) { doc.Sentences[0].Entities = new List(); } - doc.Sentences[0].Entities.ForEach(x => parameters[x.Entity] = x.Value); var predictedIntent = doc.Sentences[0].Intent; @@ -166,7 +163,8 @@ namespace BotSharp.Core ResolvedQuery = request.Text, Score = predictedIntent.Confidence, Source = predictedIntent.Classifier, - Intent = predictedIntent.Label + Intent = predictedIntent.Label, + Entities = doc.Sentences[0].Entities }; Console.WriteLine($"TextResponse: {aiResponse.Intent}, {request.SessionId}"); diff --git a/BotSharp.Platform.Models/AiResponse/AIResponse.cs b/BotSharp.Platform.Models/AiResponse/AIResponse.cs index 1b6c3184..5158f6f5 100644 --- a/BotSharp.Platform.Models/AiResponse/AIResponse.cs +++ b/BotSharp.Platform.Models/AiResponse/AIResponse.cs @@ -1,4 +1,5 @@ -using System; +using BotSharp.Platform.Models.Entities; +using System; using System.Collections.Generic; using System.Text; @@ -6,12 +7,19 @@ namespace BotSharp.Platform.Models.AiResponse { public class AiResponse { - public String ResolvedQuery { get; set; } + public AiResponse() + { + Entities = new List(); + } + + public string ResolvedQuery { get; set; } public string Intent { get; set; } public string Source { get; set; } public double Score { get; set; } + + public List Entities { get; set; } } } diff --git a/BotSharp.NLP/NlpEntity.cs b/BotSharp.Platform.Models/Entities/NlpEntity.cs similarity index 93% rename from BotSharp.NLP/NlpEntity.cs rename to BotSharp.Platform.Models/Entities/NlpEntity.cs index 122a5000..d181c1bd 100644 --- a/BotSharp.NLP/NlpEntity.cs +++ b/BotSharp.Platform.Models/Entities/NlpEntity.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace BotSharp.Models.NLP +namespace BotSharp.Platform.Models.Entities { public class NlpEntity { diff --git a/BotSharp.WebHost/Settings/BotSharpNLU.json b/BotSharp.WebHost/Settings/BotSharpNLU.json index ba0c4bca..24d0c694 100644 --- a/BotSharp.WebHost/Settings/BotSharpNLU.json +++ b/BotSharp.WebHost/Settings/BotSharpNLU.json @@ -7,10 +7,10 @@ "botSharpProvider": { }, - "pipe": "BotSharpTokenizer, BotSharpTagger, BotSharpCRFNer, BotSharpIntentClassifier", + "pipe": "BotSharpTokenizer, BotSharpTagger, BotSharpNER, BotSharpIntentClassifier", "botSharpTokenizer": { - "tokenizer": "JiebaTokenizer" + "tokenizer": "TreebankTokenizer" }, "botSharpIntentClassifier": { @@ -19,10 +19,10 @@ }, "botSharpTagger": { - "tagger": "JiebaTagger" + "tagger": "NGramTagger" }, - "botSharpCRFNer": { + "botSharpNER": { "template": "|App_Data|CRFLite/template.en" } }