Cuneiform Script

Last updated: Mar 26th, 2018

Introduction

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.

  • Priority
  • Preconditions
  • Action

Nodes

The code for a node follows the structure shown below:


node <NODE_NAME> {
    priority: <PRIORITY_VALUE>;

    preconditions {
        <CONDITION_SET>
    }

    action {
        <ACTION_SET>
    }
}
                                    

Preconditions

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.

Priority

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.

Action

The action indicates what is executed by the application when the node is visited. Node actions are written in the Cuneiform Programming Language.

Action Code

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

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

  • y stores the value 3
  • z stores the value 8

Operators

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

Arithmetic operators are used to perform arithmetic operations on numbers.

Operator Description
+ Addition
- Subtraction
* Multiplication
/ Float division
div Integer division

Comparison Operators

Operator Description
== Equal to
!= Not equal
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

Logical Operators

Operator Description
&& Logical and
|| Logical or
! Logical not

Conditionals

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 to specify a block of code to be executed, if a specified condition is true.
  • else to specify a block of code to be executed, if the same condition is false.
  • elif (else if) to specify a new condition to test, if the first condition is false.

if (hour < 10) {
    greeting = "Good morning";
} elif (hour < 20) {
    greeting = "Good day";
} else {
    greeting = "Good evening";
}
                                    

Loops

Cuneiform supports two types of loops.

  • While loops - loop though a block of code as long as the specified condition holds true
  • For loops - looping through arrays

System Operations

System operations are built-in libraries which allow Cuneiform to perform more complex functions. System operations have two sets of attributes.

  1. Properties
  2. Operations

What's next?

The next section explores the implementation of the interpreter which executes the code written in the Cuneiform script.