Classify() 공개 메소드

public Classify ( ) : List
리턴 List
        public void ClassifyTest_ShouldReturnNotEmptyResults()
        {
            RestaurantBasicData rest = new RestaurantBasicData()
            {
                Name = "פלאפל ג'ינה",
                Adress = new Address() { City = "תל אביב" }
            };
            string classifierName = "CuisinesSupervised1";

            SearchEngineResultClassificator searchClassifier = new SearchEngineResultClassificator(rest, classifierName);

            //act
            var results = searchClassifier.Classify();

            //Assert
            Assert.IsNotNull(results);
        }
예제 #2
0
        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;
            }
        }