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 (4) 

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 (6) 

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

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

EntityClassDimensions 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]=

EntityClassDimensions 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]=

EntityClassDimensions can find the dimensions of AggregatedEntityClass:

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

EntityClassDimensions 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 entity classes with their CombinedEntityClass:

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

Applications (1) 

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[11]=

Properties and Relations (2) 

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

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

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

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

Possible Issues (1) 

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

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

Neat Examples (1) 

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

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

Publisher

Seth J. Chandler

Version History

  • 1.0.0 – 12 July 2019

License Information