How to extract the displayed name of an entity
With the same
historicalEvents = EntityList[Entity["HistoricalEvent"]];
as in the answer by Martin John Hadley.
One can generate the same historicalEntityNames
using
historicalEntityNames = <|"EntityName" -> #1, "DisplayedName" -> #2|> & @@@
Transpose[{CanonicalName@historicalEvents, CommonName@historicalEvents}]
or
historicalEntityNames =
AssociationThread[{"EntityName", "DisplayedName"}, #] & /@
Transpose[Through[{CanonicalName, CommonName}[historicalEvents]]]
Or more directly:
historicalEntityNames =
Query[All, <|"EntityName" -> CanonicalName@#, "DisplayedName" -> CommonName@#|> &]@
EntityList[Entity["HistoricalEvent"]]
or
historicalEntityNames = Query[All, {CanonicalName, CommonName} /*
<|"EntityName" -> First, "DisplayedName" -> Last|>]@
EntityList[Entity["HistoricalEvent"]]
For a single Entity
using for example
EntityValue[Entity["HistoricalEvent", "AlanTuring"], {"CanonicalName", "Name"},
"PropertyAssociation"]
might be useful.
All of the HistoricalEvents
in the Wolfram Knowledgebase are accessible as follows:
historicalEvents = EntityList[Entity["HistoricalEvent"]];
Using ToBoxes
the display form of the Entity
can be seen:
ToBoxes[historicalEvents[[1]]]
(*TemplateBox[{"\"Alan Turing writes his influential paper, \\\"On \
Computable Numbers\\\"\"",
RowBox[{"Entity", "[",
RowBox[{"\"HistoricalEvent\"", ",", "\"AlanTuring\""}], "]"}],
"\"Entity[\\\"HistoricalEvent\\\", \\\"AlanTuring\\\"]\"",
"\"historical event\""}, "Entity"]*)
Using the following ReplaceAll
pattern the entity names and descriptions can be returned easily:
historicalEntityNames =
ToBoxes /@ historicalEvents /.
TemplateBox[{name_,
RowBox[{_, _, RowBox[{_, ",", entity_}], _}], _, _},
"Entity"] :> <|"EntityName" -> TextWords[entity][[1]],
"DisplayedName" -> StringRiffle@TextWords@name|>;
It is usually possible to query properties of entities. That makes it easier to discover how to extract information.
Code:
ent = Entity["HistoricalEvent", "AlanTuring"]
ent["Properties"]
InputForm[%]
ent["Name"]
(I'm not really sure why ent
doesn't display properly on my machine...)