foodToVitCData = EntityClass["Food",
    EntityProperty["Food", "Preparation"] -> Entity["FoodPreparation", "Raw"],
    EntityProperty["Food", "RelativeTotalProteinContent"] -> TakeLargest[10]
][{"RelativeTotalProteinContent"}, "EntityPropertyAssociation"]

will give me the 10 with the highest relative total protein content, but how to construct a compound criterion RelativeTotalProteinContent/RelativeTotalCaloriesContent?

  • $\begingroup$ I believe EntityFunction is what you need. Can you please try EntityClass["Food", {EntityProperty["Food", "Preparation"] -> Entity["FoodPreparation", "Raw"], EntityFunction[c, c["RelativeTotalCaloriesContent"]] -> TakeLargest[10]}][{"RelativeTotalProteinContent"}, "EntityPropertyAssociation"]? However, it looks like this downloads the whole database first, which is probably not what you want, right? $\endgroup$
    – Domen
    Nov 1, 2023 at 17:26

1 Answer 1


I have no idea if the result here is correct, so there may be an error in my approach, but I think you can do something along these lines...

First, create a new entity class by extending the food class:

newClass = 
      {EntityProperty["Food", "Preparation"] -> Entity["FoodPreparation", "Raw"]}],
      "ProteinPerCalorie" -> EntityFunction[c, c["RelativeTotalProteinContent"]/c["RelativeTotalCaloriesContent"]]]

Now sort and select your desired items:

EntityList[SortedEntityClass[newClass, "ProteinPerCalorie" -> "Descending", 10]]
(* The results by "Name" property are
  {"Coconut Secret Raw Coconut Vinegar", "Columbus, Sopressata", <7>>, "Emu, outside drum, raw"}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.