Example #1
0
        /// <summary>
        /// Method to parse string and assign a type of elements (words or separators)
        /// </summary>
        /// <param name="inputLine"></param>
        /// <returns></returns>
        public static ICollection <ISentenceElement> StringParse(string inputLine)
        {
            var    line = string.Concat(inputLine, " ");
            string sentenceSplitPattern   = ConfigurationManager.AppSettings["sentenceSplitter"];
            var    sentenceElements       = new Collection <ISentenceElement>();
            var    sentenceElementFactory = new SentenceElementFactory();

            foreach (Match match in Regex.Matches(line, sentenceSplitPattern))                               // Splitting our input line by certain pattern and then getting a type of each individual element
            {
                sentenceElements.Add(sentenceElementFactory.GetSentenceElement(match.Groups[1].ToString())); // assign a type of sentence element

                sentenceElements.Add(sentenceElementFactory.GetSentenceElement(match.Groups[2].ToString())); // assign the type of space value after our sentence element
            } // Groups are captured subgroups due to split pattern (done with using of parentheses in pattern)
            return(sentenceElements);
        }
        public ICollection <ISentenceElement> Parse(string inputLine)
        {
            var line = string.Concat(inputLine, " ");

            var sentenceElements = new Collection <ISentenceElement>();

            var sentenceElementFactory = new SentenceElementFactory();

            foreach (Match match in Regex.Matches(line, _wordSeparationPattern))
            {
                sentenceElements.Add(sentenceElementFactory.GetSentenceElement(match.Groups[1].ToString()));

                sentenceElements.Add(sentenceElementFactory.GetSentenceElement(match.Groups[2].ToString()));
            }

            return(sentenceElements);
        }