Skip to main content

co-types

warning

This documentation page is still being written.

This module defines the set of built-in types that are available in colang. A type defines the set of values that can be stored in a context variable.

note

NLU entities are a particular type of context variables. The types defined by this module also apply to them.

Primitive Types

There are four primitive types supported by colang:

TypeDescriptionExamples
textA sequence of characters."something", "Great! See you soon!"
regexA regular expression."\d\d-\d\d" for "12-31"
numberAn integer or float number expressed both using digits and letters.2, 15, 250.2
booleanRepresents a boolean (yes/no) value.True, False
nameRepresents a name i.e. starting with upper case.John, Marry Doe

Text Operations

The following operations can be performed with a string:

  1. Split by a given string e.g. split $a by " " to split by spaces; it returns a list of strings;

Composite Types

In addition to the primitive types, there are two composite types:

TypeDescriptionExamples
listA list of primitive values or objects["a", "b", "c"]
objectA set of property names and property values{"name": "John", "age": 32}

Object Types

Built-in object types include: DateTime.

DateTime

A DateDime object has the following properties:

PropertyDescriptionExamples
typeThe type of datetime valuedate, time, datetime, date_interval, time_interval or datetime_interval
valueThe normalized string value"2021-12-25", "14:00:00", "2021-12-25 14:00:00", "X to Y" for intervals
from_valueThe start of the interval as a DateTime value.
to_valueThe end of the interval as a DateTime value.

The six DateTime types, which correspond to the various ways people refer to the date/time of events, are explained below:

TypeDescriptionExamples
dateAn exact date, without a time."today", "Jun 27th, 1985"
timeAn exact time, without a date."5pm", "at noon"
datetimeAn exact date and time."today at 5:30pm"
date_intervalA date interval, without time."next week"
time_intervalA time interval, without a date."in the afternoon"
datetime_intervalAn exact interval, with both dates and times"tomorrow between 2pm and 4:30pm"

Functions

  • weekday($datetime): returns a number representing the day of the week (0=Monday, 6=Sunday)

Lists

Lists can be defined using the following syntax:

$names = "John", "Marry", "Mike"

To add or remove elements from a list:

add "Robert" to $names
remove "John" from $names

To access elements in a list based on their position:

$first_name = $names[0]
$second_name = $names[1]
$last_name = $names[-1]

To access the number of elements in a list:

$n = length of $names
$n = the length of $names
$n = the number of $names
$n = size of $names
tip

Lists in colang work exactly the same way as arrays in python. We can also use slicing for advanced use cases.

Dictionaries

For advanced use cases, we can also use dictionaries, exactly as in python.

$field_type = {}

$field_type["name"] = "name"
$filed_type["age"] = "number"

# To update a key
update $field_type for "name" to "text"

# or the python way
$field_type.update({"name": "text"})