Beispiel #1
0
        public void FindWordsTester()
        {
            var article = @"I can now write topics on sports e.g. basketball, football, baseball and submit it to Mrs. Smith. " +
                          @"This is what I learned from Mr. Jones about a paragraph. " +
                          @"A paragraph is a group of words put together to form a group that is usually longer than a sentence. " +
                          @"Paragraphs are often made up of several sentences.";
            var words         = new string[] { "This", "is", "smith", "sentence", "sentences", "basketball" };
            var abbreviations = "Mr.,Mrs.,e.g.";
            var wordHunter    = new WordHunter
            {
                Article         = article,
                Words           = words,
                Abbreviations   = abbreviations.Split(","),
                Delimeters      = ".?!",
                OtherDelimeters = ",;:"
            };

            var sentences = wordHunter.GetSentences();
            var result    = wordHunter.FindAndCount(sentences);

            Assert.True(result == 0);

            //Can also check if there really found words.
            //Assert.True(wordHunter.FoundWords != null && wordHunter.FoundWords.Count > 0);
        }
Beispiel #2
0
        public static void Process(string delimeters, string otherDelimeters,
                                   string article, string[] words, string abbreviations,
                                   string basePath, string outputFilename)
        {
            var wordHunter = new WordHunter
            {
                Article         = article,
                Words           = words,
                Delimeters      = delimeters,
                Abbreviations   = abbreviations.Split(","),
                OtherDelimeters = otherDelimeters
            };

            var   sentences = wordHunter.GetSentences();
            short result    = wordHunter.FindAndCount(sentences);

            if (result < 0)
            {
                SetPreProcessingException(result);
                Console.WriteLine("There was a problem in word finder processing.");
            }

            try
            {
                var outputWriter = new OutputWriter(wordHunter.FoundWords, outputFilename);

                outputWriter.FilePath = basePath;
                outputWriter.GenerateResult();
                if (outputWriter.Results.Length > 0)
                {
                    outputWriter.Write();
                    Console.WriteLine("Word Finder Processing Completed..");
                    return;
                }

                FindOrAddError("Err6", "There was no results generated.");
            }
            catch (Exception)
            {
                FindOrAddError("Err7", "Writing output file failed.");
            }
        }