Exemplo n.º 1
0
        /// <summary>
        /// This method finds all longest suitable words in lines
        /// </summary>
        /// <param name="lines"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static List <string> ConditionalLengthWords(string[] lines, WordTypes type)
        {
            Predicate <string> condition      = getConditionFromWordType(type);
            List <string>      maxLengthWords = new List <string>();
            int maxLength = -1;

            foreach (var line in lines)
            {
                string[] words = LineState.SplitLine(line);
                foreach (var word in words)
                {
                    if (!condition(word))
                    {
                        continue;
                    }
                    else if (word.Length > maxLength)
                    {
                        maxLength = word.Length;
                        maxLengthWords.Clear();
                        maxLengthWords.Add(word);
                    }
                    else if (word.Length == maxLength)
                    {
                        maxLengthWords.Add(word);
                    }
                }
            }
            return(maxLengthWords);
        }
        private static string[] stayOnlyOneSeparator(string[] lines)
        {
            List <string> updatedLines = new List <string>();

            foreach (var line in lines)
            {
                string[] words = LineState.SplitLine(line);
                updatedLines.Add(groupWordsToLineWithOneSeparator(words));
            }
            return(updatedLines.ToArray());
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method calculates the number of entering some type of word in text
        /// </summary>
        /// <param name="lines"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static int CountThroughText(string[] lines, WordTypes type)
        {
            Predicate <string> condition = getConditionFromWordType(type);
            int countInText = 0;

            foreach (var line in lines)
            {
                countInText += LineState.FindCountOfWords(line, condition);
            }
            return(countInText);
        }
        private static string[] trueWordsPlusSeparators(string[] lines)
        {
            List <string> trWordsSepar = new List <string>();

            foreach (var line in lines)
            {
                string[] words       = LineState.SplitLine(line);
                string[] separators  = LineState.SplitSeparators(line);
                bool     isSepStart  = LineState.IsStartsWithSeparator(line);
                string   updatedLine = String.Empty;
                for (int i = 0; i < words.Length; i++)
                {
                    int indSep = isSepStart ? i + 1 : i;
                    if (Conditions.IsTrueWord(words[i]))
                    {
                        updatedLine += words[i] + ((indSep == separators.Length) ? String.Empty : separators[indSep]);
                    }
                }
                trWordsSepar.Add(updatedLine);
            }
            return(trWordsSepar.ToArray());
        }