Function Repository Resource:

BuildInterpretationLookup

Source Notebook

Build a lookup association from data to its interpretation

Contributed by: John Cassel, Wolfram|Alpha Scientific Content

ResourceFunction["BuildInterpretationLookup"][assocs,key,itype]

returns an association from the values with key key in assocs to their interpretation by itype.

ResourceFunction["BuildInterpretationLookup"][assocs,key,itype, preproc]

returns a lookup association after applying preproc to the values.

Details

This function is useful for when giving a computable interpretation to data that needs a fair amount of preprocessing or when it the data is quite redundant.

Examples

Basic Examples (1) 

Build a look-up Association for the "Location" key of the given associations:

In[1]:=
ResourceFunction[
 "BuildInterpretationLookup"][{<|"Location" -> "Omaha"|>, <|"Location" -> "Nebraska"|>, <|"Location" -> "UnitedStates"|>}, "Location", "Country" | "AdministrativeDivision" | "City"]
Out[1]=

Scope (2) 

If an interpretation cannot be found, it will be mapped to Missing:

Out[1]=

Preprocessing functions can be used to handle awkward cases:

In[2]:=
generateSwapAlternative["Nebraska, Omaha"]
Out[2]=
In[3]:=
ResourceFunction[
 "BuildInterpretationLookup"][{<|"Location" -> "Omaha, Nebraska"|>, <|"Location" -> "Nebraska"|>, <|"Location" ->
     "UnitedStates"|>, <|"Location" -> "Nebraska, Omaha"|>}, "Location", "Country" | "AdministrativeDivision" | "City",
 generateSwapAlternative]
Out[3]=

Applications (1) 

Many datasets, particularly those distributed as single comma-separated tables, have the same data in a particular field over and over:

In[4]:=
wyomingCountySeatsRaw = {<|"County Seat" -> "Laramie", "County" -> "Albany County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Basin", "County" -> "Big Horn County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Gillette", "County" -> "Campbell County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Rawlins", "County" -> "Carbon County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Douglas", "County" -> "Converse County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Sundance", "County" -> "Crook County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Lander", "County" -> "Fremont County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Torrington", "County" -> "Goshen County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Thermopolis", "County" -> "Hot Springs County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Buffalo", "County" -> "Johnson County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Cheyenne", "County" -> "Laramie County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Kemmerer", "County" -> "Lincoln County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Casper", "County" -> "Natrona County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Lusk", "County" -> "Niobrara County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Cody", "County" -> "Park County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Wheatland", "County" -> "Platte County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Sheridan", "County" -> "Sheridan County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Pinedale", "County" -> "Sublette County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Green River", "County" -> "Sweetwater County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Jackson", "County" -> "Teton County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Evanston", "County" -> "Uinta County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Worland", "County" -> "Washakie County", "State" -> "Wyoming", "Country" -> "United States"|>, <|"County Seat" -> "Newcastle", "County" -> "Weston County", "State" -> "Wyoming", "Country" -> "United States"|>};
wyomingRawDataset = Dataset[wyomingCountySeatsRaw]
Out[4]=
In[5]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/e503394c-89cd-4613-8eb6-cb8c74563c4b"]
Out[5]=
In[6]:=
wyomingRawDataset[
  All, {"County Seat" -> city, "County" -> county, "State" -> state, "Country" -> country}] /. {city -> cityLookup, county -> countyLookup, state -> stateLookup, country -> countryLookup}
Out[6]=

Version History

  • 1.0.0 – 19 April 2021

License Information