Exemple #1
0
        public int DecodeIntent(NodeLUISPhoneDialog.EIntents intent2Decode, LuisResult result, System.Text.StringBuilder stringDeDebug = null)
        {
            int handSetsLeft;
            Predicate <HandSetFeatures> predicate;

            intent = intent2Decode;
            if (result != null)
            {
                Threshold     = -1;
                DateThreshold = new DateTime(1980, 1, 1);
                ExtractEntityInfo(intent2Decode, result);
            }
            intents2Exclude.Add(intent2Decode);
            if (intentFilters.TryGetValue(intent2Decode, out predicate))                                                                                                                  // it is numeric or date or string
            {
                if ((intent2Decode == NodeLUISPhoneDialog.EIntents.Color) || (intent2Decode == NodeLUISPhoneDialog.EIntents.OS) || (intent2Decode == NodeLUISPhoneDialog.EIntents.Brand)) // strings, enumerated
                {
                    if ((StrKeyWords == null) || (StrKeyWords.Count == 0))
                    {
                        throw new Exception("Error...Either color, brand or OS selected and no string was supplied");
                    }
                    if (handSets.KnockOutNumber(predicate) == handSets.BagCount())
                    {
                        return(0);
                    }
                    if (!FeatureOrSmartPhoneDecision && handSets.TooManyFeaturePhones(predicate))
                    {
                        return(-1);
                    }
                    handSets.EliminateFromBag(predicate);
                    return(handSets.BagCount());
                }
                else if ((Threshold != -1) || (DateThreshold != new DateTime(1980, 1, 1)))
                {
                    if (stringDeDebug != null)
                    {
                        stringDeDebug.Append($" The threshold extracted is : {Threshold}");
                    }
                    if (handSets.KnockOutNumber(predicate) == handSets.BagCount())
                    {
                        return(0);
                    }
                    if (!FeatureOrSmartPhoneDecision && handSets.TooManyFeaturePhones(predicate))
                    {
                        return(-1);
                    }
                    handSets.EliminateFromBag(predicate);
                    return(handSets.BagCount());
                }
                else   // Subs said he wants the best of a certain feature without specifying a value
                {
                    if (NodeLUISPhoneDialog.EIntents.Newest == intent2Decode)
                    {
                        DateThreshold = new DateTime((long)handSets.GetHighStandardThreshold(this, getters[intent2Decode]));
                    }
                    else
                    {
                        Threshold = handSets.GetHighStandardThreshold(this, getters[intent2Decode]);
                    }
                    if (handSets.KnockOutNumber(predicate) == handSets.BagCount())
                    {
                        return(0);
                    }
                    handSetsLeft = handSets.SortAndGetTop(this, getters[intent2Decode]);
                    if (handSetsLeft == 0)
                    {
                        return(0);
                    }
                    if (stringDeDebug != null)
                    {
                        stringDeDebug.Append("handSetsLeft = " + handSetsLeft);
                    }
                    if (!FeatureOrSmartPhoneDecision && handSets.TooManyFeaturePhones(predicate, handSetsLeft, stringDeDebug))
                    {
                        return(-1);
                    }
                    handSets.removeAllButTop(handSetsLeft);
                    handSets.EliminateFromBag(predicate);
                    return(handSetsLeft);
                }
            }
            /*** still here ? Boolean situation ****/
            if (booleanFilters.TryGetValue(intent2Decode, out predicate))
            {
                if (handSets.BagCount() == handSets.KnockOutNumber(predicate))
                {
                    return(0);
                }
                if ((intent2Decode != NodeLUISPhoneDialog.EIntents.SmartPhone) &&
                    (intent2Decode != NodeLUISPhoneDialog.EIntents.FeaturePhone) &&
                    !FeatureOrSmartPhoneDecision &&
                    handSets.TooManyFeaturePhones(predicate))
                {
                    return(-1);
                }
                handSets.EliminateFromBag(predicate);
                return(handSets.BagCount());
            }
            throw new Exception("IntentDecoder : Error...Intent not recongized");
        }