Entity and relationship function rule examples

Entity functions are used to perform operations on entity-specific data to produce global results, such as counting the number of instances of an entity, obtaining the highest/most recent or lowest/least recent value of an entity-level variable, and adding up numerical values gathered from each instance of the entity.

Be sure to use the exact syntax for these functions including spacing and parentheses as specified below.

TIP: The localized syntax for these functions may be viewed:

Rule examples

Function Declarations Example rule Inputs Outputs
For

Source entity: the child

Target entity: the school

Relationship type: Many-to-one

Relationship text: the child's school

 

the child may apply for a scholarship if

For(the child's school, the school has a scholarship program)

 

the child does not have to go to school if

in the case of the child's school, the school is closed for a pupil free day

 

the child's school name = the school name, in the case of the child's school

the child's school: St Mary's; the school has a scholarship program: false

 

the child's school: St Joseph's; the school is closed for a pupil free day: true

 

the child's school: St Clare's Public School; the school name: St Clare's Public School

the child may apply for a scholarship = false

 

the child does not have to go to school = true

 

the child's school name = St Clare's Public School

ForScope

Source entity: the person

Target entity: the car

Relationship type: One-to-one

Relationship text: the person's car

the person has a reliable car if

in the case of the person's car

the number of times the car has broken down = 0

the car: NSW001; the number of times the car has broken down: 4 the person has a reliable car = false
ForScope (Alias)

Source entity: the person

Target entity: the person

Relationship type: One-to-one

Relationship text: the person's spouse

the person has the highest taxable income if

ForScope(the person’s spouse, the spouse)

the person’s income > the spouse’s income

the person: Fran; the person’s income: 500

the person: Seb; the person’s income: 250

the person has the highest taxable income=true (Fran)

the person has the highest taxable income=false (Seb)

ForAll

Source entity: global

Target entity: the child

Relationship type: One-to-many

Relationship text: the children

the playground is empty if

ForAll(the children, the child is at home)

 

the playground is empty if

ForAll(the children, the child's location = "home")

 

the playground is empty if

each of the children is at home

the child: Sally; the child is at home: true; the child's location: home

the child: Molly; the child is at home: true; the child's location: home

the child: Elizabeth; the child is at home: false; the child's location: playground

the playground is empty = false
ForAllScope

Source entity: the person

Target entity: the cat

Relationship type: One-to-many

Relationship text: the person's cats

the person is happy if

for all of the person's cats

the cat is happy

the cat: Tiger; the cat is happy: false

the cat: Kit; the cat is happy: true

the cat: Patch; the cat is happy: true

the person is happy = false
ForAllScope (Alias)

Source entity: Global

Target entity: the person

Relationship type: One-to-many

Relationship text: the person's children

the person is lucky if

for all of the person's children (the child)

the person's date of birth = the child's date of birth

the person: Tobias; the person's date of birth: 2001-03-03

the person: Alexandra; the person's date of birth: 2002-06-06

the person: Victoria; the person's date of birth: 2001-03-03

the person is lucky = false
Exists

Source entity: global

Target entity: the child

Relationship type: One-to-many

Relationship text: the children

the playground has good equipment if

Exists(the children, the child is happy)

 

the playground has good equipment if

at least one of the children is happy

the child: Isabelle ; the child is happy: false

the child: Xavier; the child is happy: true

the child: Phoebe; the child is happy: false

the child: Rachel; the child is happy: false

the playground has good equipment = true
ExistsScope

Source entity: the plan

Target entity: the product

Relationship type: Many-to-many

Relationship text: the plan's products

the plan has incompatible products if

ExistsScope(the plan's products)

the plan's network <> the product's network

the plan: Plan 1; the plan's network: Vodafone

the plan: Plan 2; the plan's network: Telstra

the product: Product 1; the product's network: Optus

the product: Product 2; the product's network: Vodafone

the plan has incompatible products = true
ExistsScope (Alias)

Source entity: Global

Target entity: the child

Relationship type: One-to-many

Relationship text: the children

the child is a twin if

ExistsScope(the children, the other child)

the child’s date of birth = the other child’s date of birth and

the child's name <> the other child's name

the child: Kenneth; the child’s date of birth: 2007-10-15

the child: Benny; the child’s date of birth: 2007-10-15

the child: Jenny; the child’s date of birth: 2006-01-02

the child is a twin = true (Kenneth)

the child is a twin = true (Benny)

the child is a twin = false(Jenny)

IsMemberOf

Source entity: the person

Target entity: the dog

Relationship type: Inferred (many-to-many)

Relationship text: the person's favorite dogs

the dog is a member of the person's favorite dogs if

the dog's age = the person's age

the dog: Sam; the dog's age: 15

the person: James; the person's age: 21

the dog (Sam) is a member of the person's (James) favorite dogs = false
IsNotMemberOf

Source entity: the person

Target entity: the cat

Relationship type: One-to-many

Relationship text: the person's hated cats

Reverse relationship text: the cat's owner

the cat is happy if

in the case of the cat's owner

IsNotMemberOf(the cat, the person's hated cats)

the cat: Moggy; the cat is a member of the person's hated cats: true the cat (Moggy) is happy = false
InstanceCount

Source entity: the claimant

Target entity: the child

Relationship type: One-to-many

Relationship text: the children

the number of the claimant's children = InstanceCount(the children)

the child: Anthony

the child: Peter

the child: Rebecca

the child: Fiona

the number of the claimant's children = 4
InstanceCountIf

Source entity: the claimant

Target entity: the child

Relationship type: One-to-many

Relationship text: the children

the number of school students for the claimant = InstanceCountIf(the children, the child is a school student)

the child: Anthony; the child is a school student: false

the child: Peter; the child is a school student: false

the child: Rebecca; the child is a school student: true

the number of school students for the claimant = 1
InstanceMaximum

Source entity: the claimant

Target entity: the child

Relationship type: One-to-many

Relationship text: the children

the highest bank balance of the claimant's children = InstanceMaximum(the children, the child's bank balance)

the child: Max; the child's bank balance: $50

the child: Sophie; the child's bank balance: $175

the child: Katie; the child's bank balance: $120

the highest bank balance of the claimant's children = $175
InstanceMaximumIf

Source entity: the company

Target entity: the employee

Relationship type: One-to-many

Relationship text: the employees

the most recent date of employment of a permanent employee by the company = InstanceMaximumIf(the employees, the employee's date of employment, the employee is a permanent employee)

the employee: David; the employee's date of employment: 01/01/2006; the employee is a permanent employee: true

the employee: Shaun; the employee's date of employment: 24/08/2006; the employee is a permanent employee: false

the employee: Anita; the employee's date of employment: 15/05/2006; the employee is a permanent employee: true

the most recent date of employment of a permanent employee by the company = 2006-05-15
InstanceMinimum

Source entity: the claimant

Target entity: the child

Relationship type: One-to-many

Relationship text: the children

the lightest of the claimant's children = InstanceMinimum(the children, the child's weight in kilograms)

the child: Harry; the child's weight in kilograms: 15

the child: Sharon; the child's weight in kilograms: 30

the child: Fran; the child's weight in kilograms: 45

the lightest of the claimant's children = 15
InstanceMinimumIf

Source entity: the claimant

Target entity: the child

Relationship type: One-to-many

Relationship text: the children

the youngest of the claimant's female children = InstanceMinimumIf(the children, the child's age, the child is female)

the child: Sam; the child's age: 3; the child is female: false

the child: Alex; the child's age: 4; the child is female: true

the child: Sharon; the child's age: 6; the child is female: false

the child: Paris; the child's age: 8; the child is female: true

the youngest of the claimant's female children = 4
InstanceSum

Source entity: the claimant

Target entity: the child

Relationship type: One-to-many

Relationship text: the children

the total Child Care Benefit payable to the claimant = InstanceSum(the children, the CCB amount for the child)

the child: Mary; the CCB amount for the child: $500

the child: Sam; the CCB amount for the child: $250

the child: Lizzie; the CCB amount for the child: $150

the total Child Care Benefit payable to the claimant = $900
InstanceSumIf

Source entity: the claimant

Target entity: the child

Relationship type: One-to-many

Relationship text: the children

the total cost of boarding school fees for the claimant = InstanceSumIf(the children, the annual school fees for the child, the child attends a boarding school)

the child: Sally; the annual school fees for the child: $18000; the child attends a boarding school: true

the child: James; the annual school fees for the child: $15000; the child attends a boarding school: true

the child: Bob; the annual school fees for the child: $10000; the child attends a boarding school: false

the total cost of boarding school fees for the claimant = $33000
InstanceValueIf  

Source entity:Global

Target entity: the child

Relationship type: One-to-many

Relationship text: the children

the name of the oldest child = InstanceValueIf(the children, the child's name, the child's age = the age of the oldest child)

the age of the oldest child = 8

the child: Sam; the child's age: 3

the child: Alex; the child's age: 4

the child: Sharon; the child's age: 6

the child: Paris; the child's age: 8

the name of the oldest child = Paris

 

See also: