Example #1
0
        /// <summary>
        /// Add text to analyzed
        /// </summary>
        /// <param name="text">text to analyzed</param>
        /// <param name="mode">analyze mode</param>
        public void Add(T text, TextAnalyzeMode mode)
        {
            if (typeof(T) != typeof(string))
            {
                throw new ArgumentException();
            }

            AnalyseString(text, mode);
        }
Example #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="text">분석할 정보</param>
        /// <param name="mode">분석 모드</param>
        /// <exception cref="ArgumentException"><paramref name="text"/>가 문자열이 아닐 경우</exception>
        public FrequencyTable(T text, TextAnalyzeMode mode)
            : this()
        {
            if (typeof(string).IsInstanceOfType(text) == false)
            {
                throw new ArgumentException("text argument must be string.", "text");
            }

            AnalyseString(text, mode);
        }
Example #3
0
        private void AnalyseString(T text, TextAnalyzeMode mode)
        {
            // character strings
            const string SpecialChars = @"""!?%&/()=?@€<>|?.;:-_#'*+~껙 ";
            const string Numbers      = "0123456789";

            // Adding the entries according to mode
            switch (mode)
            {
            case TextAnalyzeMode.AllCharacters:
                foreach (char v in text.ToString())
                {
                    Add((T)Convert.ChangeType(v, text.GetType(), null));
                }
                break;

            case TextAnalyzeMode.LettersOnly:
                foreach (var v in text.ToString())
                {
                    if ((SpecialChars.IndexOf(v) == -1) & (Numbers.IndexOf(v) == -1))
                    {
                        Add((T)Convert.ChangeType(v, text.GetType(), null));
                    }
                }
                break;

            case TextAnalyzeMode.NoNumerals:
                foreach (var v in text.ToString())
                {
                    if (Numbers.IndexOf(v) == -1)
                    {
                        Add((T)Convert.ChangeType(v, text.GetType(), null));
                    }
                }
                break;

            case TextAnalyzeMode.NoSpecialCharacters:
                foreach (var v in text.ToString())
                {
                    if (SpecialChars.IndexOf(v) == -1)
                    {
                        Add((T)Convert.ChangeType(v, text.GetType(), null));
                    }
                }
                break;

            case TextAnalyzeMode.NumeralsOnly:
                foreach (var v in text.ToString())
                {
                    if (Numbers.IndexOf(v) != -1)
                    {
                        Add((T)Convert.ChangeType(v, text.GetType(), null));
                    }
                }
                break;

            case TextAnalyzeMode.SpecialCharactersOnly:
                foreach (var v in text.ToString())
                {
                    if (SpecialChars.IndexOf(v) != -1)
                    {
                        Add((T)Convert.ChangeType(v, text.GetType(), null));
                    }
                }
                break;
            }
        }