< RiTa index

A more detailed tutorial on Observable

RiScript is a simple, writer-oriented, scripting language integrated in RiTa. RiScript statements, the basics of which are described below, can be included in any grammar, or executed directly by calling RiTa.evaluate(). Fragments of writing can be abitrarily transformed, at runtime, by using the provided transforms, or by specifying your own bespoke ones.

RiScript is a simplified version of the Dial scripting language, originally created for Dialogic. The language specification and parser were created via the blazing fast Chevrotain toolkit.


Select a random choice from a group of options:
The weather was [sad | gloomy | depressed].  ->  "The weather was gloomy."

I'm [very | super | really] glad to \
[[meet | know] you | learn about you]. -> "I'm very glad to know you."

Weighted Choice

Assign weights to the options in a choice. In the example below 'depressed' will be selected four times as often as 'sad' and twice as often as 'gloomy'
The weather was [sad | gloomy (2) | depressed (4)].  ->  "The weather was depressed." 


Basic assignments, which start a line, do not have output. They simply create or update a variable to be used elsewhere (variables in JavaScript can also be used when passed in via the script's context)
$desc=wet and cold
The weather was $desc -> "The weather was wet and cold"

Inline Assignment

Inline assignments (within brackets) allow one to easily set a variable, output it, and refer to it later:
Jane was from [$place=[New York | Berlin | Shanghai]].
$place is cold and wet.
-> "Jane was from Berlin. Berlin is cold and wet."

$place=(New York | Berlin | Shanghai)
$place is cold and wet in winter.
-> "Berlin is cold and wet in the winter."

In [$place=[New York | Berlin | Shanghai]] it is cold and wet in winter.
-> "In Berlin it is cold and wet in the winter."


Transforms allow for the evaluation of variables, choices and raw text at runtime. RiScript provides a number of built-in transforms, including pluralize , capitalize and articlize, which can be nested to create complex expressions. User-defined transforms can be easily added using RiTa.addTransform() or by simply passing a transform function as part of a script's 'context'.
How many [tooth | menu | child].pluralize() do you have?
How many [tooth | menu | child].pluralize().toUpper() do you have?

He grew up to be $animal.articlize().
He grew up to be [anteater].articlize().
He grew up to be [anteater].articlize().myCustomTransform().

Built-in transforms, with their shortcuts, are listed below
Transform Description Alias
articlize() adds the correct article according to the phonemes art()
pluralize() pluralizes the phrase via the RiTa inflector s()
norepeat() ensures a choice will never repeat its output nr()
capitalize() capitalizes the first letter of the phrase ucf()
uppercase() capitalizes all letters of the phrase uc()
quotify() adds (smart) quotes around the phrase qq()