예제 #1
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);
        }
예제 #2
0
        private static Ingredient GetMappedIngredient(string text)
        {
            LoadIngredients();
            var connString         = ConfigurationManager.ConnectionStrings["Recipes"].ConnectionString;
            var repo               = new NoiseWordsRepository(connString);
            var reciperepo         = new RecipeReadRepositoryOld(connString);
            var cleaner            = new IngredientsTextCleaner(repo, reciperepo);
            var similarityComputer = new IngredientsSimilarityComputer(cleaner, "RO");

            var cleaned = cleaner.Clean(text.ToLowerInvariant(), "RO");

            cleaned = cleaned.GetCleanIngredientName();

            var ing = _ingredients.Select(i => Tuple.Create <Ingredient, double>(i, similarityComputer.ComputeSimilarity(cleaned, i.Name)))
                      .OrderByDescending(t => t.Item2)
                      .FirstOrDefault();

            if (ing == null)
            {
                return(null);
            }

            return(ing.Item1);
        }
예제 #3
0
        private static void ImportIngrediants()
        {
            var connString = ConfigurationManager.ConnectionStrings["Recipes"].ConnectionString;
            var repo       = new NoiseWordsRepository(connString);
            var reciperepo = new RecipeReadRepositoryOld(connString);
            var cleaner    = new IngredientsTextCleaner(repo, reciperepo);

            var files   = Directory.GetFiles(@"E:\UnicaRecipes\");
            var ingrepo = new IngredientsWriteRepository(ConfigurationManager.ConnectionStrings["Recipes"].ConnectionString);

            var ingredients = new List <string>();

            foreach (var file in files)
            {
                var json    = File.ReadAllText(file);
                var recipes = JsonConvert.DeserializeObject <List <CrawledRecipe> >(json);
                ingredients.AddRange(recipes.SelectMany(recipe => recipe.Ingredients).Distinct());
            }

            var cleanIngredinets = ingredients.Select(i => cleaner.Clean(i.ToLowerInvariant(), "RO")).ToList();

            var importer = new IngredientsImporter();
            //importer.ImportIngredients(ingredients.Distinct());
        }