Exemplo n.º 1
0
        public void TextAnalizer_Analize_Success()
        {
            var configuration = new Moq.Mock <IConfiguration>();

            Dictionary <string, IConfigurationSection> sections = new Dictionary <string, IConfigurationSection>();

            var prepositionSection = new Moq.Mock <IConfigurationSection>();

            prepositionSection.SetupGet(p => p.Value).Returns("para");
            sections.Add("prepositions", prepositionSection.Object);

            var articlesSection = new Moq.Mock <IConfigurationSection>();

            articlesSection.SetupGet(p => p.Value).Returns("um,o");
            sections.Add("articles", articlesSection.Object);

            var setencesBreakersSection = new Moq.Mock <IConfigurationSection>();

            setencesBreakersSection.SetupGet(p => p.Value).Returns("que");
            sections.Add("setences_breakers", setencesBreakersSection.Object);

            var pontuationSection = new Moq.Mock <IConfigurationSection>();

            pontuationSection.SetupGet(p => p.Value).Returns(".");
            sections.Add("pontuation", pontuationSection.Object);

            var verbSection = new Moq.Mock <IConfigurationSection>();

            verbSection.SetupGet(p => p.Value).Returns("é");
            sections.Add("verbs", verbSection.Object);

            configuration
            .Setup(c => c.GetSection(Moq.It.IsAny <string>()))
            .Returns <string>((sectionName) => sections[sectionName]);

            IEnumerable <Word> allWords = null;

            var textAnalizer = new TextAnalizer(configuration.Object);

            textAnalizer.OnExecuteFinished += (words) => allWords = words;
            textAnalizer.Execute("Outubro é um mês extremamente representativo para o mundo");

            Assert.NotNull(allWords);
            Assert.Equal(9, allWords.Count());
            Assert.Equal(1, allWords.Count(w => w.Type == WordType.Verb));
            Assert.Equal(1, allWords.Count(w => w.Type == WordType.Preposition));
            Assert.Equal(2, allWords.Count(w => w.Type == WordType.Article));
            Assert.Equal(5, allWords.Count(w => w.Type == WordType.Default));
        }
Exemplo n.º 2
0
        public void TextAnalizer_Analize_MoreThanOneSentence_Success()
        {
            var configuration = new Moq.Mock <IConfiguration>();

            Dictionary <string, IConfigurationSection> sections = new Dictionary <string, IConfigurationSection>();

            var prepositionSection = new Moq.Mock <IConfigurationSection>();

            prepositionSection.SetupGet(p => p.Value).Returns("para,ao,à");
            sections.Add("prepositions", prepositionSection.Object);

            var articlesSection = new Moq.Mock <IConfigurationSection>();

            articlesSection.SetupGet(p => p.Value).Returns("um,o,a,do,de");
            sections.Add("articles", articlesSection.Object);

            var setencesBreakersSection = new Moq.Mock <IConfigurationSection>();

            setencesBreakersSection.SetupGet(p => p.Value).Returns("que,e");
            sections.Add("setences_breakers", setencesBreakersSection.Object);

            var pontuationSection = new Moq.Mock <IConfigurationSection>();

            pontuationSection.SetupGet(p => p.Value).Returns(".|,");
            sections.Add("pontuation", pontuationSection.Object);

            var verbSection = new Moq.Mock <IConfigurationSection>();

            verbSection.SetupGet(p => p.Value).Returns("é");
            sections.Add("verbs", verbSection.Object);

            configuration
            .Setup(c => c.GetSection(Moq.It.IsAny <string>()))
            .Returns <string>((sectionName) => sections[sectionName]);

            var textAnalizer            = new TextAnalizer(configuration.Object);
            IEnumerable <Word> allWords = null;

            textAnalizer.OnExecuteFinished += (words) => allWords = words;
            textAnalizer.Execute("É nele que a campanha do Outubro Rosa, voltada à conscientização e prevenção ao câncer de mama, começa.");
            Assert.NotNull(allWords);
            Assert.Equal(16, allWords.Count());
            Assert.Equal(1, allWords.Count(w => w.Type == WordType.Verb));
            Assert.Equal(2, allWords.Count(w => w.Type == WordType.Preposition));
            Assert.Equal(3, allWords.Count(w => w.Type == WordType.Article));
            Assert.Equal(10, allWords.Count(w => w.Type == WordType.Default));
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .SetBasePath(Directory.GetCurrentDirectory())
                                    .AddJsonFile("appsettings.json", true, true)
                                    .Build();
            var webFeedReader      = new WebFeedReader("http://www.minutoseguros.com.br/blog/feed/");
            var wordCounter        = new WordCounter();
            var removeUselessWords = new RemoveUselessWords(config);
            var textAnalizer       = new TextAnalizer(config);
            var feed = new FeedCountImportantWords(textAnalizer, wordCounter);

            removeUselessWords.OnExecuteFinished += wordCounter.Execute;
            textAnalizer.OnExecuteFinished       += removeUselessWords.Execute;
            var feedAnalizer = new FeedAnalizer <Dictionary <string, int> >(webFeedReader, feed);

            feedAnalizer.OnArticleFinish += PrintReport;
            feedAnalizer.AnalizeFeed();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            string[] notAllowed = { "a", "the", "and", "of", "in", "be", "also", "as" };
            string   text       = System.IO.File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "TextToAnalyse.txt"));
            Result   result     = new Result();

            TextAnalizer analizer = new TextAnalizer();

            analizer.WordsNotAnalyzed.AddRange(notAllowed);
            analizer.RawText = text;

            Console.WriteLine("Text to Analize:");
            Console.WriteLine(text);
            Console.WriteLine("");
            Console.WriteLine("Sentences:");
            foreach (string sentence in analizer.Sentences)
            {
                //Write the sentence to analize
                Console.WriteLine(sentence);
                List <string> words = analizer.GetWordListFromSentence(sentence);
                foreach (string word in words)
                {
                    ResultItem item = new ResultItem();
                    item.word = word;
                    result.results.Add(item);
                }
            }
            ResultAnalysis.SortResults(result);
            ResultAnalysis.DeleteRepeatedResults(result);

            Result cleanList = new Result();

            foreach (ResultItem item in result.results)
            {
                Console.WriteLine(@"Finding words of the same meaning... """ + item.word + @"""");
                List <string> buffer = ResultAnalysis.GetSameWord(item.word, result);
                if (buffer != null)
                {
                    ResultItem newItem = new ResultItem();
                    newItem.word = item.word;
                    newItem.total_occurrences = ResultAnalysis.GetTotalOccurrences(buffer, analizer.RawText);
                    foreach (string sentence in analizer.Sentences)
                    {
                        newItem.sentence_indexes.AddRange(ResultAnalysis.GetSentenceIndexes(buffer, sentence));
                    }

                    cleanList.results.Add(newItem);
                }
            }

            Console.WriteLine("");
            Console.WriteLine("Result JSON:");
            Console.WriteLine("");

            Console.WriteLine(cleanList.ToJSONResolvit());

            Console.WriteLine("");
            Console.WriteLine("Press Any Key to Contnue...");

            Console.ReadKey();
        }