コード例 #1
0
 public WebSearchServices()
 {
     searchUtilities = new GoogleAPIs.CustomSearch.SearchUtilities();
     m_serviceLayer = new ServiceLayerImpl();
 }
コード例 #2
0
        public void TrainByGoogleSearchResult(string classifierName)
        {
            List<RestaurantBasicData> restsList = restaurantsSearchUtilty.GetAllRestaurantsWithBackOfficeSource();
            List<string> safeSourceList = new List<string>();

            //int count = 0;
            log.InfoFormat("[TrainByGoogleSearchResult] Restaurants.Count={0}.", restsList.Count);

            GoogleAPIs.CustomSearch.SearchUtilities customSearchUtil = new GoogleAPIs.CustomSearch.SearchUtilities();

            foreach (var rest in restsList)
            {
                //if (count > 10) break;
                var tempQueryPattern = new RestaurantQueryPattern(rest);
                var result = ClassifyUtility.ClassifyUnit(tempQueryPattern, "CuisinesByDescription");
                List<Classifier.uClassify.Models.Response.Class> bestClassifyResult = null;
                WebSearchResult bestGoogleSearch = null;
                if (result != null && rest.SearchResults != null)
                {
                    log.InfoFormat("[TrainByGoogleSearchResult] Restaurant.Name={0}, Restaurant.Id={1}, BestResult={2}, ResultProbability={3}.", rest.Name, rest.Id.ToString(), result[0].className, result[0].p.ToString());

                    foreach (var item in rest.SearchResults)
                    {
                        if (!string.IsNullOrEmpty(item.Snippet))
                        {
                            //tempQueryPattern.Description = item.Snippet;
                            //var tempResult = ClassifyUtility.ClassifyUnit(tempQueryPattern, "CuisinesTest");
                            var tempResult = ClassifyUtility.Classify(item.Snippet, "CuisinesTest");

                            if (tempResult != null && tempResult[0].p > 0.2 && (bestClassifyResult == null || bestClassifyResult[0].p < tempResult[0].p) && result[0].className == tempResult[0].className)
                            {
                                bestClassifyResult = new List<Classifier.uClassify.Models.Response.Class>(tempResult);
                                bestGoogleSearch = item;
                            }
                        }
                    }

                    if (bestClassifyResult != null && bestGoogleSearch != null)
                    {
                        if (!safeSourceList.Contains(bestGoogleSearch.Source)) safeSourceList.Add(bestGoogleSearch.Source);
                        Classifier.uClassify.TrainUtility.Train(bestGoogleSearch.Snippet, bestClassifyResult[0].className, classifierName);
                        log.InfoFormat("[TrainByGoogleSearchResult] After Google Search, Restaurant.Name={0}, Restaurant.Id={1}, BestResult={2}, ResultProbability={3}, item.DisplayLink={4}, item.Snippet={5}.", rest.Name, rest.Id.ToString(), bestClassifyResult[0].className, bestClassifyResult[0].p.ToString(), bestGoogleSearch.Source, bestGoogleSearch.Snippet);
                    }

                }
                else
                {
                    log.WarnFormat("[TrainByGoogleSearchResult] Null result for Restaurant.Name={0}, Restaurant.Id={1}.", rest.Name, rest.Id.ToString());
                }
            }
            log.InfoFormat("[TrainByGoogleSearchResult] safeSourceList={0}.", String.Join(", ", safeSourceList.ToArray()));
        }