Example #1
0
 /* Eg: give me a stock check for item */
 public static void ItemResponse(ConversationContext cContext, TokenRequest p1, TokenQueryQuantity p2, TokenFor p3, TokenItem p4)
 {
     // Ask for which item
     cContext.AskQuestion(CreateResponse(null));
 }
Example #2
0
        public override IEnumerable<TokenResult> Parse(string input, string UserId)
        {
            var tokenResults = new List<TokenResult>();
            string remainder = string.Empty;

            var results = base.Parse(input, UserId);

            if (results.Any())
            {
                tokenResults.Add(results.OrderByDescending(qty => qty.Length).First());

                int startPos = tokenResults.First().Start + tokenResults.First().Length + 1;

                if (startPos < input.Length)
                {
                    remainder = input.Substring(startPos);

                    if (remainder.Length > 0)
                    {
                        results = new TokenFor().Parse(remainder, UserId);
                        if (results.Any())
                        {
                            var tokenFor = results.OrderByDescending(token => token.Start).First();

                            tokenFor.Start += startPos;
                            startPos = tokenFor.Start + tokenFor.Length + 1;

                            tokenResults.Add(tokenFor);

                            remainder = (remainder.Length <= tokenFor.Length) ? string.Empty : remainder.Substring(tokenFor.Length + 1);

                            if (remainder.Length > 0)
                            {
                                results = new TokenItem().Parse(remainder, UserId);

                                if (results.Any())
                                {
                                    var tokenItem = results.OrderBy(token => token.Start).First();

                                    if (tokenItem.Start == 0)
                                    {
                                        tokenItem.Start += startPos;
                                        startPos = tokenItem.Start + tokenItem.Length + 1;

                                        tokenResults.Add(tokenItem);

                                        remainder = (remainder.Length <= tokenItem.Length) ? string.Empty : remainder.Substring(tokenItem.Length + 1);
                                    }
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(remainder))
                        {
                            tokenResults.Add(new TokenResult
                            {
                                Length = remainder.Length,
                                Start = startPos,
                                Token = new TokenQuotedPhrase { Value = remainder },
                                TokenType = typeof(TokenQuotedPhrase).ToString(),
                                Value = remainder
                            });
                        }
                    }
                }
            }

            return tokenResults;
        }
Example #3
0
 /* Eg: give me a stock check for item XYZ */
 public static void ItemResponse(ConversationContext cContext, TokenRequest p1, TokenQueryQuantity p2, TokenFor p3, TokenItem p4, TokenQuotedPhrase p5)
 {
     cContext.Say(CreateResponse(p5.Value.ToString()), null);
 }