コード例 #1
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");
        }
コード例 #2
0
        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);
        }