Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Build a lookup association from data to its interpretation
| 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. | 
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"]](https://www.wolframcloud.com/obj/resourcesystem/images/cc1/cc1a472b-e160-4f3e-a2aa-360c205be9b9/317540aeec70266b.png) | 
| Out[1]= |  | 
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"]](https://www.wolframcloud.com/obj/resourcesystem/images/cc1/cc1a472b-e160-4f3e-a2aa-360c205be9b9/77dfd4e551bbec3e.png) | 
| Out[2]= |  | 
| In[3]:= | ![ResourceFunction[
 "BuildInterpretationLookup"][{<|"Location" -> "Omaha, Nebraska"|>, <|"Location" -> "Nebraska"|>, <|"Location" ->
     "UnitedStates"|>, <|"Location" -> "Nebraska, Omaha"|>}, "Location", "Country" | "AdministrativeDivision" | "City",
 generateSwapAlternative]](https://www.wolframcloud.com/obj/resourcesystem/images/cc1/cc1a472b-e160-4f3e-a2aa-360c205be9b9/4f579c8ea07f5514.png) | 
| Out[3]= |  | 
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]](https://www.wolframcloud.com/obj/resourcesystem/images/cc1/cc1a472b-e160-4f3e-a2aa-360c205be9b9/3251b7e0b7f0281a.png) | 
| Out[4]= |  | 
| In[5]:= | ![(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/e503394c-89cd-4613-8eb6-cb8c74563c4b"]](https://www.wolframcloud.com/obj/resourcesystem/images/cc1/cc1a472b-e160-4f3e-a2aa-360c205be9b9/0c423e64432dbc80.png) | 
| Out[5]= |  | 
| In[6]:= | ![wyomingRawDataset[
  All, {"County Seat" -> city, "County" -> county, "State" -> state, "Country" -> country}] /. {city -> cityLookup, county -> countyLookup, state -> stateLookup, country -> countryLookup}](https://www.wolframcloud.com/obj/resourcesystem/images/cc1/cc1a472b-e160-4f3e-a2aa-360c205be9b9/14f293754a9b2843.png) | 
| Out[6]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License