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:
Type | Description | Examples |
---|---|---|
text | A sequence of characters. | "something", "Great! See you soon!" |
regex | A regular expression. | "\d\d-\d\d" for "12-31" |
number | An integer or float number expressed both using digits and letters. | 2, 15, 250.2 |
boolean | Represents a boolean (yes/no) value. | True, False |
name | Represents a name i.e. starting with upper case. | John, Marry Doe |
Text Operations
The following operations can be performed with a string:
- 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:
Type | Description | Examples |
---|---|---|
list | A list of primitive values or objects | ["a", "b", "c"] |
object | A 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:
Property | Description | Examples |
---|---|---|
type | The type of datetime value | date , time , datetime , date_interval , time_interval or datetime_interval |
value | The normalized string value | "2021-12-25", "14:00:00", "2021-12-25 14:00:00", "X to Y" for intervals |
from_value | The start of the interval as a DateTime value. | |
to_value | The 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:
Type | Description | Examples |
---|---|---|
date | An exact date, without a time. | "today", "Jun 27th, 1985" |
time | An exact time, without a date. | "5pm", "at noon" |
datetime | An exact date and time. | "today at 5:30pm" |
date_interval | A date interval, without time. | "next week" |
time_interval | A time interval, without a date. | "in the afternoon" |
datetime_interval | An 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"})