public void SearchResultsClassificationQualityFilter_ShouldReturnAllFilteredResultsForSameWebSearch()
        {
            WebSearchClassifyResult result1 = new WebSearchClassifyResult()
            {
                Result = "falafel",
                Propability = 0.56,
                SearchResult = new WebSearchResult()
                {
                    SearchEngine = "Google",
                    Source = "www.test1.com",
                    Snippet = "פלפליה מקומית, וגם חומוס, הזמנת משלוחים"
                }
            };
            WebSearchClassifyResult result2 = new WebSearchClassifyResult()
            {
                Result = "Hummus",
                Propability = 0.52,
                SearchResult = new WebSearchResult()
                {
                    SearchEngine = "Google",
                    Source = "www.test1.com",
                    Snippet = "פלפליה מקומית, וגם חומוס, הזמנת משלוחים"
                }
            };
            WebSearchClassifyResult result3 = new WebSearchClassifyResult()
            {
                Result = "kebab",
                Propability = 0.53,
                SearchResult = new WebSearchResult()
                {
                    SearchEngine = "Google",
                    Source = "www.test2.com",
                    Snippet = "בשרים על האש"
                }
            };
            List<WebSearchClassifyResult> notQualifiedList = new List<WebSearchClassifyResult>() { result1, result2, result3 };

            SearchResultsClassificationQualityFilter filter = new SearchResultsClassificationQualityFilter(notQualifiedList);

            //act
            var qualifiedResults = filter.Qualify();

            //Assert
            Assert.IsNotNull(qualifiedResults);
            Assert.IsTrue(qualifiedResults.Count == 2);
            Assert.IsTrue(qualifiedResults[0].Propability == 0.56);
            Assert.IsTrue(qualifiedResults[1].Propability == 0.52);
        }
        public List<RestaurantBasicData> Classify()
        {
            try
            {
                restaurantsToClassify = restaurantsSource.GetRestaurants();
                if (restaurantsToClassify != null && restaurantsToClassify.Count > 0)
                {
                    foreach (var rest in restaurantsToClassify)
                    {
                        List<ClassifyResult> classifyResults = new List<ClassifyResult>();
                        try
                        {
                            //Classify by restaurants info
                            RestaurantInfoClassificator restInfoClassify = new RestaurantInfoClassificator(rest, classifier);
                            classifyResults = restInfoClassify.Classify();

                            ClassificationQualityFilter filter = new ClassificationQualityFilter(classifyResults);
                            var filteredResults = filter.Qualify();

                            if (filteredResults != null && filteredResults.Count > 0)
                            {
                                GetCuisinesByClassifierResults getCuisines = new GetCuisinesByClassifierResults(rest, filteredResults);
                                if (getCuisines.GetCuisines() != null)
                                {
                                    classifiedByRestInfo.Add(rest);

                                    log.InfoFormat("[Classify] Classified by rest info: restaurant.Name={0}, restaurant.Id={1}, classifierName={2}, filteredResults.Count={3}, filteredResults={4}.",
                                        rest.Name, rest.Id.ToString(), classifier, filteredResults.Count, filteredResults.ExtendedToString());
                                }
                                else
                                {
                                    log.InfoFormat("[Classify] Not found cuisines by rest info classification: restaurant.Name={0}, restaurant.Id={1}, classifierName={2}, filteredResults.Count={3}, filteredResults={4}.",
                                        rest.Name, rest.Id.ToString(), classifier, filteredResults.Count, filteredResults.ExtendedToString());
                                    notClassified.Add(rest);
                                }
                            }
                            else
                            {
                                log.DebugFormat("[Classify] No qualified result by restaurant info for: restaurant.Name={0}, restaurant.Id={1}, classifierName={2}, classifyQuery={3}.",
                                    rest.Name, rest.Id.ToString(), classifier);

                                List<WebSearchClassifyResult> webSearchClassifyResults = new List<WebSearchClassifyResult>();
                                //Classify by WebSearch
                                SearchEngineResultClassificator searchClassifier = new SearchEngineResultClassificator(rest, classifier);
                                webSearchClassifyResults = searchClassifier.Classify();
                                SearchResultsClassificationQualityFilter webSearchResultFilter = new SearchResultsClassificationQualityFilter(webSearchClassifyResults);
                                List<WebSearchClassifyResult> searchFilteredResults = webSearchResultFilter.Qualify();
                                if (searchFilteredResults != null)
                                {
                                    List<ClassifyResult> tempClassifyResults = searchFilteredResults.Cast<ClassifyResult>().ToList();
                                    GetCuisinesByClassifierResults getCuisines = new GetCuisinesByClassifierResults(rest, tempClassifyResults);
                                    if (getCuisines.GetCuisines() != null)
                                    {
                                        if (rest.SearchResults == null) rest.SearchResults = new List<WebSearchResult>();
                                        rest.SearchResults.Add(searchFilteredResults[0].SearchResult);

                                        classifiedByWebSearch.Add(rest);

                                        log.InfoFormat("[Classify] Classified by WebSearch: restaurant.Name={0}, restaurant.Id={1}, classifierName={2}, filteredResults.Count={4}, filteredResults={5}.",
                                            rest.Name, rest.Id.ToString(), classifier, searchFilteredResults.Count, searchFilteredResults.ExtendedToString());
                                    }
                                    else
                                    {
                                        log.InfoFormat("[Classify] Not found cuisines by WebSearch classification: restaurant.Name={0}, restaurant.Id={1}, classifierName={2}, filteredResults.Count={4}, filteredResults={5}.",
                                            rest.Name, rest.Id.ToString(), classifier, searchFilteredResults.Count, searchFilteredResults.ExtendedToString());
                                        notClassified.Add(rest);
                                    }

                                }
                                else
                                {
                                    log.DebugFormat("[Classify] No qualified result by WebSearch for: restaurant.Name={0}, restaurant.Id={1}, classifierName={2}.",
                                    rest.Name, rest.Id.ToString());
                                    notClassified.Add(rest);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            log.ErrorFormat("[RestaurantsClassifier] Exception={0}, rest.Name={1}, rest.Id={2}.", e.Message, rest.Name, rest.Id.ToString());
                        }
                    }

                    if (classifiedByRestInfo.Count > 0) allClassified.AddRange(classifiedByRestInfo);
                    if (classifiedByWebSearch.Count > 0) allClassified.AddRange(classifiedByWebSearch);
                    log.InfoFormat("[RestaurantsClassifier] restaurantsToClassify.Count={0}, allClassified={1}, classifiedByRestInfo.Count={2}, classifiedByWebSearch.Count={3}, notClassified.Count={4}.",
                        restaurantsToClassify.Count.ToString(), allClassified.Count.ToString(), classifiedByRestInfo.Count.ToString(), classifiedByWebSearch.Count.ToString(), notClassified.Count.ToString());
                    return allClassified;
                }
                else
                {
                    log.DebugFormat("[RestaurantsClassifier] Not found restaurants for classify by restaurantsSource={0}.", restaurantsSource.ToString());
                }
                return null;
            }
            catch (Exception e)
            {
                log.ErrorFormat("[RestaurantsClassifier] Exception={0}.", e.Message);
                return null;
            }
        }