Entity and relationship function rule examples

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.

Rule examples

Function Declarations Example rule Inputs Outputs Further information
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

Refer to entities connected by a to-one relationship
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 Extend the For, For All and Exists functions
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)

Remove ambiguity when reasoning about more than one instance of the same entity
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 Check that a condition returns true for every instance of an entity
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 Extend the For, For All and Exists functions
ForAllScope (Alias)

Source entity: the person

Target entity: the person

Relationship type: One-to-many

Relationship text: the person's dependents

the person has one large party if

for all of the person's dependents (the dependent)

the person's birthday = the dependent's birthday

the person: Tobias; the person's birthday: 3 May

the person: Alexandra; the person's birthday: 3 May

the person: Victoria; the person's birthday: 5 May

the person has one large party = false Remove ambiguity when reasoning about more than one instance of the same entity
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 Check that a condition returns true for at least one instance of an entity 
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 Extend the For, For All and Exists functions
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 mother <> the other child's mother

the child: Kenneth; the child’s date of birth: 2007-10-15; the child's mother: Samantha Jane Smith

the child: Benny; the child’s date of birth: 2007-10-15; the child's mother: Samantha Jane Smith

the child: Jenny; the child’s date of birth: 2006-01-02; the child's mother: Samantha Jane Smith

the child is a twin = true (Kenneth)

the child is a twin = true (Benny)

the child is a twin = false(Jenny)

Remove ambiguity when reasoning about more than one instance of the same entity
IsMemberOf

Source entity: the person

Target entity: the child

Relationship type: Many-to-many

Relationship text: the person's household

the child is a member of the person's household if

the child's address = the person's address

the child: Sam; the child's address: 15 Melbourne Avenue Canberra

the person: James; the person's address: 21 Sydney Avenue Canberra

the child (Sam) is a member of the person's (James) household = false

Use relationship membership as a rule input

 

Infer membership of a relationship

IsNotMemberOf

Source entity: the person

Target entity: the bird

Relationship type: One-to-many

Relationship text: the person's hated birds

Reverse relationship text: the bird's owner

the bird is happy if

in the case of the bird's owner

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

the bird: Chirpy; the bird is a member of the person's hated birds: true the bird (Chirpy) is happy = false Use relationship membership as a rule input
InferInstance

Source entity: the employee

Target entity: the location

Relationship type: Many-to-one

Relationship text: the location in which the employee works

Reverse relationship text: the employees at the location

the location in which the employee works (the employee’s local office) exists

 

InferInstance(the location in which the employee works, the employee’s local office)

the employee: Gordon; the employee’s local office: "London"

the employee: Britney; the employee’s local office: "London"

the employee: Dominique; the employee’s local office: "Paris"

new inferred location: London; the location = "London", the employee (Gordon) is a member of the employees at the location (London) = true, the employee (Britney) is a member of the employees at the location (London) = true, the employee (Dominique) is a member of the employees at the location (London) = false

 

new inferred location: Paris; the location = "Paris", the employee (Gordon) is a member of the employees at the location (Paris) = false, the employee (Britney) is a member of the employees at the location (Paris) = false, the employee (Dominique) is a member of the employees at the location (Paris) = true

Infer existence of entities to satisfy the relationship
InstanceCount

Source entity: the claimant

Target entity: the child

Relationship type: One-to-many

Relationship text: the claimant's children

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

the child: Anthony

the child: Peter

the child: Rebecca

the child: Fiona

the number of children that the claimant has = 4 Count the number of instances of an entity
InstanceCountIf

Source entity: the claimant

Target entity: the child

Relationship type: One-to-many

Relationship text: the claimant's children

the number of school students that the claimant has = InstanceCountIf(the claimant's 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 that the claimant has = 1 Count the number of instances of an entity for which a particular attribute is true
InstanceMaximum

Source entity: the claimant

Target entity: the child

Relationship type: One-to-many

Relationship text: the claimant's children

the highest bank balance for a child of the claimant = InstanceMaximum(the claimant's 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 for a child of the claimant = $175 Get the highest/most recent value of an entity-level variable
InstanceMaximumIf

Source entity: the company

Target entity: the employee

Relationship type: One-to-many

Relationship text: the company's employees

the most recent date of employment of a permanent employee by the company = InstanceMaximumIf(the company's 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 Get the highest/most recent value of an entity-level variable for which a particular attribute is true
InstanceMinimum

Source entity: the claimant

Target entity: the child

Relationship type: One-to-many

Relationship text: the claimant's children

the lightest weight for a child of the claimant = InstanceMinimum(the claimant's 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 weight for a child of the claimant = 15 Get the lowest/least recent value of an entity-level variable
InstanceMinimumIf

Source entity: the claimant

Target entity: the child

Relationship type: One-to-many

Relationship text: the claimant's children

the youngest of the claimant's female children = InstanceMinimumIf(the claimant's 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 Get the lowest/least recent value of an entity-level variable for which a particular attribute is true
InstanceSum

Source entity: the claimant

Target entity: the child

Relationship type: One-to-many

Relationship text: the claimant's children

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

the child: Mary; the Child Care Benefit amount for the child: $500

the child: Sam; the Child Care Benefit amount for the child: $250

the child: Lizzie; the Child Care Benefit amount for the child: $150

the total Child Care Benefit payable to the claimant = $900 Add up numerical values gathered from each instance of an entity
InstanceSumIf

Source entity: the claimant

Target entity: the child

Relationship type: One-to-many

Relationship text: the claimant's children

the total cost of boarding school fees for the claimant = InstanceSumIf(the claimant's 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 Add up numerical values gathered from each instance of an entity for which a particular attribute is true
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 Get a value from a unique entity instance
InstanceEquals

Source entity: the product

Target entity: the product

Relationship type: Many-to-many

Relationship text: the products

the product is a duplicate if

ExistsScope(the products, the other product)

the product's code = the other product's code and

InstanceEquals(the product, the other product)

the product: Product A; the product's code: TD2010

the product: Product B; the product's code: SM2031

the product: Product A; the product's code: TD2010

the product (Product A) is a duplicate = true

the product (Product B) is a duplicate = false

Compare instances of the same entity
InstanceNotEquals

Source entity: the employee

Target entity: the employee

Relationship type: Many-to-many

Relationship text: the employees

the employee has a conflicting ID if

ExistsScope(the employees, the other employee)

the employee's ID = the other employee's ID and

InstanceNotEquals(the employee, the other employee)

the employee: Harry; the employee's ID: RN6710

the employee: Will; the employee's ID: RN5812

the employee: Kate; the employee's ID: RN5812

the employee (Harry) has a conflicting ID = false

the employee (Will) has a conflicting ID = true

the employee (Kate) has a conflicting ID = true

Compare instances of the same entity

 

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