Message Boards Message Boards

[WSSA16] Semantic representation of recipes on the web

Posted 8 years ago

Abstract

Everyone needs to take care of their health and the most important thing is to be careful what you eat.You can find many interesting recipes and cook anything you want, but for health it is important to know what kind of influence it can have on you. In other words you need some nutrition information about meals.The goal of this project is to create a program which will give users such kind of information.You can import ingredients of meals and the program will give you some information such as total calories content, total sugar content etc ... example enter image description here

The code of my project is

CloudDeploy[FormFunction[
  {"items", None} -> RepeatingElement[
    CompoundElement[<|
      "food" -> <|"Label" -> "Foods", "Interpreter" -> "Food"|>, 
      "quantity" -> <|"Label" -> "Quantity", 
        "Interpreter" -> "Quantity"|>
      |>]
          ],
  With[{vals = 
      Values@EntityGroup[
         EntityInstance @@@ #items][{"AbsoluteTotalCaloriesContent", 
         "AbsoluteTotalCarbohydratesContent", 
         "AbsoluteTotalSugarContent", "AbsoluteTotalFatContent", 
         "AbsoluteCholesterolContent", "AbsoluteTotalProteinContent"},
         "PropertyAssociation"]},
    If[FreeQ[vals, _Missing],
     Grid[
      Prepend[Transpose[{{"Calories", "Carbs", "Sugar", "Fat", 
          "Cholesterol", "Protein"}, vals}], {"Name", "Content"}],
      Background -> {None, {Lighter[Yellow, .9], {White, 
          Lighter[Blend[{Red, Red}], .6]}}}, 
      Dividers -> {{Darker[Gray, .6], {Lighter[Gray, .5]}, 
         Darker[Gray, .6]}, {Darker[Gray, .6], 
         Darker[Gray, .6], {False}, Darker[Gray, .6]}}, 
      ItemSize -> {{20, 20}}, Frame -> Darker[Gray, .6], 
      ItemStyle -> 15, Spacings -> {Automatic, .8}], 
     "Sorry, Missing data"]] &, "PNG"
                    ], Permissions -> "Public"]

Steps of work

  • Get data from Wolfram
  • Set relations between items and their quantities
  • Count the total quantity of contents
  • Set condition for those items whose data are missing
  • Design page
  • Put it on web

In Wolfram Alpha there are a lot of information about foods, including nutrition information.So I've used those ones to make my project. As the output of the program depends on items and their quantities, I've used EntityInstance function to set relations between items and their quantities enter image description here

Then to combine all entities I've used EntityGroup function.

To count total quantity of contents I've used properties such as "AbsoluteTotalCaloriesContent", "AbsoluteTotalCarbohydratesContent", "AbsoluteTotalSugarContent", "AbsoluteTotalFatContent", "AbsoluteCholesterolContent", "AbsoluteTotalProteinContent"

Property "PropertyAssociation" helped me to create association between properties and appropriate quantities.

enter image description here

There are some foods about which there are no information in wolfram data, so for correct working of program I've used functions With and If. So as a result, if you input item about which there is no information the program will give this

missing

For designing outputs I've used Grid function

Grid[Prepend[
  Transpose[{{"Calories", "Carbs", "Sugar", "Fat", "Cholesterol", 
     "Protein"}, vals}], {"Name", "Content"}],
 Background -> {None, {Lighter[Yellow, .9], {White, 
     Lighter[Blend[{Red, Red}], .6]}}}, 
 Dividers -> {{Darker[Gray, .6], {Lighter[Gray, .5]}, 
    Darker[Gray, .6]}, {Darker[Gray, .6], Darker[Gray, .6], {False}, 
    Darker[Gray, .6]}}, ItemSize -> {{20, 20}}, 
 Frame -> Darker[Gray, .6], ItemStyle -> 15, 
 Spacings -> {Automatic, .8}]

Then for creating web page I've used CloudDeploy

enter image description here

In Quantity field you should import not only quantity but also a unit, otherwise it will show

enter image description here

You can try to use this program here

Attachments:
POSTED BY: Astghik Saharyan
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract