From eb63e588b7e9ce48b3fc2137f515e4f06eb843a6 Mon Sep 17 00:00:00 2001 From: maurok Date: Thu, 1 Jun 2017 16:51:34 -0300 Subject: [PATCH] # Adding action model to showcase advanced usage options --- .../Advanced/AlternativesAction.cs | 56 +++++++++++++++++++ .../LuisActions.Samples.Shared.csproj | 1 + 2 files changed, 57 insertions(+) create mode 100644 CSharp/Blog-LUISActionBinding/LuisActions.Samples.Shared/Advanced/AlternativesAction.cs diff --git a/CSharp/Blog-LUISActionBinding/LuisActions.Samples.Shared/Advanced/AlternativesAction.cs b/CSharp/Blog-LUISActionBinding/LuisActions.Samples.Shared/Advanced/AlternativesAction.cs new file mode 100644 index 0000000000..21ef46ec02 --- /dev/null +++ b/CSharp/Blog-LUISActionBinding/LuisActions.Samples.Shared/Advanced/AlternativesAction.cs @@ -0,0 +1,56 @@ +namespace LuisActions.Samples +{ + using System; + using System.ComponentModel.DataAnnotations; + using System.Threading.Tasks; + using Microsoft.Cognitive.LUIS.ActionBinding; + using Newtonsoft.Json; + + // This sample were added to showcase support to Custom List Entities - default JSON model does not have it + + // Refer to 'List Entities' @ https://docs.microsoft.com/en-us/azure/cognitive-services/luis/add-entities + + // You can create your own model with an 'AlternativeChoose' intent with utterances + // having a 'List Entity' called 'Alternatives' with the canonical forms defined by the + // 'Alternative' enum - or just can simply create your custom list entity, + // intent and update the intent binding here and custom name/type at fields + + public enum Alternative + { + // default (ie. empty choice) + None = 0, + + DomainOption1 = 11, + DomainOption2 = 12, + DomainOption3 = 13, + + ExternalOption1 = 101, + ExternalOption2 = 102 + } + + public class RequiredEnumAttribute : ValidationAttribute + { + public override bool IsValid(object value) + { + return (int)value > 0; + } + } + + [Serializable] + [LuisActionBinding("AlternativeChoose", FriendlyName = "Alternatives Choosing Model Sample")] + public class AlternativesAction : BaseLuisAction + { + [RequiredEnum(ErrorMessage = "Please provide an alternative")] + [LuisActionBindingParam(CustomType = "Alternatives", Order = 1)] + public Alternative FirstAlternative { get; set; } + + [Required(ErrorMessage = "Please provide one or more alternatives")] + [LuisActionBindingParam(CustomType = "Alternatives", Order = 2)] + public Alternative[] SecondaryAlternatives { get; set; } + + public override Task FulfillAsync() + { + return Task.FromResult((object)JsonConvert.SerializeObject(this)); + } + } +} diff --git a/CSharp/Blog-LUISActionBinding/LuisActions.Samples.Shared/LuisActions.Samples.Shared.csproj b/CSharp/Blog-LUISActionBinding/LuisActions.Samples.Shared/LuisActions.Samples.Shared.csproj index 0dbef98449..af8406667f 100644 --- a/CSharp/Blog-LUISActionBinding/LuisActions.Samples.Shared/LuisActions.Samples.Shared.csproj +++ b/CSharp/Blog-LUISActionBinding/LuisActions.Samples.Shared/LuisActions.Samples.Shared.csproj @@ -58,6 +58,7 @@ +