Message Boards Message Boards

Random Cities with a Non-Missing Property

Posted 4 years ago

I would like to fetch four random city entities from the curated database that have a value in a specified property (not Missing[]). The end result would look something like this if I used the property "Area":

{{"Los Angeles", Quantity[468.6701619038, ("Miles")^2]},{"Miami", Quantity[35.871043820, ("Miles")^2]},{"Twin Falls", Quantity[18.103053374, ("Miles")^2]},{"Canton", Quantity[25.462368239, ("Miles")^2]}}

So far everything I've tried has been too slow to be useful, on the order of 20 minutes per query. I admit though that I don't understand EntityClass, EntityFunction, etc. very well. The problem seems to be in the large size of the database that contains the "city" entities and the relatively few entities that have values for most of the properties. Usable times for my purpose would be less than 15 seconds or so.

Any help would be appreciated.

Mark

POSTED BY: Mark Greenberg
2 Replies
Posted 4 years ago

How about this?

RandomEntity[
   EntityClass["City",  "Area" -> Quantity[Interval[{0, Infinity}], "Miles"*"Miles"]], 4] //
  EntityValue[#, {"Area"}, "EntityAssociation"] & //AbsoluteTiming

(*
{1.70067,
 <|Entity["City", {"Westminster", "Colorado", "UnitedStates"}] -> {Quantity[31.550416264, ("Miles")^2]}, 
  Entity["City", {"Belvue", "Kansas", "UnitedStates"}] -> {Quantity[0.115757288, ("Miles")^2]}, 
  Entity["City", {"Lewisville", "Indiana", "UnitedStates"}] -> {Quantity[0.253491511, ("Miles")^2]}, 
  Entity["City", {"Lehighton", "Pennsylvania", "UnitedStates"}] -> {Quantity[1.623076949,("Miles")^2]}|>}
*)
POSTED BY: Rohit Namjoshi
Posted 4 years ago

Awesome, thank you. I was getting the syntax wrong. The Interval[{0,Infinity}] is the part I left out. I had tried >=0. Your solution not only solves my short-term problem, but also opens up a direction in my Wolfram programming that I had been avoiding because I couldn't make it work.

Thanks again, Rohit.

Mark

POSTED BY: Mark Greenberg
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract