private async Task <string> GetIntentVariableAsync(LazyInput input, string intentProperty)
        {
            var intent = await input.GetIntentAsync();

            if (intent == null)
            {
                return(null);
            }

            switch (intentProperty)
            {
            case "id":
                return(intent.Id);

            case "name":
                return(intent.Name);

            case "score":
                return(intent.Score?.ToString(CultureInfo.InvariantCulture));

            case "answer":
                var document = intent.Answer?.Value;
                if (document == null)
                {
                    return(null);
                }
                return(_documentSerializer.Serialize(document));
            }

            return(null);
        }
예제 #2
0
        public async Task <bool> EvaluateConditionAsync(
            LazyInput lazyInput,
            IContext context,
            CancellationToken cancellationToken)
        {
            string comparisonValue;

            switch (Source)
            {
            case ValueSource.Input:
                comparisonValue = lazyInput.SerializedContent;
                break;

            case ValueSource.Context:
                comparisonValue = await context.GetVariableAsync(Variable, cancellationToken);

                break;

            case ValueSource.Intent:
                comparisonValue = (await lazyInput.GetIntentAsync())?.Name;
                break;

            case ValueSource.Entity:
                comparisonValue = (await lazyInput.GetEntityValue(Entity))?.Value;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            switch (Comparison.GetComparisonType())
            {
            case ComparisonType.Unary:
                var unaryComparisonFunc = Comparison.ToUnaryDelegate();

                return(unaryComparisonFunc(comparisonValue));

            case ComparisonType.Binary:
                var binaryComparisonFunc = Comparison.ToBinaryDelegate();

                switch (Operator)
                {
                case ConditionOperator.Or:
                    return(Values.Any(v => binaryComparisonFunc(comparisonValue, v)));

                case ConditionOperator.And:
                    return(Values.All(v => binaryComparisonFunc(comparisonValue, v)));

                default:
                    throw new ArgumentOutOfRangeException();
                }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }