Skip to content

Commit

Permalink
# Supporting resolving multiple matching entities with array values t…
Browse files Browse the repository at this point in the history
…o array parameter value
  • Loading branch information
maurok committed Jun 1, 2017
1 parent eb63e58 commit 0fbd43b
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.Bot.Builder.Dialogs.Internals;
using Microsoft.Bot.Builder.Luis;
using Microsoft.Bot.Builder.Luis.Models;
using Newtonsoft.Json.Linq;

[Serializable]
public class LuisActionResolver
Expand Down Expand Up @@ -92,7 +93,7 @@ public static async Task<QueryValueResult> QueryValueFromLuisAsync(
{
var newIntentName = default(string);
var newAction = new LuisActionResolver(action.GetType().Assembly).ResolveActionFromLuisIntent(result, out newIntentName);
if (newAction != null)
if (newAction != null && !newAction.GetType().Equals(action.GetType()))
{
return new QueryValueResult(false)
{
Expand Down Expand Up @@ -359,7 +360,7 @@ private static bool AssignValue(ILuisAction action, PropertyInfo property, objec
}
else if (type.IsEnum)
{
value = Enum.Parse(type, (string)paramValue);
value = Enum.Parse(type, paramValue.ToString());
}
else
{
Expand Down Expand Up @@ -397,7 +398,7 @@ private static Array BuildArrayOfValues(ILuisAction action, PropertyInfo propert
var result = Array.CreateInstance(elementType, values.Count());
foreach (var value in values)
{
result.SetValue(elementType.IsEnum ? Enum.Parse(elementType, (string)value) : Convert.ChangeType(value, elementType), idx++);
result.SetValue(elementType.IsEnum ? Enum.Parse(elementType, value.ToString()) : Convert.ChangeType(value, elementType), idx++);
}

return result;
Expand All @@ -413,9 +414,9 @@ private static object SanitizeInputValue(Type targetType, object value)
object result = value;

// handle case where input is JArray returned from LUIS
if (value is Newtonsoft.Json.Linq.JArray)
if (value is JArray)
{
var arrayOfValues = value as Newtonsoft.Json.Linq.JArray;
var arrayOfValues = value as JArray;

if (targetType.IsArray)
{
Expand Down Expand Up @@ -523,6 +524,22 @@ private static bool AssignEntitiesToMembers(

result &= AssignValue(action, property, paramValue);
}
else if (matchingEntities.Count() > 0
&& matchingEntities.Count(e => e.Resolution != null && e.Resolution.First().Value is JArray) == matchingEntities.Count())
{
var paramValues = new JArray();

foreach (var currentMatchingEntity in matchingEntities)
{
var values = currentMatchingEntity.Resolution.First().Value as JArray;
foreach (var value in values)
{
paramValues.Add(value);
}
}

result &= AssignValue(action, property, paramValues);
}
else
{
result = false;
Expand Down

0 comments on commit 0fbd43b

Please sign in to comment.