public RecipeCreator(IKpcContext context)
        {
            this.context = context;
            this.recipe = new Recipe();

            this.recipe.DateEntered = DateTime.Now;
        }
コード例 #2
0
        private static void CategorizeMeal(Recipe recipe, CategorizationResult result, Analyzer analyzer)
        {
            IRecipeClassification trainedRecipe;
            if (analyzer.CheckIfTrained(recipe.Id, out trainedRecipe))
            {
                result.MealBreakfast = trainedRecipe.IsBreakfast;
                result.MealLunch = trainedRecipe.IsLunch;
                result.MealDinner = trainedRecipe.IsDinner;
                result.MealDessert = trainedRecipe.IsDessert;
            }
            else
            {
                var analysis = analyzer.GetPrediction(recipe);

                result.MealBreakfast =
                    analysis.FirstPlace.Equals(Category.Breakfast) ||
                    analysis.SecondPlace.Equals(Category.Breakfast);
                result.MealLunch =
                    analysis.FirstPlace.Equals(Category.Lunch) ||
                    analysis.SecondPlace.Equals(Category.Lunch);
                result.MealDinner =
                    analysis.FirstPlace.Equals(Category.Dinner) ||
                    analysis.SecondPlace.Equals(Category.Dinner);
                result.MealDessert =
                    analysis.FirstPlace.Equals(Category.Dessert) ||
                    analysis.SecondPlace.Equals(Category.Dessert);
            }
        }
コード例 #3
0
        public RecipeRater(IKPCContext context, Recipe recipe, Rating rating)
        {
            this.context = context;
            this.newRatings = new Dictionary<Recipe, Rating>();

            this.newRatings.Add(recipe, rating);
        }
コード例 #4
0
        public RecipeClassification(Recipe recipe, RecipeTag tag)
        {
            this.Recipe = recipe;

            this.IsBreakfast = tag == RecipeTag.Breakfast;
            this.IsLunch = tag == RecipeTag.Lunch;
            this.IsDinner = tag == RecipeTag.Dinner;
            this.IsDessert = tag == RecipeTag.Dessert;
        }
コード例 #5
0
        public MenuUpdater Add(Recipe recipe)
        {
            if (!this.addQueue.Contains(recipe))
            {
                this.addQueue.Add(recipe);
            }

            return this;
        }
コード例 #6
0
ファイル: Tokenizer.cs プロジェクト: relimited/core
        static readonly Regex valid = new Regex(@"[a-z]", RegexOptions.IgnoreCase); //All tokens have to have at least one letter in them

        #endregion Fields

        #region Methods

        public static IEnumerable<IToken> Tokenize(Recipe recipe)
        {
            var tokens = new List<IToken>();
             tokens.AddRange(ParseText(recipe.Title ?? ""));
             tokens.AddRange(ParseText(recipe.Description ?? ""));
             //tokens.AddRange(ParseText(recipe.Method ?? ""));
             //tokens.Add(new TimeToken(recipe.CookTime.GetValueOrDefault() + recipe.PrepTime.GetValueOrDefault()));
             tokens.AddRange(from i in recipe.Ingredients.NeverNull() select new IngredientToken(i.Ingredient) as IToken);

             return tokens;
        }
 public RecipeBrief(Recipe recipe)
 {
     this.Id = recipe.Id;
     this.OwnerId = recipe.OwnerId;
     this.Title = recipe.Title;
     this.Description = recipe.Description;
     this.ImageUrl = recipe.ImageUrl;
     this.Author = recipe.OwnerAlias;
     this.PreparationTime = recipe.PreparationTime;
     this.CookingTime = recipe.CookingTime;
     this.AverageRating = recipe.AverageRating;
 }
コード例 #8
0
ファイル: RecipeBrief.cs プロジェクト: relimited/core
 public RecipeBrief(Recipe r)
 {
     this.Id = r.Id;
      this.OwnerId = r.OwnerId;
      this.Title = r.Title;
      this.Description = r.Description;
      this.ImageUrl = r.ImageUrl;
      this.Author = r.OwnerAlias;
      this.PrepTime = r.PrepTime;
      this.CookTime = r.CookTime;
      this.AvgRating = r.AvgRating;
 }
        public CategorizationResult Categorize(Recipe recipe)
        {
            var result = new CategorizationResult();

             CategorizeMeal(recipe, result, analyzer);
             CategorizeDiet(recipe, result);
             CategorizeNutrition(recipe, result);
             CategorizeSkill(recipe, result);
             CategorizeTaste(recipe, result);

             return result;
        }
        public static Recipe MockRecipe(string title, string desc, RecipeTags tags = null)
        {
            var ret = new Recipe(Guid.NewGuid(), title, desc, null);

            ret.Method = "This is a mock recipe.";
            ret.OwnerAlias = "Fake Owner";
            ret.OwnerId = Guid.NewGuid();
            ret.PermanentLink = "http://www.kitchenpc.com/123";
            ret.ServingSize = 5;
            ret.Tags = tags;

            return ret;
        }
