3
$\begingroup$

If you read the docs for EntityProperty you see it can be used with EntityValue to perform qualified selections of data, improving efficiency of queries, etc.

Unfortunately the docs only say this:

EntityProperty[type, pname,{qual1->val1,qual2->val2,…}]
represents a property modified by the qualifier rules quali->vali.

and nothing about how to figure out what's valid for quali

So how do we do this?

$\endgroup$
4
$\begingroup$

It appears you can do queries on an EntityProperty too, with EntityValue. There's another question, here, which is what are the valid EntityProperty properties, but at least for what we care about we have this:

EntityValue[
 EntityProperty["..."],
 "Qualifiers"
 ]

Here's a fun example:

AssociationThread[
   CanonicalName@#,
   EntityValue[#, "Qualifiers"]
   ] &@RandomSample[EntityProperties@"Country", 10]

<|"ExternalBalance" -> {"CurrencyUnit", "Date", "PercentOfGDP", 
   "TradeSection"}, "ISOCertificationOwnership" -> {"Date"}, 
 "CapitalCity" -> {"Date"}, 
 "BenefitsCostIndex" -> {"Date", "Frequency", "SeasonalAdjustment", 
   "TimeSeriesOperator"}, 
 "RoadSectorGasolineFuelConsumption" -> {"Date", "PerCapita"}, 
 "FederalDebt" -> {"Adjustment", "Date", "FederalDebtHolder", 
   "Frequency", "Modifier", "SeasonalAdjustment", 
   "TimeSeriesOperator"}, 
 "EmploymentToPopulationRatio" -> {"AgeClass", "Date", "Gender"}, 
 "HospitalBedsPer10000Population" -> {"Date"}, 
 "AgriculturalProductionIndex" -> {"Date"}, 
 "TotalFertilityRate" -> {"Date", "DateRange"}|>

Then we can use it like so:

EntityValue[
  countryclass,
  EntityProperty["Country", 
   "ExternalBalance", {"Date" -> 
     Interval[{DateObject["1992"], DateObject["2005"]}]}
   ]
  ] // Short

ts

But it's not trivial to figure out how these work in general...

EntityValue[
  countryclass,
  EntityProperty["Country", 
   "ExternalBalance", {"CurrencyUnit" -> "Euros"}
   ]
  ] // DeleteDuplicates

{Missing["UnknownProperty", {"Country", 
   "ExternalBalance", {"CurrencyUnit" -> "Euros"}}]}

EntityValue[
  countryclass,
  EntityProperty["Country", 
   "ExternalBalance", {"CurrencyUnit" -> Quantity[1, "Euros"]}
   ]
  ] // DeleteDuplicates

{Missing["UnknownProperty", {"Country", 
   "ExternalBalance", {"CurrencyUnit" -> Quantity[1, "Euros"]}}]}

Sometimes you can figure out how these properties work with Ctrl+=, which is how I figured out how to do this:

EntityValue[
 countryclass,
 EntityProperty["Country", 
  "ExternalBalance", {"PercentOfGDP" -> "PercentOfGDP"}
  ]
 ]

{Quantity[0.703882, "Percent"], Quantity[7.0582, "Percent"], 
 Quantity[4.48768, "Percent"], Quantity[-6.47908, "Percent"], 
 Quantity[0.459015, "Percent"], Quantity[7.57397, "Percent"], 
 Missing["NotAvailable"], Quantity[4.11505, "Percent"], 
 Quantity[32.1342, "Percent"], Missing["NotAvailable"], 
 Missing["NotAvailable"], Quantity[-1.32907, "Percent"], 
 Quantity[2.01432, "Percent"], Quantity[36.0466, "Percent"], 
 Quantity[11.6811, "Percent"], Quantity[2.42052, "Percent"], 
 Quantity[3.99459, "Percent"], Missing["NotAvailable"], 
 Quantity[4.20712, "Percent"], Quantity[-1.40457, "Percent"]}

Another very interesting place where I do know how this works is for the "WolframLanguageSymbol" property "Ranks" and its qualifier "Corpus":

EntityValue[
  EntityClass["WolframLanguageSymbol", "Atomic"],
  EntityProperty["WolframLanguageSymbol", 
   "Ranks", {"Corpus" -> "StackExchange"}],
  "Association"
  ] // TakeSmallest[5]

<|Entity["WolframLanguageSymbol", "Integer"] -> 75, 
 Entity["WolframLanguageSymbol", "Association"] -> 104, 
 Entity["WolframLanguageSymbol", "Real"] -> 142, 
 Entity["WolframLanguageSymbol", "String"] -> 145, 
 Entity["WolframLanguageSymbol", "Image"] -> 182|>
$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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