Пример #1
0
        private static void LoadIngredients()
        {
            if (_ingredients == null || _ingredients.Count() == 0)
            {
                var connString = ConfigurationManager.ConnectionStrings["Recipes"].ConnectionString;

                var ingredientsRepo = new IngredientsReadRepositoryOld(connString);
                _ingredients = ingredientsRepo.GetAllIngredienst();
            }
        }
Пример #2
0
        private static void Map()
        {
            var connString      = ConfigurationManager.ConnectionStrings["Recipes"].ConnectionString;
            var ingredientsRepo = new IngredientsReadRepositoryOld(connString);
            var reciperepo      = new RecipeReadRepositoryOld(connString);

            var repo = new NoiseWordsRepository(connString);

            var cleaner = new IngredientsTextCleaner(repo, reciperepo);

            var vendorRepo = new VendorWriteRepository(connString);

            var vendorProducts     = reciperepo.GetAllVendorProducts();
            var ingredients        = ingredientsRepo.GetAllIngredienst();
            var mappings           = new List <VendorProductIngredient>();
            var similarityComputer = new IngredientsSimilarityComputer(cleaner, "RO");

            var cleandProducts = vendorProducts.Select(p =>
            {
                p.Title = cleaner.Clean(p.Title.ToLowerInvariant(), "RO");
                return(p);
            }).Select(p => new Ingredient {
                Name = p.Title, IdLanguage = 1
            }).ToList();

            var cleanedIngredients = ingredients.Select(i =>
            {
                i.Name = cleaner.Clean(i.Name.ToLowerInvariant(), "RO", false);
                return(i);
            }).ToList();

            foreach (var cleanedProduct in cleandProducts)
            {
                var tempMappings = cleanedIngredients.Select(ing => new VendorProductIngredient
                {
                    IdIngredient      = ing.Id,
                    IdProduct         = cleanedProduct.Id,
                    MappingConfidence = similarityComputer.ComputeSimilarity(ing.Name, cleanedProduct.Name)
                });

                var mappingList   = tempMappings.OrderByDescending(m => m.MappingConfidence).ToList();
                var maxConfidence = mappingList.FirstOrDefault();

                var finalList = mappingList.Where(m => m.MappingConfidence == maxConfidence.MappingConfidence)
                                .Where(m => m.MappingConfidence > 0.76);

                mappings.AddRange(finalList);
            }

            vendorRepo.CreateProductIngredientMappings(mappings);
        }