# How to turn a colour entity into a colour directive?

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?

Example:

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.

• FromEntity[] should do the trick. – J. M.'s discontentment Jul 5 '16 at 12:50
• @J.M. Excellent! Answer? Or should I delete? – Szabolcs Jul 5 '16 at 12:54
• 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. :) – J. M.'s discontentment Jul 5 '16 at 12:57
• @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". – Szabolcs Jul 5 '16 at 12:57

FromEntity and ToEntity can do the conversion.

FromEntity[StarData["Sirius", "Color"]]
(* RGBColor[0.73, 0.8, 1.] *)

• Or you could hit it with a hammer: RGBColor @@ ent[[-1, -1]] – Bob Hanlon Jul 5 '16 at 15:42

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

EntityProperties["Color"]


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

ent["Value"]
(* RGBColor[1., 0.96, 0.93] *)


Hope this helps.

• I thought I had tried EntityValue[ent, EntityProperties[ent]]. I must have only tried specific properties then. – Szabolcs Jul 23 '16 at 18:49