The following gives a list of all counties in the state of Maryland.
counties = EntityClass["AdministrativeDivision", "USCountiesMaryland"]
["Name"];
Flatten[StringDrop[StringCases[#, __ ~~ ","], -1] & /@ counties]
(* {Allegany County, Maryland,Anne Arundel County, Maryland,
Baltimore (independent city), Maryland,Baltimore County,
Maryland,Calvert County, Maryland,Caroline County, Maryland,
Carroll County, Maryland,Cecil County, Maryland,Charles County,
Maryland,Dorchester County, Maryland,Frederick County, Maryland,Garrett
County, Maryland,Harford County, Maryland,Howard County, Maryland,
Kent County, Maryland,Montgomery County, Maryland,Prince George's
County, Maryland,Queen Anne's County, Maryland,Somerset County,
Maryland,St. Mary's County, Maryland,Talbot County, Maryland,
Washington County, Maryland,Wicomico County, Maryland,Worcester
County, Maryland} *)
The first line is based on code another person wrote. I have seen use of "AdministrativeDivision" and "Name" before. How would I determine that "USCountiesMaryland" is needed? Also, how does one know when EntityClass needs more than one argument?
Answer
(See also this: http://reference.wolfram.com/language/guide/KnowledgeRepresentationAndAccess.html)
This is all in the docs, but maybe it's good to lay out here.
If you need classes, use EntityClassList
:
EntityClassList["AdministrativeDivision"] // CanonicalName //
Take[#, 5] &
{"ADM1", "ADM2", "ADM3", "AllUSStatesAndTerritories", \
"AllUSStatesPlusDC"}
If you need properties, use EntityProperties
:
EntityProperties["AdministrativeDivision"] // CanonicalName //
Take[#, 5] &
{"AccommodationAndFoodServicesSales", "AggravatedAssault", \
"AggravatedAssaultRate", "AggregateHouseholdIncome", "AnnualBirths"}
If you want straight-up entities, use EntityList
:
EntityList["Aircraft"] // CanonicalName // Take[#, 5] &
{"RB1", "CAP1", "TSR2", "3ISkyArrow", "3SigmaNearchos"}
Note that EntityList
can be applied to a class, too and EntityProperties
can be applied to individual entities.
If you want the type name, use EntityTypeName
, see also CanonicalName
and CommonName
I don't actually know how to get a list of every EntityPropertyClass
for an entity type without direct access to the EntityStore
If you want an Association
or Dataset
of your data, you can specify that to EntityValue
. This works even for custom entities provided via EntityStore
:
EntityValue[Entity["AirlineSafety", "Aer Lingus"], "Association"]
<|EntityProperty["AirlineSafety", "Label"] -> "Aer Lingus",
EntityProperty["AirlineSafety", "Airline"] -> "Aer Lingus",
EntityProperty["AirlineSafety", "AvailableSeatKilometersPerWeek"] ->
320906734, EntityProperty["AirlineSafety", "Incidents85to99"] -> 2,
EntityProperty["AirlineSafety", "FatalAccidents85to99"] -> 0,
EntityProperty["AirlineSafety", "Fatalities85to99"] -> 0,
EntityProperty["AirlineSafety", "Incidents00to14"] -> 0,
EntityProperty["AirlineSafety", "FatalAccidents00to14"] -> 0,
EntityProperty["AirlineSafety", "Fatalities00to14"] -> 0|>
Note that this also can be used on types or classes, e.g,
EntityClass["Airline", "Departures" -> GreaterThan[1000000]][
"Association"] // Map[Take[#, 3] &]
<|Entity["Airline",
"SouthwestAirlinesCo::tcv64"] -> <|EntityProperty["Airline",
"AircraftFuel"] -> Quantity[1.53*10^9, "Gallons"],
EntityProperty["Airline", "AirlineID"] -> "19393",
EntityProperty["Airline", "Airtime"] ->
Quantity[36319489/20, "Hours"]|>|>
Comments
Post a Comment