diff --git a/BotSharp.Core/Engines/BotEngineBase.cs b/BotSharp.Core/Engines/BotEngineBase.cs index 6b7072d8..c80a36ea 100644 --- a/BotSharp.Core/Engines/BotEngineBase.cs +++ b/BotSharp.Core/Engines/BotEngineBase.cs @@ -50,13 +50,13 @@ namespace BotSharp.Core.Engines Status = new AIResponseStatus(), Result = new AIResponseResult { - Score = doc.Sentences[0].Intent.Confidence, + Score = doc.Sentences[0].Intent == null ? 0 : doc.Sentences[0].Intent.Confidence, ResolvedQuery = doc.Sentences[0].Text, Fulfillment = new AIResponseFulfillment { }, Parameters = parameters, Metadata = new AIResponseMetadata { - IntentName = doc.Sentences[0].Intent.Label + IntentName = doc.Sentences[0].Intent?.Label } } }; diff --git a/BotSharp.Core/Engines/NERs/CRFsuiteEntityRecognizer.cs b/BotSharp.Core/Engines/NERs/CRFsuiteEntityRecognizer.cs index 939ce7be..b9e4ca59 100644 --- a/BotSharp.Core/Engines/NERs/CRFsuiteEntityRecognizer.cs +++ b/BotSharp.Core/Engines/NERs/CRFsuiteEntityRecognizer.cs @@ -29,6 +29,7 @@ namespace BotSharp.Core.Engines.NERs { return new List { + OntologyEnum.Location, OntologyEnum.DateTime }; } diff --git a/BotSharp.Core/Engines/NERs/README.md b/BotSharp.Core/Engines/NERs/README.md new file mode 100644 index 00000000..126a4d9b --- /dev/null +++ b/BotSharp.Core/Engines/NERs/README.md @@ -0,0 +1,15 @@ +# Extend Botsharp's entity recognition capabilities + +## Expand with Facebook Duckling +Duckling is a Haskell library that parses text into structured data. A Haskell environment is required. +``` +sudo apt install haskell-stack + +``` +Clone ducking from github +``` +git clone https://github.com/facebook/duckling +cd duckling +stack setup +stack build +``` \ No newline at end of file diff --git a/BotSharp.Core/Engines/NERs/WitAiEntityRecognizer.cs b/BotSharp.Core/Engines/NERs/WitAiEntityRecognizer.cs index a13029b4..8be3369a 100644 --- a/BotSharp.Core/Engines/NERs/WitAiEntityRecognizer.cs +++ b/BotSharp.Core/Engines/NERs/WitAiEntityRecognizer.cs @@ -34,11 +34,10 @@ namespace BotSharp.Core.Engines.NERs public async Task Predict(Agent agent, NlpDoc doc, PipeModel meta) { - var config = (IConfiguration)AppDomain.CurrentDomain.GetData("Configuration"); - var client = new RestClient($"{config.GetSection("WitAi:url").Value}"); - var request = new RestRequest(config.GetSection("WitAi:resource").Value, Method.GET); - request.AddHeader("Authorization", "Bearer " + config.GetSection("WitAi:serverAccessToken").Value); - request.AddQueryParameter("v", config.GetSection("WitAi:version").Value); + var client = new RestClient($"{Configuration.GetSection("WitAiEntityRecognizer:url").Value}"); + var request = new RestRequest(Configuration.GetSection("WitAiEntityRecognizer:resource").Value, Method.GET); + request.AddHeader("Authorization", "Bearer " + Configuration.GetSection("WitAiEntityRecognizer:serverAccessToken").Value); + request.AddQueryParameter("v", Configuration.GetSection("WitAiEntityRecognizer:version").Value); request.AddQueryParameter("q", doc.Sentences[0].Text); request.AddQueryParameter("verbose", "true"); request.AddQueryParameter("autosuggest", "true"); diff --git a/BotSharp.WebHost/Settings/bot.json b/BotSharp.WebHost/Settings/bot.json index e00880bf..b498eadb 100644 --- a/BotSharp.WebHost/Settings/bot.json +++ b/BotSharp.WebHost/Settings/bot.json @@ -1,26 +1,29 @@ { - "RasaNlu": { + "RasaAi": { "url": "http://localhost:5000" }, - - "WitAi": { - "url": "https://api.wit.ai", - "resource": "message", - "serverAccessToken": "YLLK6SFAPXNYGMKAWLOREQ5MJQSX345L", - "version": "20180811" - }, - "BotSharpAi": { "Lang": "en", + "Provider": "SpaCyProvider", "SpaCyProvider": { - "Url": "http://localhost:5005" + "url": "http://localhost:5005" + }, + + "Pipe": "SpaCyTokenizer, CRFsuiteEntityRecognizer, FasttextClassifier", + "SpaCyTokenizer": { + "url": "http://localhost:5005" }, - "Pipe": "SpaCyTokenizer, CRFsuiteEntityRecognizer, WitAiEntityRecognizer, FasttextClassifier", "CRFsuiteEntityRecognizer": { "fields": "y w pos chk", "uniFeatures": "w wl pos chk shape shaped type p1 p2 p3 p4 s1 s2 s3 s4 2d 4d d&a d&- d&/ d&, d&. up iu au al ad ao cu cl ca cd cs", "biFeatures": "w pos chk shaped type" + }, + "WitAiEntityRecognizer": { + "url": "https://api.wit.ai", + "resource": "message", + "serverAccessToken": "SERVER_ACCESS_TOKEN", + "version": "20180811" } } }