コード例 #11
0
ファイル: Tokenizer.cs プロジェクト: KaloyanTodorov/Teamwork
        // What should IToken have? Should Token be a Generic Item<T>?
        public static IEnumerable<IToken> Tokenize(Recipe recipe)
        {
            var tokens = new List<IToken>();
            tokens.AddRange(ParseText(recipe.Title ?? string.Empty));
            tokens.AddRange(ParseText(recipe.Description ?? string.Empty));
            tokens.AddRange(ParseText(recipe.Method ?? string.Empty));
            tokens.Add(new TimeToken(recipe.CookTime + recipe.PrepTime));
            tokens.AddRange(
                recipe.Ingredients.NeverNull()
                    .Select(ingredientUsage => new IngredientToken(ingredientUsage.Ingredient)));

            return tokens;
        }
コード例 #12
0
 public void Add(Recipe recipe)
 {
     var tokens = Tokenizer.Tokenize(recipe);
     foreach (var token in tokens)
     {
         if (this.index.ContainsKey(token))
         {
             this.index[token]++;
         }
         else
         {
             this.index.Add(token, 1);
         }
     }
 }
コード例 #13
0
        private void CategorizeDiet(Recipe recipe, CategorizationResult result)
        {
            var ingredientMeta = recipe.Ingredients.Select(ing => ing.Ingredient.Metadata).ToArray();

            var glutenFree = ingredientMeta.All(ing => ing.HasGluten == false);
            var noAnimals = ingredientMeta.All(ing => ing.HasAnimal == false);
            var noMeat = ingredientMeta.All(ing => ing.HasMeat == false);
            var noPork = ingredientMeta.All(ing => ing.HasPork == false);
            var noRedMeat = ingredientMeta.All(ing => ing.HasRedMeat == false);

            result.DietGlutenFree = glutenFree;
            result.DietNoAnimals = noAnimals;
            result.DietNoMeat = noMeat;
            result.DietNoPork = noPork;
            result.DietNoRedMeat = noRedMeat;
        }
        static void CategorizeDiet(Recipe recipe, CategorizationResult result)
        {
            var ingmeta = (from ing in recipe.Ingredients select ing.Ingredient.Metadata).ToArray();

             var glutenFree = ingmeta.All(ing => ing.HasGluten == false);
             var noAnimals = ingmeta.All(ing => ing.HasAnimal == false);
             var noMeat = ingmeta.All(ing => ing.HasMeat == false);
             var noPork = ingmeta.All(ing => ing.HasPork == false);
             var noRed = ingmeta.All(ing => ing.HasRedMeat == false);

             result.Diet_GlutenFree = glutenFree;
             result.Diet_NoAnimals = noAnimals;
             result.Diet_NoMeat = noMeat;
             result.Diet_NoPork = noPork;
             result.Diet_NoRedMeat = noRed;
        }
コード例 #15
0
        public AnalyzerResult GetPrediction(Recipe recipe)
        {
            var winsBreakfast = new Ranking(Category.Breakfast);
            var winsLunch = new Ranking(Category.Lunch);
            var winsDinner = new Ranking(Category.Dinner);
            var winsDessert = new Ranking(Category.Dessert);

            // Setup Tournament
            this.Compete(recipe, this.breakfastIndex, this.lunchIndex, winsBreakfast, winsLunch, winsDinner, winsDessert);
            this.Compete(recipe, this.breakfastIndex, this.dinnerIndex, winsBreakfast, winsLunch, winsDinner, winsDessert);
            this.Compete(recipe, this.breakfastIndex, this.dessertIndex, winsBreakfast, winsLunch, winsDinner, winsDessert);
            this.Compete(recipe, this.lunchIndex, this.dinnerIndex, winsBreakfast, winsLunch, winsDinner, winsDessert);
            this.Compete(recipe, this.lunchIndex, this.dessertIndex, winsBreakfast, winsLunch, winsDinner, winsDessert);
            this.Compete(recipe, this.dinnerIndex, this.dessertIndex, winsBreakfast, winsLunch, winsDinner, winsDessert);

            // Choose winner
            var result = GetWinner(winsBreakfast, winsLunch, winsDinner, winsDessert);
            return result;
        }
コード例 #16
0
        private void CategorizeMeal(Recipe recipe, CategorizationResult result)
        {
            IRecipeClassification trainedRecipe = this.analyzer.GetTrainedRecipe(recipe.Id);
            if (trainedRecipe != null)
            {
                result.MealBreakfast = trainedRecipe.IsBreakfast;
                result.MealLunch = trainedRecipe.IsLunch;
                result.MealDinner = trainedRecipe.IsDinner;
                result.MealDessert = trainedRecipe.IsDessert;
            }
            else
            {
                var analysis = this.analyzer.GetPrediction(recipe);

                result.MealBreakfast = analysis.FirstPlace.Equals(Category.Breakfast) || analysis.SecondPlace.Equals(Category.Breakfast);
                result.MealLunch = analysis.FirstPlace.Equals(Category.Lunch) || analysis.SecondPlace.Equals(Category.Lunch);
                result.MealDinner = analysis.FirstPlace.Equals(Category.Dinner) || analysis.SecondPlace.Equals(Category.Dinner);
                result.MealDessert = analysis.FirstPlace.Equals(Category.Dessert) || analysis.SecondPlace.Equals(Category.Dessert);
            }
        }
コード例 #17
0
        public static IngredientSection[] GetSections(Recipe recipe)
        {
            //TODO: This code can probably be done in a LINQ expression, or more efficiently.

            var nullSection = new IngredientSection(null);
            var map = new Dictionary<string, IngredientSection>();

            foreach (var usage in recipe.Ingredients)
            {
                if (string.IsNullOrEmpty(usage.Section))
                {
                    nullSection.Ingredients.Add(usage);
                }
                else
                {
                    var sectionKey = usage.Section.ToLower();

                    IngredientSection sectionList;
                    if (map.TryGetValue(sectionKey, out sectionList))
                    {
                        sectionList.Ingredients.Add(usage);
                    }
                    else
                    {
                        sectionList = new IngredientSection(usage.Section);
                        sectionList.Ingredients.Add(usage);
                        map.Add(sectionKey, sectionList);
                    }
                }
            }

            var result = new List<IngredientSection>();
            if (nullSection.Ingredients.Count > 0)
            {
                result.Add(nullSection);
            }

            result.AddRange(map.Values);

            return result.ToArray();
        }
        public AnalyzerResult GetPrediction(Recipe recipe)
        {
            var winsBr = new Ranking(Category.Breakfast);
             var winsLu = new Ranking(Category.Lunch);
             var winsDi = new Ranking(Category.Dinner);
             var winsDe = new Ranking(Category.Dessert);

             //Setup Tournament
             Compete(recipe, BreakfastIndex, LunchIndex, winsBr, winsLu, winsDi, winsDe);
             Compete(recipe, BreakfastIndex, DinnerIndex, winsBr, winsLu, winsDi, winsDe);
             Compete(recipe, BreakfastIndex, DessertIndex, winsBr, winsLu, winsDi, winsDe);
             Compete(recipe, LunchIndex, DinnerIndex, winsBr, winsLu, winsDi, winsDe);
             Compete(recipe, LunchIndex, DessertIndex, winsBr, winsLu, winsDi, winsDe);
             Compete(recipe, DinnerIndex, DessertIndex, winsBr, winsLu, winsDi, winsDe);

             //Choose winner
             Ranking tag1, tag2;
             var result = GetWinner(winsBr, winsLu, winsDi, winsDe, out tag1, out tag2);

             return result;
        }
コード例 #19
0
ファイル: MockContext.cs プロジェクト: relimited/core
 public RecipeResult CreateRecipe(Recipe recipe)
 {
     throw new NotImplementedException();
 }
コード例 #20
0
 public RecipeLoader(IKPCContext context, Recipe recipe)
 {
     this.context = context;
     this.recipesToLoad = new List<Recipe>() { recipe };
 }
コード例 #21
0
 public RecipeLoader Load(Recipe recipe)
 {
     this.recipesToLoad.Add(recipe);
     return this;
 }
コード例 #22
0
ファイル: Analyzer.cs プロジェクト: KaloyanTodorov/Teamwork
        private void Compete(Recipe entry, RecipeIndex first, RecipeIndex second, Ranking rankBreakfast, Ranking rankLunch, Ranking rankDinner, Ranking rankDessert)
        {
            var chance = this.GetPrediction(entry, first, second);
            if (chance > 0.5f - Tolerance && chance < 0.5f + Tolerance)
            {
                return; // No winner
            }

            var diff = (float)Math.Abs(chance - 0.5);
            var winner = chance < 0.5 ? second : first;

            if (winner == this.breakfastIndex)
            {
                rankBreakfast.Score += diff;
            }

            if (winner == this.lunchIndex)
            {
                rankLunch.Score += diff;
            }

            if (winner == this.dinnerIndex)
            {
                rankDinner.Score += diff;
            }

            if (winner == this.dessertIndex)
            {
                rankDessert.Score += diff;
            }
        }
コード例 #23
0
 public RecipeResult CreateRecipe(Recipe recipe)
 {
     this.CRCalledTimes++;
     return new RecipeResult();
 }
        public static void Validate(Recipe recipe)
        {
            if (String.IsNullOrEmpty(recipe.Title) || recipe.Title.Trim().Length == 0)
             {
            throw new InvalidRecipeDataException("A recipe title is required.");
             }

             if (recipe.PrepTime < 0)
             {
            throw new InvalidRecipeDataException("PrepTime must be equal to or greater than zero.");
             }

             if (recipe.CookTime < 0)
             {
            throw new InvalidRecipeDataException("CookTime must be equal to or greater than zero.");
             }

             if (recipe.ServingSize <= 0)
             {
            throw new InvalidRecipeDataException("ServingSize must be greater than zero.");
             }

             if (recipe.Ingredients == null || recipe.Ingredients.Length == 0)
             {
            throw new InvalidRecipeDataException("Recipes must contain at least one ingredient.");
             }

             if (recipe.Tags == null || recipe.Tags.Length == 0)
             {
            throw new InvalidRecipeDataException("Recipes must contain at least one tag.");
             }

             if (recipe.Description != null && recipe.Description.Length > 250)
             {
            recipe.Description = recipe.Description.Substring(0, 250) + "...";
             }

             if (recipe.CreditUrl != null)
             {
            const string pattern = @"^https?\://(?<domain>[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3})(/\S*)?$";
            var m = Regex.Match(recipe.CreditUrl, pattern);
            if (m.Success && m.Groups["domain"].Success)
            {
               recipe.CreditUrl = m.Value;
               recipe.Credit = m.Groups["domain"].Value.ToLower(); //TODO: Clean up domain name
            }
            else //Bad URL, clear Credit info
            {
               recipe.Credit = null;
               recipe.CreditUrl = null;
            }
             }
        }
        public ProfileCreator AddRating(Recipe recipe, byte rating)
        {
            ratings.Add(new RecipeRating
             {
            RecipeId = recipe.Id,
            Rating = rating
             });

             return this;
        }
コード例 #26
0
ファイル: MockContext.cs プロジェクト: relimited/core
 public ShoppingListResult CreateShoppingList(string name, Recipe[] recipes, Ingredient[] ingredients, IngredientUsage[] usages, string[] items)
 {
     throw new NotImplementedException();
 }
コード例 #27
0
 public RecipeEnqueuer Recipe(Recipe recipe)
 {
     this.recipesQueue.Add(recipe);
     return this;
 }
コード例 #28
0
ファイル: Analyzer.cs プロジェクト: KaloyanTodorov/Teamwork
        private float GetPrediction(Recipe recipe, RecipeIndex first, RecipeIndex second)
        {
            // Reset probability and invertedProbability
            this.invertedProbability = 0;
            this.probability = 0;

            var tokens = Tokenizer.Tokenize(recipe);

            foreach (var token in tokens)
            {
                var firstRITokensCount = first.GetTokenCount(token);
                var secondRITokensCount = second.GetTokenCount(token);

                this.CalcProbability(firstRITokensCount, first.EntryCount, secondRITokensCount, second.EntryCount);
            }

            var prediction = this.probability / (this.probability + this.invertedProbability);
            return prediction;
        }
 public ProfileCreator AvoidRecipe(Recipe recipe)
 {
     avoidRecipe = recipe.Id;
      return this;
 }
コード例 #30
0
 public RecipeRater Rate(Recipe recipe, Rating rating)
 {
     var result = new RecipeRater(this.context, recipe, rating);
     return result;
 }