EntityFunction

EntityFunction[x,body]

is a function with a single formal parameter x, to be used in EntityValue and related functions.

EntityFunction[{x1,x2,},body]

is an EntityFunction with a list of formal parameters.

Details

  • EntityFunction[x, body] behaves exactly like an EntityProperty and can be used directly in EntityValue.
  • In EntityFunction[x,body], x is usually bound to a single Entity at a time. The second argument of AggregatedEntityClass is an exception to this rule, since the formal parameter will bind to each group of entities.
  • In the context of the second argument of AggregatedEntityClass for relational-database-backed entities, the following aggregation functions are supported:
  • Minminimum of values
    Maxmaximum of values
    Lengthnumber of values
    Totalsum of values
    Meanthe mean value
    StandardDeviationsample standard deviation
    Variancesample variance
  • EntityFunction[{left,right},body] can appear as the condition for CombinedEntityClass. Here, left will bind to each Entity in the first argument of CombinedEntityClass and right to each Entity in the second argument.
  • When dealing with entities registered in a relational-database-backed EntityStore, only the following forms can be compiled to SQL:
  • a+badditions between numbers, dates and time quantities
    a-bdifferences between numbers or dates
    a*bmultiplications between numbers
    a/bratios between numbers
    a^bpowers between numbers
    Quotient[a,b]integer division
    Mod[a,b]remainder of division between integers
    Sqrt[a]square root
    Exp[a]exponential of numbers
    Log,Log10,Log2logarithms in different bases
    Abs[a]absolute value
    OddQ[a],EvenQ[a]parity checks on integers
    ab,a>b,ab,comparisons between numbers, dates, strings
    a&&b,a||b,!a,Boolean algebra
    If[a,b,c]if statements
    Which[]which statements
    MissingQ[a]check whether an element is missing
    Length[list]0check whether a list is empty
    OrderedQ[a,b]check the alphabetical order of strings
    MemberQ[list,a]check whether an element is in a list or an entity in a class
    StringJoin[a,b,]string concatenation
    StringMatchQ[],StringStartsQ[],basic string matching operations
    Now,Todaygetting the current date
    AllTrue,AnyTrueBoolean operations on lists
    SelectFirst[list,Not@*MissingQ]select the first non-missing value in a list
    BitNot,BitAnd,BitOr,BitShiftLeft,bitwise operations
    Sin,Cos,Tan,trigonometric functions
    ArcSin,ArcCos,ArcTan,inverse trigonometric functions
    Sinh,Cosh,Tanh,hyperbolic functions
    ArcSinh,ArcCosh,ArcTanhinverse hyperbolic functions
    Round,Floor,Ceilingrounding functions
    Min,Maxminimum and maximum (outside aggregations)
    StringTake,StringDropextract a subpart of a string (including UpTo support)
    ToString[a]convert a number or date to string
    N[a]convert an integer to real
    IntegerPart[a]extract the integer part of a real number
    FromDigits[a]convert a string to integer
    Boole[a]convert a Boolean to 0 or 1
    Interpreter["StructuredDate"][a],Interpreter["StructuredTime"][a],Interpreter["StructuredDateTime"][a]convert a string to date or time object
    UnixTime[a]convert a date object with time to a number
    FromUnixTime[a]convert a number to a date object with time
    JulianDate[a]convert a date object to a number
    FromJulianDate[a]convert a number to a date object
    DateValue[a,"SecondsFromMidnight"]convert a time object to a number
    DateValue[UnixTime[a],"TimeObject"]convert a number to a time object
  • In the context of relational-database-backed entities, the functions above might have limited functionality with respect to their Wolfram Language counterpart. For example, SQL lacks support for complex numbers; because of this, the domains of numerical functions are limited to regions where they are real valued. Symbolic evaluation is generally not available. Precision-tracking semantics may also vary.

Examples

open allclose all

Basic Examples  (3)

Compute the ratio between atomic mass and atomic number for all noble gases:

EntityFunction can be applied directly to a single entity, like EntityProperty:

Use EntityFunction as a condition for FilteredEntityClass:

Properties & Relations  (6)

Use in ExtendedEntityClass to add a new computed property:

Use in FilteredEntityClass as a predicate to select certain entities:

Use in SortedEntityClass as a sorting criterion:

Use in the second argument of AggregatedEntityClass as an aggregator:

Use in the third argument of AggregatedEntityClass as a grouping criterion:

Use in CombinedEntityClass as a combining criterion:

Possible Issues  (1)

SQL doesn't support all operations supported by the Wolfram Language:

Mathematical operations in SQL only support real numbers; performing operations that would return a complex number might result in Missing or a runtime error, depending on the backend:

SQL doesn't support returning anything but scalars from properties or EntityFunction:

Wolfram Research (2019), EntityFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/EntityFunction.html (updated 2020).

Text

Wolfram Research (2019), EntityFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/EntityFunction.html (updated 2020).

CMS

Wolfram Language. 2019. "EntityFunction." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/EntityFunction.html.

APA

Wolfram Language. (2019). EntityFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/EntityFunction.html

BibTeX

@misc{reference.wolfram_2024_entityfunction, author="Wolfram Research", title="{EntityFunction}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/EntityFunction.html}", note=[Accessed: 22-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_entityfunction, organization={Wolfram Research}, title={EntityFunction}, year={2020}, url={https://reference.wolfram.com/language/ref/EntityFunction.html}, note=[Accessed: 22-November-2024 ]}