Rainbird
  • 🏃‍♂️Getting started
    • What is Rainbird?
    • How does Rainbird work?
    • Example use cases
      • 📈Investment suitability assessment
      • 🤖Digital tax consultant
      • 🏥Covid risk assessment
      • 🚗Insurance claims liability
      • 💰Fraud identification
    • Hosting options
    • Quickstart guide
    • Onboarding with Rainbird
  • 🧠Knowledge Modelling
    • What is knowledge modelling?
    • What is a query?
    • Modelling
      • Concepts
        • Concept instances
      • Relationships
        • Question Configuration
        • Rules
          • Match, Infer, Ask process
          • Expressions List
      • Facts
      • Datasources
      • Other features
        • Markdown
        • Import/Export Knowledge Maps
      • Troubleshooting Tips
    • Testing
      • Manual tests
      • Automated tests
      • External User Acceptance Testing (UAT)
    • Versioning
    • Publishing
      • API Management
      • Setting a live version
      • Publishing an agent
    • Stats and Reporting
    • Managing your data
    • The library
      • How to: update a template
  • 🔍Evidence
    • What is evidence?
    • The Evidence Tree
      • The Salience Chart
  • 👩‍💻Developer guides
    • Overview
    • API Guide
      • API request flow
      • Run example queries
      • Environments
      • Error codes
      • Skipping an answer to a question
      • Retrieving a full Evidence Tree for use with a custom UI or application
      • Building an Evidence Tree URL
    • API interactive documentation
    • SDKs
  • Rainbird Labs
    • Overview
    • Consult
    • Generate from documentation
    • Co-author
    • /interact
    • /explain
Powered by GitBook
On this page
  • Comparison functions
  • Comparing data
  • String functions
  • includes
  • String Concatenation
  • Mathematical functions
  • Date functions
  • Retrieve the current date/time
  • Get an index for a given date
  • Add or subtract from a date
  • Calculate the difference between dates
  • Comparing dates
  • List functions
  • countRelationshipInstances
  • sumObjects
  • minObjects
  • maxObjects
  • isSubset
  • Logical Operators (and / or)
  1. Knowledge Modelling
  2. Modelling
  3. Relationships
  4. Rules

Expressions List

Last updated 5 days ago

You can use a variety of functions when writing an expression to compare or transform data during the processing of a rule.

The following functions are currently supported within an expression:

Comparison functions

Comparing data

These will compare one instance to another and will evaluate to either True or False.

These operators are not available for all data types. The table below shows what operators can be used with what data. Operators support either a symbol representation (e.g. =) or a natural language equivalent. For , see the date functions.

Data type of output: Boolean (true/false)

Operator (and aliases)
String (text)
Number
Date
Truth

=

equals

is equal to

!=

does not equal

is not equal to

>

gt

greater than

is greater than

>=

gte

greater than or equal to

is greater than or equal to

<

lt

less than

is less than

<=

lte

less than or equal to

is less than or equal to

Follow our course on comparative expressions for detailed examples and how you can combine multiple comparative expressions.

String functions

includes

Confirm a string contains a set of characters. Partial matching enables you to check the presence of a word or set of characters to infer facts.

Data type of output: Boolean (true/false)

Example

includes(%COMPANY_NAME, ‘LTD’)

In this example you could infer a company is Public Limited Company by checking if a company name contains 'LTD' in the name. E.g. given a company name of Rainbird Technologies LTD the function will evaluate to true.

Matching is case sensitive and will include whitespace before, within and after the search string.

E.g. Given a search string of ' Ltd' a company name of Rainbird Technologies LTD (uppercase) or Rainbird TechnologiesLtd (no whitespace before) would evaluate to false.

To check the absence of a set of characters, = false can be added to the end of the expression.

e.g. includes(%EMAIL_ADDRESS, '@rainbird.ai') = false can determine a person is not an internal user when the email does not contain the company name.

String Concatenation

Join values together into a single output using the + operator. Concatenation enables you to combine variables with text strings to create dynamic output.

Data type of output: String

Example %FIRST_NAME + ' ' + %LAST_NAME

In this example you could create a full name by joining the first and last name with a space in between. E.g. given a first name of John and a last name of Smith the expression will evaluate to John Smith.

Concatenation can join any number of strings and variables together. E.g. 'Claim ' + %CLAIM_ID + ' has been ' + %APPROVAL_STATUS + ' with a payout amount of £' + %PAYOUT_AMOUNT could produce Claim CL-8932 has been APPROVED with a payout amount of £5,750.

Dates, numbers and truth types will automatically convert to strings. Dates will display as a timestamp.


Mathematical functions

The following mathematical functions are available to use with number concepts only.

Data type of output: number

Function name
Description
Example

Add

+ Add two numbers together

10 + 5 = 15

Subtract

- Subtract one number from another

2 - 1 = 1

Divide

/ Divide one number by another

6 / 2 = 3

Multiply

* Multiple one number by another

4 * 2 = 8

Round

round(%X, %Y) Round X to the nearest integer. You can specify Y to round to Y number of places. If Y is not specified, 0 is assumed.

round(123.4) = 123 or round(123.4567,2) = 123.46

Ceiling

ceil(%X) Round X towards plus infinity

ceil(4.2) = 5 ceil(-4.2) = -4

Floor

floor(%X) Round X towards minus infinity

floor(4.2) = 4 floor(-4.2) = -5

Absolute

abs(%X) Calculate the absolute value of X

abs(4.2) = 4.2 abs(-4.2) = 4.2

Minimum

min(%A,%B,%C...) Calculate the minimum value in a set of values

min(6,4,2,15,11) = 2

Maximum

max(%A,%B,%C...) Calculate the maximum value in a set of values

max(6,4,2,15,11) = 15

Modulus

mod(%X,%Y) Calculate the modulus (the remainder of an integer division) of X/Y

mod(5,2) = 1

Power

pow(%X,%Y) Calculate the power of X to Y (X^Y)

pow(10,3) = 1000

Square root

sqrt(%X) Calculate the square root of X

sqrt(64) = 8

Factorial

factorial(%X) Calculate the factorial of X

factorial(4) = 24

Tangent

tan(%X) Calculate the tangent of X

tan(45) = 1.61978

Cosecant

csc(%X) Calculate the cosecant of X

csc(30) = 1.01211

Cotangent

cot(%X) Calculate the cotangent of X

cot(80) = 0.11107

Secant

sec(%X) Calculate the secant of X

sec(60) = -1.04996

Mathematical functions can be combined using brackets.

Mathematical functions can be combined using brackets. Where mathematical calculations are being performed you should observe correct usage of brackets, otherwise the calculation will be read left to right.


Date functions

Use within an expression to compare or transform dates.

These functions allow you to:

  1. Retrieve the current date/time

  2. Get an index for a given date

  3. Add or subtract from a date

  4. Calculate the difference between dates

  5. Compare two dates to determine if one is in the past, present or future from the other

  • Inputs to these functions must come from a concept set to a date type. An error will be displayed if you try to use these on data that is from a string, number or truth concept.

  • Date format: YYYY-MM-DD

  • These functions may output timestamps, dates, numbers or true/false. The output data type will be mentioned for each function.

Retrieve the current date/time

Functions to get the current date or date/time to use within other functions. For example to work out a person's age you can write an expression to calculate the number of years between a person's date-of-birth and today's date.

Data type of output: date/time

Function name
Description
Example

Today

today() Current date at the point the function is executed during a query. The time will default to midnight.

today() = 1703203200000 (translates to 2023-12-22 00:00:00)

Now

now() Current date and time at the point the function is executed during a query.

now() = 1703249564941 (translates to 2023-12-22 12:52:44)

Get an index for a given date

Functions that take a date and return an index (number) based on the chosen function.

Data type of output: number

Function name
Description
Example

Day of week

dayOfWeek(%date) Returns the nth day of the week for a given date (a number from 1 to 7 where Monday = 1 and Sunday -= 7)

dayOfWeek(2023-12-22) = 5 (it's a Friday)

Day of month

dayOfMonth(%date) Returns the nth day of the month for a given date

dayOfMonth(2023-12-22) = 22

Day of year

dayOfYear(%date) Returns the nth day of the year for a given date

dayOfYear(2023-12-22) = 356

Month of year

monthOfYear(%date) Returns the nth month of the year for a given date (a number between 1-12)

monthOfYear(2023-12-22) = 12

Year

year(%date) Returns the year of a given date

year(2023-12-22) = 2023

Add or subtract from a date

Add or remove a number of days, weeks, months or years from a date to create a new date.

This function requires you to pass in a date followed by a number you want to add. e.g. addDays(2023-12-22, 3) = 2023-12-25.

To subtract from a date you can use a negative number. e.g. addDays(2023-12-22, -3) = 2023-12-19

These examples use static data, but both arguments of this function can be dynamic by using variables, so long as the data used is of the correct type. E.g. addDays(%date, %number).

Data type of output: date/time

Function name
Description
Example

Add days

addDays(%date, n) Add n number of days to a given date.

addDays(2023-12-22, 3) =

1703462400000 (converts to 2023-12-25)

Add weeks

addWeeks(%date, n) Add n number of weeks to a given date.

addWeeks(2023-12-22, 3) = 1705017600000 (converts to 2024-01-12)

Add months

addMonths(%date, n) Add n number of months to a given date.

addMonths(2023-12-22), 3) = 1711065600000 (converts to 2024-03-22)

