Created
February 7, 2019 11:39
-
-
Save icebeam7/164948aaab240639e3ae4e4e612775c6 to your computer and use it in GitHub Desktop.
WeatherBotv4 - LuisParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
using Microsoft.Bot.Builder; | |
namespace WeatherBotv4.Helpers | |
{ | |
public static class LuisParser | |
{ | |
public static string GetEntityValue(RecognizerResult result) | |
{ | |
foreach (var entity in result.Entities) | |
{ | |
var location = JObject.Parse(entity.Value.ToString())[Constants.LocationLabel]; | |
var locationPattern = JObject.Parse(entity.Value.ToString())[Constants.LocationPatternLabel]; | |
if (location != null || locationPattern != null) | |
{ | |
dynamic value = JsonConvert.DeserializeObject<dynamic>(entity.Value.ToString()); | |
if (location != null) | |
return value.Location[0].text; | |
if (locationPattern != null) | |
return value.Location_PatternAny[0].text; | |
} | |
} | |
return string.Empty; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment