Skip to content

Let’s Make a Recipe!

February 14, 2014

The Beta version of KitchenPC allowed users to enter their own recipes, but it was such a giant pain, pretty much no one did it. The re-launch gave KitchenPC a new goal; to be a powerful recipe search engine, where existing recipes were collected from all over the Internet.

However, the KitchenPC platform allows you to add new recipes to the database. This could be done through a UI, an automated process, crawler, etc.

To do so, we use the fluent Recipes.Create action:

var result = context.Recipes
   .WithTitle("Puff Pancake")
   .WithCreditUrl(new Uri(""))
   .WithImage(new Uri(""))
   .WithDescription("Great for breakfast!")
   .WithMethod("Mix everything together, pour in a glass pie dish, bake for 23 minutes at 400 degrees.")
   .WithTags(RecipeTag.Breakfast | RecipeTag.NoMeat | RecipeTag.Easy)
   .WithIngredients(i => i
      .AddRaw("4 eggs")
      .AddRaw("1 cup flour")
      .AddRaw("1 cup milk")

Obviously, some of these properties are optional, but you get the idea. The WithIngredients method is fairly flexible as to how you can express ingredients. The easiest way, as shown above, is to call AddRaw, which invokes the natural language parser to understand ingredient usages. As all recipes in KitchenPC must be normalized, KitchenPC will throw an exception if it is unable to parse an ingredient usage.

You can also manually specify an ingredient or usage, using AddIngredient or AddIngredientUsage:

.WithIngredients(i => i
   .AddIngredient(Ingredient.FromId(new Guid("948aeda5-ffff-41bd-af4e-71d1c740db76"))) // Eggs

Or, to specify an amount along with a prep note:

.WithIngredients(i => i
   .AddIngredientUsage(c => c
      .WithIngredient(Ingredient.FromId(new Guid("948aeda5-ffff-41bd-af4e-71d1c740db76"))) // Eggs
      .WithForm(IngredientForm.FromId(new Guid("28c374f6-2bd7-4085-a053-f68d0565050a")))   // Unit form
      .WithAmount(4, Units.Unit)

You can also divide your ingredients up into sections, which is frequently used to separate parts of a recipe (the cake part and the frosting part, for example). Let’s add some fruit toppings to our puff pancake.

.WithIngredients(i => i
   .AddRaw("4 eggs")
   .AddRaw("1 cup flour")
   .AddRaw("1 cup milk")
.WithIngredients("toppings", i => i
   .AddRaw("maple syrup")

Now, we have our main ingredients in an unnamed section, and bananas and maple syrup in a section called toppings.

I think I know what I’m eating for breakfast tomorrow.


From → Technical

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: