({{, (RefLink[ExtendedEntityClass, paclet:ref/ExtendedEntityClass])[class,"name"->f]
represents an entity class derived from class by adding a new computed property "name" whose value for each entity is obtained by applying the entity function f.}, {, (RefLink[ExtendedEntityClass, paclet:ref/ExtendedEntityClass])[class,{"(Subscript[name, 1])"->(Subscript[f, 1]),"(Subscript[name, 2])"->(Subscript[f, 2]),…}]
adds the properties (Subscript[name, i]) defined by the functions (Subscript[f, i]).}})

OpenersNotesSection(Spacer1)Details

In (RefLink[ExtendedEntityClass, paclet:ref/ExtendedEntityClass])[class,"name"->f], the function f must be an (RefLink[EntityFunction, paclet:ref/EntityFunction]) object.

(RefLink[ExtendedEntityClass, paclet:ref/ExtendedEntityClass]) works with any (RefLink[EntityStore, paclet:ref/EntityStore]) object, whether defined explicitly or based on a (RefLink[RelationalDatabase, paclet:ref/RelationalDatabase]) object.

(RefLink[ExtendedEntityClass, paclet:ref/ExtendedEntityClass])[class,"new"->f] effectively represents a virtual database table derived from class, with a new column named new added, with values f[(Subscript[entity, i])] for each entity (Subscript[entity, i]).

For an extended entity class (RefLink[ExtendedEntityClass, paclet:ref/ExtendedEntityClass])[class,"new"->f], the full name of the new property added is (RefLink[EntityProperty, paclet:ref/EntityProperty])[ExtendedEntityClass[class,"new"->f],"new"].

(RefLink[ExtendedEntityClass, paclet:ref/ExtendedEntityClass])[class,"new"->f] adds a new computed property even if class already has a property whose name is "new". In this case, however, the new computed property must be referred to using the full name (RefLink[EntityProperty, paclet:ref/EntityProperty])[ExtendedEntityClass[class,"new"->f],"new"].

If the name of a new property does not conflict with the names of any existing properties, then (RefLink[EntityValue, paclet:ref/EntityValue])[class,"new"] can be used to get values of the new property.

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Use (RefLink[ExtendedEntityClass, paclet:ref/ExtendedEntityClass]) to add a computed property to a class of entities:

ExtendedEntityClass[EntityClass["Country", "G8"], "AdultFraction" -> EntityFunction[c,c["AdultPopulation"]/c["Population"]]]["AdultFraction"]

Add an alias for a property:

ExtendedEntityClass[EntityClass["Element", "Metal"], "AtomicWeight" -> EntityProperty["Element","AtomicMass"]]["AtomicWeight"]

When used with relational-database-backed entities, (RefLink[ExtendedEntityClass, paclet:ref/ExtendedEntityClass]) is equivalent to adding an expression in the SELECT statement:

EntityRegister[EntityStore[RelationalDatabase[FindFile["ExampleData/ecommerce-database.sqlite"]]]]

ExtendedEntityClass["employees" , "fullName"->EntityFunction[x, x["firstName"] <> " " <> x["lastName"]]]["fullName"]

OpenersExampleSection1(Spacer1)Scope  (1)

Add multiple properties at the same time:

ExtendedEntityClass[(EntityClass["European Union official languages", EntityClass["Language","EuropeanUnionLanguages"], "EntityClass[\"Language\", \"EuropeanUnionLanguages\"]", "languages"]),{"WikipediArticlesPerCapita" -> EntityFunction[l, l[(EntityProperty["Wikipedia size", EntityProperty["Language","WikipediaArticleCount"], "EntityProperty[\"Language\", \"WikipediaArticleCount\"]"])]/l[(EntityProperty["total number of speakers", EntityProperty["Language","TotalSpeakers"], "EntityProperty[\"Language\", \"TotalSpeakers\"]"])]], "YesNo" -> EntityFunction[l, Lookup[l[(EntityProperty["basic communication", EntityProperty["Language","BasicCommunicationWords"], "EntityProperty[\"Language\", \"BasicCommunicationWords\"]"])],{(Entity["yes", Entity["Word","yes"], "Entity[\"Word\", \"yes\"]", "word"]),(Entity["no", Entity["Word","no"], "Entity[\"Word\", \"no\"]", "word"])}]]}][{"WikipediArticlesPerCapita","YesNo"}]

