示例#1
0
        public void GetEntityResolutions(LuisResult luisResult, FundAttributionModel attrModel)
        {
            var entities = luisResult.ConnectedServiceResult.Entities;

            if (entities != null)
            {
                foreach (EntityModel entity in entities)
                {
                    switch (entity.Type)
                    {
                    //found fund name
                    case FundName:
                        var fund = Common.GetResolutionFromEntity(entity);
                        //given fund name is a ticker
                        if (fund.Trim().Length == 5)
                        {
                            attrModel.FundName = Common.tickersToFundName[fund.Trim().ToUpper()];
                        }
                        else
                        {
                            attrModel.FundName = fund;
                        }

                        break;

                    //found contributor or detractor
                    case AttributionType:
                        var attrType = Common.GetResolutionFromEntity(entity);
                        if (attrType == "contributor")
                        {
                            attrModel.ContributorsOrDetractors = 0;
                        }
                        else
                        {
                            attrModel.ContributorsOrDetractors = 1;
                        }

                        break;

                    //found "return of holding" or "contribution to portfolio return"
                    case AttributionChars:
                        attrModel.AttributionChar = Common.GetResolutionFromEntity(entity);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
示例#2
0
        private async Task <DialogTurnResult> ParseGivenParametersAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var luisResult       = (LuisResult)stepContext.Options;
            var attributionModel = new FundAttributionModel();

            //find all entities found by LUIS and save it to the model
            GetEntityResolutions(luisResult, attributionModel);

            //if the user requested "any fund"
            if (attributionModel.FundName == "any fund")
            {
                attributionModel.FundName = null;
                await stepContext.Context.SendActivityAsync(ChannelFormattingService.FormatSimpleMessage(stepContext.Context, "You must select a fund to view top contributors/detractors"));

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }

            stepContext.Values[FundAttributionModelValue] = attributionModel;

            //if no fund name is given, we need to ask the user
            if (string.IsNullOrEmpty(attributionModel.FundName))
            {
                var choices          = Common.PIFundNames.ToList();
                var suggestedActions = SuggestedActionGenerator.GenerateSuggestedActions(choices);

                var placeholder = attributionModel.ContributorsOrDetractors == 0 ? "top contributors" : "top detractors";

                var reply      = MessageFactory.Text(ChannelFormattingService.FormatSimpleMessage(stepContext.Context, $"Which fund would you like to see {placeholder} for?"));
                var retryReply = MessageFactory.Text(ChannelFormattingService.FormatSimpleMessage(stepContext.Context, "Please select a valid choice"));
                reply.SuggestedActions      = suggestedActions;
                retryReply.SuggestedActions = suggestedActions;

                return(await stepContext.PromptAsync($"{nameof(FundAttributionDialog)}.fundName", new PromptOptions
                {
                    Prompt = reply,
                    RetryPrompt = retryReply
                }, cancellationToken));
            }

            return(await stepContext.NextAsync(null, cancellationToken));
        }