Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Created February 7, 2019 11:39
Show Gist options
  • Save icebeam7/164948aaab240639e3ae4e4e612775c6 to your computer and use it in GitHub Desktop.
Save icebeam7/164948aaab240639e3ae4e4e612775c6 to your computer and use it in GitHub Desktop.
WeatherBotv4 - LuisParser.cs
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