Add years

addYears(%date, n) Add n number of years

addYears(2023-12-222, 3) = 1797897600000 (converts to 2026-12-22)

These functions output a timestamp. If the output of this function is assigned to the object of the rule (%O) then the object should be a date type. If the object is a number, the timestamp will be displayed in the result and/or the evidence.

Calculate the difference between dates

Returns the difference between two dates as a number.

This function requires you to pass in two dates. Regardless of the order, it will always output a positive number.

Data type of output: number

Function name
Description
Example

Seconds between

secondsBetween(%date1, %date2) The number of seconds between two date/times.

secondsBetween(2023-12-22 12:30:10, 2023-12-22 12:30:12) = 2

Minutes between

minutesBetween(%date1, %date2) The number of minutes between two date/times.

minutesBetween(2023-12-22 12:30:10, 2023-12-22 12:40:12) = 10

Hours between

hoursBetween(%date1, %date2) The number of hours between two dates/times.

hoursBetween(2023-12-22 12:30:10, 2023-12-22 14:30:12) = 2

Days between

daysBetween(%date1, %date2) The number of days between two date/times.

daysBetween(2023-12-18 12:30:10, 2023-12-22 12:30:12) = 4

Weeks between

weeksBetween(%date1, %date2) The number of weeksonds between two date/times.

weeksBetween(2023-11-20 12:30:10, 2023-12-22 12:30:12) = 4

Months between

monthsBetween(%date1, %date2) The number of months between two date/times.

monthsBetween(2023-10-22 12:30:10, 2023-12-22 12:30:12) = 2

Years between

yearsBetween(%date1, %date2) The number of years between two date/times.

yearsBetween(2023-12-22 12:30:10, 2025-07-18 12:30:12) = 1

Comparing dates

Pass two dates into the function to check if one is in the past, present or future from the other.

These functions will check the dates and evaluate to true or false for the expression to either pass or fail.

Data type of output: Boolean (true/false)

Function name
Description
Example

Is before date

isBeforeDate(%date1, %date2) Checks if date 1 is before date 2 and returns true or false

isBeforeDate(2023-12-21, 2023-12-22) = true

Is same date

isSameDate(%date1, %date2) Checks if date 1 is the same as date 2 and returns true or false

isSameDate(2023-12-21, 2023-12-22) = false

Is after date

isAfterDate(%date1, %date2) Checks if date 1 is after date 2 and returns true or false

isAfterDate(2023-12-21, 2023-12-22) = false

List functions

Performs comparisons or transformations over a list of facts.

countRelationshipInstances

Count how many facts exist for a given relationship. This enables you to determine the number of relationships a specific entity has.

Data type of output: Number

countRelationshipInstances(%ACCOUNT_ID, 'has account flags', *)

In this example %ACCOUNT_ID denotes a variable where an account identifier is used to constrain the function to consider only that account. The asterisk * denotes all objects.

This will return the number of account flags associated with the given account. For example, if account "ACC-7823" has three flags ("Suspicious activity", "High risk", "Manual review"), the function will evaluate to 3.

countRelationshipInstances(*, 'has account flags', *)

In this example, the first asterisk * denotes all subjects (all accounts), and the second asterisk * denotes all objects (all flags).

This will return the total number of account flags across all accounts in the session. For example, if account "ACC-7823" has three flags ("Suspicious activity", "High risk", "Manual review"), account "ACC-4519" has two flags ("Dormant", "Foreign national"), and account "ACC-9032" has one flag ("Politically exposed"), the function will evaluate to 6.

sumObjects

Adds all number objects from a list and returns the total, when they share the same relationship.

Data type of output: number

sumObjects(%COMPANY, ‘has employee salaries’, *)

In this example %COMPANY denotes a variable where a company name is used to constrain the function to consider only facts for that company. The asterisk * denotes all objects.

This will return a sum of all employee salaries for the given company.

Note: the relationship in this example must be plural

sumObjects(*, ‘has employee salaries’, *)

In this example the subject is not being constrained to a single company as the asterisk * to denote all is also being used for the subject.

This will return a sum of all employee salaries for all companies.

Note: the relationship in this example can be singular or plural

minObjects

Returns the lowest value from a list of objects.

Supports finding the lowest number or earliest date.

Data type of output: date or number (depending on the input data type)

minObjects(%COMPANY, ‘has employee salaries’, *)

In this example %COMPANY denotes a variable where a company name is used to constrain the function to consider only that company. The asterisk * denotes all objects.

This will return the lowest salary for the given company.

Note: the relationship in this example must be plural

minObjects(*, ‘has employee salaries’, *)

In this example the subject is not being constrained to a single company as the asterisk * to denote all is also being used for the subject.

This will return the lowest salary for all companies.

Note: the relationship in this example can be singular or plural

maxObjects

Returns the highest value from a list of objects.

Supports finding the highest number or latest date.

Data type of output: date or number (depending on the input data type)

maxObjects(%COMPANY, ‘has employee salaries’, *)

In this example %COMPANY denotes a variable where a company name is used to constrain the function to consider only that company. The asterisk * denotes all objects.

This will return the highest salary for the given company.

Note: the relationship in this example must be plural

maxObjects(*, ‘has employee salaries’, *)

In this example the subject is not being constrained to a single company as the asterisk * to denote all is also being used for the subject.

This will return the highest salary for all companies.

Note: the relationship in this example can be singular or plural

isSubset

Compares one list of instances against another list and returns either True or False if the items in the 1st list are present in the 2nd list.

Data type of output: Boolean (true/false)

Example of isSubset

This function could be used to check that the essential skills required for a job role is a subset of the skills listed for a candidate.

To do this, the function needs to be told where to gather this data from. This is done by specifying which two relationships contain this information and which side of the relationship (the subject or object) will be compared.

These relationships should be plural.

Using the example above, we might have a rule that looks like this:

Rule: Candidate (%S) > is suitable for > Job role (%O)

Expression:

isSubset(%O, 'requires essential skills', *, %S, 'has skills', *)

At runtime, if we had a candidate of Simone and the rule was processing a job role of Retail Financial Advisor, the expression would do the following to determine that the 1st list is a subset of the 2nd list, confirming the candidate possesses the essential skills for the role and returning true from the expression.

1. Generate 1st list
2. Generate 2nd list

%O = Retail Financial Advisor

%S = Candidate

Retail Financial Advisor > has essential skills > *

(* denotes all)

Simone > meets > *

The engine gathers all facts for Retail Financial Advisor > has essential skills > * and compiles a list from the objects. Shown below.

The engine gathers all facts for Simone > meets > * and compiles a list from the objects. Shown below.

1st list

2nd list

Banking experience

Banking experience

Degree qualified

Multi-lingual

3 x A-levels

Degree qualified

Driving license

Driving license

3 x A-levels

Knowledge of current finance products

Logical Operators (and / or)

Combine multiple conditions within expressions to create more complex logic. Logical operators enable you to evaluate whether multiple conditions are true or whether at least one condition is true.

Operators available:

  • and: All conditions must be true for the expression to evaluate to true

  • or: At least one condition must be true for the expression to evaluate to true

Examples

(includes(%POLICY_TYPE, 'Auto')) and (%CLAIM_AMOUNT > 5000)

This example evaluates to true only when both conditions are met: the policy type contains "Auto" AND the claim amount exceeds £5,000.

(%RISK_SCORE > 80) or (includes(%CLIENT_STATUS, 'VIP'))

This example evaluates to true when either condition is met: the risk score is above 80 OR the client has VIP status.

Logical operators can be combined to create more complex conditions:

((%AGE < 25) or (%DRIVING_YEARS < 3)) and (%ACCIDENT_COUNT > 0)

This will evaluate to true when either the client is under 25 OR has less than 3 years of driving experience, AND they have had at least one accident.

Truth table for logical operators

Condition 1
Condition 2
1 AND 2
1 OR 2

true

true

true

true

true

false

false

true

false

true

false

true

false

false

false

false

  1. Use parentheses to control the order of evaluation when combining multiple logical operators.

  2. and / or must be lowercase

These functions will output a unix timestamp, which is a machine readable datetime format. Mostly you will not see these timestamps. However, if you do come across them during building and want to see it in a human-friendly format there’s many websites you can use to convert them such as .

🧠
epoch converter
Academy
comparing dates
isSubset