コード例 #1
0
        public bool Match(string input)
        {
            //Remove question mark
            input = input.Substring(0, input.Length - 1);

            bool isQuestion = (input.StartsWith("how many", StringComparison.OrdinalIgnoreCase));

            if (!isQuestion)
            {
                return(false);
            }

            string[] parts = input.Split(new string[] { " is " }, StringSplitOptions.RemoveEmptyEntries);
            if (parts.Length != 2)
            {
                return(false);
            }

            string[] preIsWords = parts[0].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (preIsWords.Length < 3)
            {
                return(false);
            }

            string[] postIsWords = parts[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (postIsWords.Length < 2)
            {
                return(false);
            }

            return(helper.AreWordsValidCommodities(preIsWords.Skip(preIsWords.Length - 1).ToArray()) &&
                   helper.AreWordsValidCommodities(postIsWords.Skip(postIsWords.Length - 1).ToArray()) &&
                   helper.AreWordsValidAliases(postIsWords.Take(postIsWords.Length - 1).ToArray()));
        }
コード例 #2
0
        public bool Match(string input)
        {
            //Remove question mark
            input = input.ToUpper().Substring(0, input.Length - 1);

            bool isQuestion = (input.StartsWith("HOW MANY", StringComparison.OrdinalIgnoreCase));

            if (!isQuestion)
            {
                return(false);
            }

            string[] parts = input.Split(new string[] { " IS " }, StringSplitOptions.RemoveEmptyEntries);
            if (parts.Length != 2)
            {
                return(false);
            }

            string[] words = parts[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (words.Length < 1)
            {
                return(false);
            }

            return(_helper.AreWordsValidAliases(words.Take(words.Length - 1).ToArray()) &&
                   _helper.AreWordsValidCommodities(words.Skip(words.Length - 1).ToArray()));
        }