Equalities
Equalities
Equalities are functions that evaluate to zero if false or one if true. The most basic form of an equality is to check whether two things are equal. Then there are several variations on this to check, for example, if they are not equal, of one is bigger than the other etc. - and every time the result is a zero or a one to denote false or true, respectively.
The different forms of equalities that can be used in Juno Functions are described in detail below. These types are:
By coding these forms of equality in different functions, the return values of one function can in turn be used as a value in a consequent function, thereby allowing you to create a complex equality function that combines AND and/or OR statements in different combinations.
Basic Equality
The format for defining a basic equality is as follows:
[‘number’/‘text’ or ‘n’/‘t’] : [variable_name] [operator] [comparewith] : [case sensitive?]
where:
- [‘number’/‘text’ or ‘n’/‘t’] specifies whether the values being compared are numeric values or text.
- [variable_name] is the name of a variable or function key in the parameter list.
- [operator] is one of the allowed operators (see below for operator codes that are allowed).
- [comparewith] is a number or text value with which the variable will be compared, or the name of a variable or function key to compare with.
Example 1
To compare the value of the data in the raw data field ‘road_name’ with a constant value of ‘Hamlin Street’ using a case sensitive comparison:
t: road_name = Hamlin Street : true
Important Note that the value that variable ‘road_name’ is being compared with is NOT in quotation marks. Thus always code an equality as:
t: road_name = Hamlin Street : true
and NOT as t: road_name = ‘Hamlin Street’ : true
Example 2
To compare the value of the data in the model parameter ‘par_age’ with the value returned by function ‘f_age_limit’:
n: par_age = f_age_limit
Equality Operators
In both of the above examples, we used the equal operator ‘=’. There are of course many other equality operators you can use:
For TEXT Equalities:
Symbol | Meaning | Example | comment |
---|---|---|---|
= | Equals | t: par_name = Joe Bloggs : true | Is value in ‘par_name’ value equal to ‘Joe Bloggs’ (case sensitive comparison) |
!= | Is Not Equal | t: par_code != error : false | Is value in ‘par_code’ not equal to ‘error’ (case in-sensitive comparison) |
starts_with | Starts With | t: par_type starts_with rehab_ : false | Does value in ‘par_type’ start with ‘rehab_’ (case in-sensitive comparison) |
ends_with | Ends With | t: par_type ends_with _age : false | Does value in ‘par_type’ end with ‘_age’ (case in-sensitive comparison) |
contains | Contains | t: par_type contains ‘concrete’ : false | Does value in ‘par_type’ contain the phrase ‘concrete’ (case in-sensitive comparison) |
within | Within a List | t: par_type within a|b|c : false | Is the value in ‘par_type’ contained in the pipe delimited list ‘(a,b,c)’ ? (case in-sensitive comparison) |
For NUMERIC Equalities:
Symbol | Meaning | Example | comment |
---|---|---|---|
= | Equals | n: par_age = f_age_threshold | Is value in ‘par_age’ equal to ’ the value in variable ‘f_age_threshold’ |
!= | Is Not Equal | n: f_is_ac != 0 | Is value in ‘f_is_ac’ not equal to zero |
> | Greater Than | n: par_age > f_age_threshold | Is the value in ‘par_age’ greater than the value in variable ‘f_age_threshold’ |
>= | Greater Than or Equal To | n: par_age >= f_age_threshold | Is the value in ‘par_age’ greater than or equal to the value in variable ’f_age_threshold |
< | Less Than | n: par_age < f_age_threshold | Is the value in ‘par_age’ less than the value in variable ‘f_age_threshold’ |
<= | Less Than or Equal To | n: par_age <= f_age_threshold | Is the value in ‘par_age’ less than or equal to the value in variable ‘f_age_threshold’ |
IMPORTANT! Please always assume that equality operator symbols are case-sensitive. Use symbols exactly as they are listed above. Specifically, ensure you use lowercase for operators such as ‘starts_with’, ‘containts’ etc.
AND-Compounded Equality
The AND-Compounded Equality is an equality that consists of several Basic Equalities that are compounded together using the (case-sensitive) phrase ‘AND’. If you have mastered the syntax for a Basic Equality, then coding an AND-compounded equality is easy. Here is an example:
n: par_age > f_age_limit AND t: material within a|b|c
This equality first checks two basic equalities:
- n: par_age > f_age_limit asks: ‘Is the value in par_age greater than the value in f_age_limit?’
- t: material within a|b|c asks: ‘Is the value in material in the list (a, b, c)?’
The AND-compounded equality then only returns a 1 (true) if BOTH basic equalities evaluate to 1 (true).
OR-Compounded Equality
The OR-Compounded Equality is an equality that consists of several Basic Equalities that are compounded together using the (case-sensitive) phrase ‘OR’. If you have mastered the syntax for a Basic Equality, then coding an OR-compounded equality is easy. Here is an example:
n: par_age > f_age_limit OR n: f_has_failed = 1
This equality first checks two basic equalities:
- n: par_age > f_age_limit asks: ‘Is the value in par_age greater than the value in f_age_limit?’
- n: f_has_failed = 1 asks: ‘Is the value in f_has_failed equal to 1?’
The OR-compounded equality then returns a 1 (true) if EITHER of these two basic equalities evaluate to 1 (true).
Building More Complex Equalities
You can build any complex equality consisting of combinations of AND and OR equalities by sequentially creating the sub-elements of your final equality. Let’s say you want to build the following equality (expressed in pseudo-code):
if [(A = x AND B = y) OR (C = z)] then true
Let’s assume that A, B and C as well as x, y, and z are all text fields. Thus we are dealing with a text-type equality.
You can break this into two separate JFunction Equalities. First you create an AND-compounded equality (assumed to be mapped to key ‘f_eq_1’):
t: A = x AND t: B = y (assigned to key: ‘f_eq_1’)
Next you combine the result of ‘f_eq_1’ in an OR-compounded equality:
n : f_eq_1 = 1 OR t: C = z
Thus the result of the equality that is mapped to key ‘f_eq_1’ is used in the second OR-compounded equality. Note that the result in ‘f_eq_1’ is now a number (a zero or one) and thus in the final equality we use ‘n:’ to tell JCass that the first part of the OR-compounded equality consists of a numerical comparison.
When creating complex compounded equalities in this manner it is vital that the order of your JFunctions be correct. JFunctions are evaluated as they are listed, from top to bottom. Thus, ‘f_eq_1’ needs to be evaluated first before it can be used in the second, OR-compounded equality.