Function Repository Resource:

AddSemantics

Source Notebook

Automatically add semantics to structured data

Contributed by: Bob Sandheinrich

ResourceFunction["AddSemantics"][data]

automatically and semantically interprets the structured dataset data.

ResourceFunction["AddSemantics"][data,spec]

interprets data using the given spec.

Details and Options

The data must either be a Dataset or data supported by Dataset.
The specification spec takes the same values as SemanticImport and SemanticImportString.

Examples

Basic Examples (2) 

Add semantics to an Association:

In[1]:=
ResourceFunction[
 "AddSemantics"][<|"location" -> "St. Louis", "person" -> "Scott Joplin", "date" -> "November 24, 1868"|>]
Out[1]=

Add semantics to a Dataset:

In[2]:=
ResourceFunction["AddSemantics"][Dataset@{
   <|"Time" -> "1:05 PM", "Amount" -> "10 kg"|>,
   <|"Time" -> "1:22 PM", "Amount" -> "14 kg"|>,
   <|"Time" -> "1:25 PM", "Amount" -> "16 kg"|>
   }]
Out[2]=

Scope (4) 

Use a flat Dataset:

In[3]:=
ResourceFunction["AddSemantics"][
 Dataset[<|"A" -> "Amsterdam", "B" -> "Budapest", "C" -> "Copenhagen",
    "D" -> "Dublin"|>]]
Out[3]=

Get a tabular Dataset:

In[4]:=
data = Dataset[
  AssociationThread[{"Destination", "Cost"} -> #] & /@ Rest@StringSplit[
     StringSplit[Import["ExampleData/countries-currency", "Text"], "\n"], "\t"]]
Out[4]=

Add semantics to the data:

In[5]:=
ResourceFunction["AddSemantics"][data]
Out[5]=

A nested Dataset:

In[6]:=
ResourceFunction["AddSemantics"]@
 Dataset[<| "Flour" -> <|"Amount" -> "400 ml", "Calories" -> 800, "Sugar" -> "0 grams"|>,
   "Chocolate Chips" -> <|"Amount" -> "50 ml", "Calories" -> 100, "Sugar" -> "20 grams"|>,
   "Butter" -> <|"Amount" -> "100 ml", "Calories" -> 400, "Sugar" -> "0 grams"|>
   |>]
Out[6]=

Specify semantic type for tabular data:

In[7]:=
ResourceFunction["AddSemantics"][Dataset[{
   <|"Amount" -> "400 ml", "Calories" -> 800, "Sugar" -> "0 grams"|>,
   <|"Amount" -> "50 ml", "Calories" -> 100, "Sugar" -> "20 grams"|>,
   <|"Amount" -> "100 ml", "Calories" -> 400, "Sugar" -> "0 grams"|>
   }], {Automatic, Restricted["StructuredQuantity", "Calories"], Automatic}]
Out[7]=

Version History

  • 2.0.0 – 04 June 2020
  • 1.0.0 – 28 August 2019

Related Resources

License Information