public void BuildSentimentBox(SearchResultModel model, SentimentValuator sentimentValuator) { var sentimentBox = new StatBox() { Title = "Sentimiento" }; model.StatBoxs.Add(sentimentBox); sentimentBox.StatItems.Add(new StatItem() { Title = "Positivas", Link = "#", Value = sentimentValuator.PositiveCount }); sentimentBox.StatItems.Add(new StatItem() { Title = "Negativas", Link = "#", Value = sentimentValuator.NegativeCount }); sentimentBox.StatItems.Add(new StatItem() { Title = "Neutras", Link = "#", Value = sentimentValuator.NeutralCount }); if (model.Items.Count > 0) { sentimentBox.StatItems[0].ValueText = ((decimal)sentimentValuator.PositiveCount / model.Items.Count * 100).ToString("f") + "%"; sentimentBox.StatItems[1].ValueText = ((decimal)sentimentValuator.NegativeCount / model.Items.Count * 100).ToString("f") + "%"; sentimentBox.StatItems[2].ValueText = ((decimal)sentimentValuator.NeutralCount / model.Items.Count * 100).ToString("f") + "%"; sentimentBox.StatItems[0].ValuePercent = ((decimal)sentimentValuator.PositiveCount / model.Items.Count * 100); sentimentBox.StatItems[1].ValuePercent = ((decimal)sentimentValuator.NegativeCount / model.Items.Count * 100); sentimentBox.StatItems[2].ValuePercent = ((decimal)sentimentValuator.NeutralCount / model.Items.Count * 100); } else { sentimentBox.StatItems[0].ValueText = "0%"; sentimentBox.StatItems[1].ValueText = "0%"; sentimentBox.StatItems[2].ValueText = "0%"; sentimentBox.StatItems[0].ValuePercent = 0; sentimentBox.StatItems[1].ValuePercent = 0; sentimentBox.StatItems[2].ValuePercent = 0; } }
public void Initialize() { log4net.Config.XmlConfigurator.Configure(); _logger = LogManager.GetLogger(GetType()); _logger.Info("====== Initializing Service ======\n\n"); _serviceManager = new ServicesManager(); _searchEngineManager = new SearchEngineManager(); _logger.Info("\n\n====== SETTING UP SENTIMENT EVALUATOR ======\n\n"); var negativeWords = _serviceManager.GetAllWords().Where(x => x.Sentiment == "Negativo").Select(x => x.Name).ToList(); var positiveWords = _serviceManager.GetAllWords().Where(x => x.Sentiment == "Positivo").Select(x => x.Name).ToList(); var ignoreList = new List<string>() { ".", "," }; _sentimentValuator = new SentimentValuator { NegativeWords = negativeWords, PositiveWords = positiveWords, IgnoreChars = ignoreList }; _logger.Info("\n\n====== SENTIMENT EVALUATOR SET UP SUCCESSFULLY ======\n\n"); SearchEngineManager.ConfigureAddins(); _logger.Info("\n\n====== Service Initialized ======\n\n"); }
public JsonResult SearchResults(string parameters, string searchEngines, string sentiment, string socialNetworking, string userName) { var result = new List<Post>(); var model = new SearchResultModel(); if (ModelState.IsValid) { var searchEngineManager = new SearchEngineManager(); result = searchEngineManager.Search(parameters, searchEngines.Split(',').ToList()); result = result.OrderByDescending(o => o.CreatedAt).ToList(); if (result.Count > 0) { GetAllWords(); var sentimentValuator = new SentimentValuator { NegativeWords = negativeWords, PositiveWords = positiveWords, IgnoreChars = ignoreList }; foreach (var item in result) { sentimentValuator.ProcessItem(item); if (string.IsNullOrEmpty(sentiment) && string.IsNullOrEmpty(socialNetworking) && string.IsNullOrEmpty(userName)) model.Items.Add(item); else if (ValidateFilters(sentiment, socialNetworking, userName, item)) model.Items.Add(item); } sentimentValuator.ResetCounters(); foreach (var item in model.Items) { sentimentValuator.ProcessItem(item); } BuildSentimentBox(model, sentimentValuator); BuildEnginesBox(model); BuildTopUsersBox(model); } } return Json(model, JsonRequestBehavior.AllowGet); }