Wolfram Research

Function Repository Resource:

EntityClassDimensions

Source Notebook

Produce a list with the number of entities in an entity class and the number of properties possessed by each entity therein

Contributed by: Seth J. Chandler

ResourceFunction["EntityClassDimensions"][class]

takes an EntityClass or list of EntityClass expressions and returns the number of entities each contains and the number of properties in the class.

ResourceFunction["EntityClassDimensions"][class,form]

returns results in the specified form.

Details and Options

Supported values of form are:
“List” list of entity and property counts
“EntityAssociation” Association with classes as keys
“PropertyAssociation” Association containing "EntityCount" and "PropertyCount" values
“EntityPropertyAssociation” nested Association with classes as keys and "PropertyAssociation" values
The default form is "List".

Examples

Basic Examples

Determine the number of DogBreed entities (dog breeds) and properties:

In[1]:=
ResourceFunction["EntityClassDimensions"][
 EntityClass["DogBreed", All]]
Out[1]=

Use the canonical name of the EntityClass and get its dimensions:

In[2]:=
ResourceFunction["EntityClassDimensions"]["YogaPose"]
Out[2]=

Obtain the dimensions of a list of classes:

In[3]:=
ResourceFunction[
 "EntityClassDimensions"][{EntityClass["DogBreed", All], "YogaPose"}]
Out[3]=

Return the information as an Association:

In[4]:=
ResourceFunction["EntityClassDimensions"][
 EntityClass["DogBreed", "Spaniel"], "PropertyAssociation"]
Out[4]=

Scope

It can return the results as an Association in which the EntityClass is the key:

In[5]:=
ResourceFunction["EntityClassDimensions"][
 EntityClass["Book", All], "EntityAssociation"]
Out[5]=

It can return the results as a nested Association in which the outer keys are the entity classes, represented in the form specified by the user, and the inner keys are the properties:

In[6]:=
ResourceFunction[
 "EntityClassDimensions"][{EntityClass["DogBreed", All], "YogaPose"}, "EntityPropertyAssociation"]
Out[6]=

It can find the dimensions of derived entity classes, such as a FilteredEntityClass:

In[7]:=
ResourceFunction["EntityClassDimensions"][
 FilteredEntityClass["YogaPose", EntityFunction[e, e["IntensityLevel"] === "Low"]]]
Out[7]=

It can find the dimensions of an AggregatedEntityClass:

In[8]:=
ResourceFunction["EntityClassDimensions"][
 AggregatedEntityClass["DogBreed", "MeanWeightMale" -> EntityFunction[e, Mean[DeleteMissing["WeightMaleMean"]]], "Size"]]
Out[8]=

It can find the dimensions of an ExtendedEntityClass:

In[9]:=
ResourceFunction["EntityClassDimensions"][
 ExtendedEntityClass["DogBreed", "Big" -> EntityFunction[e, UnitConvert[e["WeightMaleMean"], "Pounds"] > Quantity[100, "Pounds"]]]]
Out[9]=

Compare the dimensions of two instances of EntityClass, with their CombinedEntityClass:

In[10]:=
ResourceFunction[
 "EntityClassDimensions"][{"Isotope", EntityClass["Element", "Period1"], CombinedEntityClass["Isotope", EntityClass["Element", "Period1"], "Element" -> "Entity"]}, "EntityPropertyAssociation"]
Out[10]=

Applications

Determine the dimensions of a user-created EntityClass:

In[11]:=
EntityRegister[
  EntityStore[
   "t" -> <|
     "Entities" -> <|
       "e1" -> <|"p2" -> 59|>,
       "e2" -> <|"p1" -> 27, "p2" -> 288|>,
       "e3" -> <|"p1" -> Missing[], "p2" -> 288|>
       |>
     |>]];
ResourceFunction["EntityClassDimensions"]["t"]
Out[12]=

Properties and Relations

Use EntityTypeName to find the dimensions of the class to which an Entity belongs:

In[13]:=
ResourceFunction["EntityClassDimensions"][
 EntityTypeName[Entity["DogBreed", "AlaskanMalamute"]]]
Out[13]=

Use KeyMap to change the form of any EntityClass keys in the output:

In[14]:=
KeyMap[CanonicalName][
 ResourceFunction["EntityClassDimensions"][EntityClass["Book", All], "EntityAssociation"]]
Out[14]=

Possible Issues

If you specify a class that is unknown to the system, the function returns Missing objects:

In[15]:=
ResourceFunction["EntityClassDimensions"]["unknownClass"]
Out[15]=

Neat Examples

You can probe the size of relational databases held on external servers:

In[16]:=
ResourceFunction["EntityClassDimensions"][
 EntityRegister[
  EntityStore[
   RelationalDatabase[{"xref", "gene"}, "mysql://anonymous@ensembldb.ensembl.org/homo_sapiens_core_95_38"]\
]], "EntityPropertyAssociation"]
Out[16]=

Resource History

License Information