I am not experienced with Wolfram Knowledgebase queries and working with entities.

What is the "correct" way to convert a colour entity into a colour directive?


ent = StarData["Sun", "Color"]
(* Entity["Color", {"RGB", {1., 0.96, 0.93}}] *)

I want to convert ent to RGBColor[1., 0.96, 0.93].

Is there an API for this, or is the only way extracting the part of the Entity expression?

Somehow extracting directly "doesn't feel right", but I may be mistaken about how this is intended to be used. It also isn't very convenient to extract directly because when working with such queries, sometimes Missing[...] is returned. Missing values are gracefully handled by functions such as EntityValue, but I'd have to handle them myself if I extract directly. An example is list = StarData[EntityClass["Star", {EntityProperty["Star", "DistanceFromEarth"] -> TakeSmallest[50]}], "Color"], which has some missing value. Now EntityValue[list, "HSLValue"] simply skips missing values without failing, while I would have to do extra work to handle them myself.

Overall, this question is about how these functions are intended to be used, and what is the most convenient way to use them when chaining multiple queries. Extracting with Part is obviously trivial.

  • $\begingroup$ FromEntity[] should do the trick. $\endgroup$ – J. M.'s discontentment Jul 5 '16 at 12:50
  • $\begingroup$ @J.M. Excellent! Answer? Or should I delete? $\endgroup$ – Szabolcs Jul 5 '16 at 12:54
  • $\begingroup$ I'm using a phone right now, so I'm not sure if it'd have worked. Please feel free to write something if it did work. :) $\endgroup$ – J. M.'s discontentment Jul 5 '16 at 12:57
  • 2
    $\begingroup$ @J.M. Yes, this is easily found in the documentation. Yet I did spend time on it and I didn't find it. I guess I should keep this in mind when closing beginners' questions as a "simple mistake". $\endgroup$ – Szabolcs Jul 5 '16 at 12:57

FromEntity and ToEntity can do the conversion.

FromEntity[StarData["Sirius", "Color"]]
(* RGBColor[0.73, 0.8, 1.] *)
  • 1
    $\begingroup$ Or you could hit it with a hammer: RGBColor @@ ent[[-1, -1]] $\endgroup$ – Bob Hanlon Jul 5 '16 at 15:42

ent is an Entity of "Color" you can investigate its properties.


Of the many properties the "Value" property (strangely it has CommonName "Wolfram Language") will return the RGB color you are seeking.

(* RGBColor[1., 0.96, 0.93] *)

Hope this helps.

| improve this answer | |
  • $\begingroup$ I thought I had tried EntityValue[ent, EntityProperties[ent]]. I must have only tried specific properties then. $\endgroup$ – Szabolcs Jul 23 '16 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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