Cuneiform script is the programming language used to develop conversational applications using the Cuneiform platform. A script is written in a file containing a .cu extension. Each script represents the conversation design for an intent.
Each intent consists of a Conversation graph. The conversation graph is a Graph data structure which consists of a set of nodes interconnected by edges. Each edge connecting into a single node may consist with a set of preconditions.
A cuneiform file consists of a set of nodes. Each node consists of the following properties.
The code for a node follows the structure shown below:
node <NODE_NAME> {
priority: <PRIORITY_VALUE>;
preconditions {
<CONDITION_SET>
}
action {
<ACTION_SET>
}
}
In the conversation graph, the preconditions represent the edges. Each edge pointing into a node represents the preconditions of that node. The condition set within the preconditions are written as a condition in conditionals for Cuneiform.
If there are no preconditions for the node, the condition set can be left empty. If there are more than one conditions, they can be separated by && or || operators, as well as parenthesis. To learn more about conditional statements, read about it in the conditionals section of the Cuneiform documentation.
The sole purpose of assigning a priority to a node is accounting for cases where preconditions get satisfied for multiple nodes. In this case, the node with the highest priority gets executed. This is done such that the developer get more control over the behaviour of the system. The priority is set to 5 by default.
The action indicates what is executed by the application when the node is visited. Node actions are written in the Cuneiform Programming Language.
The action code represents the core of a node. The set of instructions to be executed when the node is visited is written in the action code. The Cuneiform programming language consists of its own syntax to execute various programming functions. Detailed information regarding the Cuneiform programming languqage can be found in the Documentation.
Variables in Cuneiform are declared with the "var" keyword, followed by the variable name. There are two types of variables in Cuneiform.
Similar to languages like Javascript, Cuneiform variables are containers for storing data values. In this example, x, y, and z are variables.
var x = 5;
var y = 3;
var z = x + y;
From the example above, you can expect
The numbers in an arithmetic operation are called operands.
The operation to be performed between the two operands is defined by an operator.
Arithmetic operators are used to perform arithmetic operations on numbers.
Operator | Description |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Float division |
div | Integer division |
Operator | Description |
---|---|
== | Equal to |
!= | Not equal |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
Operator | Description |
---|---|
&& | Logical and |
|| | Logical or |
! | Logical not |
Conditional statements are used to perform different actions based on different conditions. Conditional statements are written in our code to perform different actions for different decisions.
In Cuneiform, we use the following conditional statements:
if (hour < 10) {
greeting = "Good morning";
} elif (hour < 20) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
Cuneiform supports two types of loops.
System operations are built-in libraries which allow Cuneiform to perform more complex functions. System operations have two sets of attributes.
The next section explores the implementation of the interpreter which executes the code written in the Cuneiform script.