Exemplo n.º 1
0
        //This method checks the availability of the file and handles raw text
        public void ParseText(string path)
        {
            try
            {
                StringBuilder tempText = new StringBuilder();
                using (StreamReader sr = new StreamReader(path))
                {
                    string line = sr.ReadToEnd().Replace("\n", String.Empty).Replace("\r", String.Empty).Replace("\t", String.Empty);
                    tempText.Append(line);
                }

                string[]        senstences    = Regex.Split(tempText.ToString(), @"(?<=[.?!])");
                SentenceHandler temtSentences = new SentenceHandler();
                //The line above is commented out so that we can create not only instances of the SentenceHandler class
                foreach (string sentence in senstences)
                {
                    Sentences.Add(SentenceHandler.ParseSentence(sentence));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("\n==================================================\n");
                Environment.Exit(1);
            }
        }
Exemplo n.º 2
0
        //This method handles the raw sentence. This method is static, in order to apply it without creating an instance (In the method ParseText from TextHandler class)
        //We can remove the "static" and uncomment one line in the ParseText method (TextHandler class)
        static public SentenceHandler ParseSentence(string sentence)
        {
            string tempSentence = Regex.Replace(sentence.Trim(), "[^a-zA-Z0-9 ]", "");

            string[]        words  = tempSentence.Split(' ');
            SentenceHandler result = new SentenceHandler(sentence.Trim(), sentence.LastOrDefault());

            foreach (string word in words)
            {
                result.Words.Add(new WordHandler(word));
            }
            return(result);
        }