OpenersExampleSection2(Spacer1)Applications  (1)

(RefLink[ExtendedEntityClass, paclet:ref/ExtendedEntityClass]) can be used to avoid repeating code:

SortedEntityClass[
"Planet",
EntityFunction[e,e[(EntityProperty["average diameter", EntityProperty["Planet","Diameter"], "EntityProperty[\"Planet\", \"Diameter\"]"])]/e[(EntityProperty["distance from Sun", EntityProperty["Planet","DistanceFromSun"], "EntityProperty[\"Planet\", \"DistanceFromSun\"]"])]]
][
EntityFunction[e,e[(EntityProperty["average diameter", EntityProperty["Planet","Diameter"], "EntityProperty[\"Planet\", \"Diameter\"]"])]/e[(EntityProperty["distance from Sun", EntityProperty["Planet","DistanceFromSun"], "EntityProperty[\"Planet\", \"DistanceFromSun\"]"])]]
]

It can be rewritten as:

SortedEntityClass[
ExtendedEntityClass[
"Planet",
"ratio"->EntityFunction[e,e[(EntityProperty["average diameter", EntityProperty["Planet","Diameter"], "EntityProperty[\"Planet\", \"Diameter\"]"])]/e[(EntityProperty["distance from Sun", EntityProperty["Planet","DistanceFromSun"], "EntityProperty[\"Planet\", \"DistanceFromSun\"]"])]]
],
"ratio"
]["ratio"]

OpenersExampleSection3(Spacer1)Possible Issues  (1)

When dealing with SQL-backed entities, it is not possible to extend an entity class with nonscalar values:

EntityRegister[EntityStore[RelationalDatabase[FindFile["ExampleData/ecommerce-database.sqlite"]]]]

ExtendedEntityClass["customers", "PaymentsAmount" -> EntityFunction[c, c["payments"]["amount"]]]["PaymentsAmount"]

OpenersExampleSection4(Spacer1)Neat Examples  (1)

Colorful flags:

EntityValue[ExtendedEntityClass[(EntityClass["European Union official languages", EntityClass["Language","EuropeanUnionLanguages"], "EntityClass[\"Language\", \"EuropeanUnionLanguages\"]", "languages"]),"FlagColors" -> EntityFunction[l, Nearest[MapAt[Interpreter["StructuredColor"]@*CommonName,l[ (EntityProperty["colors", EntityProperty["Language","ColorNames"], "EntityProperty[\"Language\", \"ColorNames\"]"])],{All,1}],DominantColors[l[(EntityProperty["place with most speakers", EntityProperty["Language","LargestCountry"], "EntityProperty[\"Language\", \"LargestCountry\"]"])][EntityProperty["Country", "Flag"]]]][[All, 1]]]],"FlagColors", "EntityAssociation"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[EntityValue, paclet:ref/EntityValue])  ▪  (RefLink[EntityList, paclet:ref/EntityList])  ▪  (RefLink[EntityClass, paclet:ref/EntityClass])  ▪  (RefLink[EntityStore, paclet:ref/EntityStore])  ▪  (RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Working with Information in Relational Databases, paclet:guide/WorkingWithRelationalDatabases])}, {▪(RefLinkPlain[Knowledge Representation & Access, paclet:guide/KnowledgeRepresentationAndAccess])}, {▪(RefLinkPlain[Entity Types, paclet:guide/EntityTypes])}})}})