Classifier.CuisinesClassifier.RestaurantsClassifier.Classify C# (CSharp) Method

Classify() public method

public Classify ( ) : List
return List
        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;
            }
        }

Usage Example

        public void ClassifyTest_ShouldSaveResults_UpdateRestaurantsInDB()
        {
            string classifierName = "CuisinesSupervised1";
            RealTenTestRestaurants restaurantsSource = new RealTenTestRestaurants();

            RestaurantsClassifier restClassifier = new RestaurantsClassifier(restaurantsSource, classifierName);

            var classified = restClassifier.Classify();
            restClassifier.SaveResults();

            //Assert
            Assert.IsNotNull(classified);
        }
All Usage Examples Of Classifier.CuisinesClassifier.RestaurantsClassifier::Classify