public bool KnocksSomeButNotAll(NodeLUISPhoneDialog.EIntents desiredFeature) { Dictionary <NodeLUISPhoneDialog.EIntents, NumberOfDifferent> enumerated = new Dictionary <NodeLUISPhoneDialog.EIntents, NumberOfDifferent>() { { NodeLUISPhoneDialog.EIntents.Color, () => handSets.GetBagColors().Count }, { NodeLUISPhoneDialog.EIntents.Brand, () => handSets.GetBagBrands().Count }, { NodeLUISPhoneDialog.EIntents.OS, () => handSets.GetBagOSes().Count } }; Predicate <HandSetFeatures> predicate; int count = handSets.BagCount(); int knockOutNumber; if (booleanFilters.TryGetValue(desiredFeature, out predicate)) // It's boolean { knockOutNumber = handSets.KnockOutNumber(predicate); return((knockOutNumber != count) && (knockOutNumber != 0)); } else if (intentFilters.TryGetValue(desiredFeature, out predicate)) { if (!enumerated.ContainsKey(desiredFeature)) { double highStandardThreshold; intent = desiredFeature; highStandardThreshold = handSets.GetHighStandardThreshold(this, getters[desiredFeature]); if (desiredFeature == NodeLUISPhoneDialog.EIntents.Newest) { DateThreshold = new DateTime((long)highStandardThreshold); } else { Threshold = highStandardThreshold; } knockOutNumber = handSets.KnockOutNumber(predicate); return((knockOutNumber != count) && (knockOutNumber != 0)); } else { return((enumerated[desiredFeature])() != 1); } } throw new Exception("Error...received a feature I don't know about:" + desiredFeature.ToString()); }
public async Task ProcessLuisNeedsResult(IDialogContext context, IAwaitable <object> awaitable) { Tuple <NodeLuisSubsNeeds.ENeeds, double> result = (Tuple <NodeLuisSubsNeeds.ENeeds, double>) await awaitable; StringBuilder sb = new StringBuilder(); double needsScore = result.Item2; NodeLuisSubsNeeds.ENeeds needsIntent = result.Item1; int handSetsLeft, handSetsNow = decoder.CurrentNumberofHandsetsLeft(); if (CommonDialog.debugMessages) { await context.PostAsync("DEBUG : Beginning of the method ProcessLuisNeedResult()"); } if (needsScore > desiredFeatureScore) // WE have a need { if (CommonDialog.debugMessages) { await context.PostAsync("DEBUG : It's a need, namely " + needsIntent.ToString()); } context.ConversationData.SetValue <NodeLuisSubsNeeds.ENeeds>(BotConstants.LAST_NEED_KEY, needsIntent); decoder.LastOneWasNeed = true; decoder.FeatureOrNeedDesc = NodeLuisSubsNeeds.GetNeedIntentDesc(result.Item1); if (CommonDialog.debugMessages) { await context.PostAsync("DEBUG : I'm going to obtain the top"); } handSetsLeft = needsScores.GetTopFive(needsIntent); if (CommonDialog.debugMessages) { await context.PostAsync("DEBUG : I've already obtained the top 5"); } await UpdateUserAsync(context, handSetsLeft, handSetsNow); } else { try { if (desiredFeature == EIntents.None) { await context.PostAsync("I'm sorry, I'm afraid I didn't understand that, could you please rephrase?"); return; } if (CommonDialog.debugMessages) { await context.PostAsync("DEBUG : I'm goin to set frequency"); } topButtons.SetNewFreq(desiredFeature, sb); if (CommonDialog.debugMessages) { await context.PostAsync("DEBUG : New Frequency set, getting into the switch to switch to correct one (no pun intented)"); } context.ConversationData.SetValue(BotConstants.LAST_FEATURE_KEY, desiredFeature); switch (desiredFeature) { case EIntents.Small: if (!ExtractPhoneSizeInfo(res)) { PromptDialog.Choice(context, ProcessSizeChoice, new List <string>() { "BIGGER", "SMALLER", "THE SAME" }, "Are you looking for a phone with a similar size as your existing model or something bigger or smaller?", "Not understood, please try again", 3); } break; case EIntents.Camera: if (!GetCameraCompositeEntityData(res)) // The desired megapixels aren't present, so in this particular case we'll send it to fuzzy engine { if (CommonDialog.debugMessages) { await context.PostAsync("DEBUG : Camera intent : No data detected"); } decoder.ExcludeThis(EIntents.Camera); decoder.SetSizeRequirements(-1, true); handSetsLeft = needsScores.GetTopFive(NodeLuisSubsNeeds.ENeeds.Camera); await UpdateUserAsync(context, handSetsLeft, handSetsNow); } else { if (CommonDialog.debugMessages) { await context.PostAsync("DEBUG : Camera intent : Data detected"); } await DecodeAndProcessIntentAsync(context); } break; case EIntents.OS: if (!GetOSData(res)) { if (CommonDialog.debugMessages) { await context.PostAsync("Handling OS intent"); } PromptDialog.Choice(context, ProcessEnumeratedChoice, handSetsBag.GetBagOSes(), "Could you please indicate your favourite Operating System?", "Not understood, please try again", 3); } else { await DecodeAndProcessIntentAsync(context); } break; case EIntents.Color: if (!GetPreferredColors(res)) { PromptDialog.Choice(context, ProcessEnumeratedChoice, handSetsBag.GetBagColors(), "Could you please indicate your favourite Color?", "Not understood, please try again", 3); } else { await DecodeAndProcessIntentAsync(context); } break; case EIntents.Brand: if (!GetSpecificBrands(res)) { List <string> brands = handSetsBag.GetBagBrands(); Activity reply = (Activity)context.MakeMessage(); reply.Text = "Could you please indicate your favourite brand?"; await Miscellany.InsertDelayAsync(context); Miscellany.ComposeBrandsCarousel(reply, brands, handSetsBag); await context.PostAsync(reply); context.Wait(ProcessBrandChoice); } else { await DecodeAndProcessIntentAsync(context); } break; default: await DecodeAndProcessIntentAsync(context); break; } } catch (ArgumentException) { await context.PostAsync("Argument xception"); } catch (Exception xception) { await context.PostAsync($"Error...Exception Message = {xception.Message}"); } } }