Concepts in RavenClaw
Basic concept types
There are two main categories of concepts:
- system concepts contain values that the system manipulates internally (like variables in typical programming languages); they are typically used to store results retrieved from the backend.
- user concepts capture entities provided by the user.
In addition, each system or user concept can be of one of four atomic types:
- integer (see INT_USER_CONCEPT and INT_SYSTEM_CONCEPT)
- float (see FLOAT_USER_CONCEPT and FLOAT_SYSTEM_CONCEPT)
- boolean (see BOOL_USER_CONCEPT and BOOL_SYSTEM_CONCEPT)
- string (see STRING_USER_CONCEPT and STRING_SYSTEM_CONCEPT)
You can also define your own "custom" concept types. There are three structured types that can be used in custom concepts:
- arrays (defined with DEFINE_ARRAY_CONCEPT_TYPE): a list of identical elements identified by an index (0,1,2...). RCTSL arrays are dynamically allocated which means that you don't have to know their size when you declare them, their size will increase as you add more elements
- frames (defined with DEFINE_FRAME_CONCEPT_TYPE): a set of atomic or custom concepts, each representing distinct but related entities (as in this case)
- structs (defined with DEFINE_STRUCT_CONCEPT_TYPE): a set of atomic or custom concepts that represent a single entity as a whole
The distinction between frames and structs is fairly subtle but quite important for systems that deal with even moderately complex information. Whether to use one or the other for a particular structured concept depends on how you view that concept for your particular task. For example say your system talks about dates, which are composed of three integer elements, "day", "month", and "year". If you want the system to be able to discuss about the elements of a particular date independently (e.g. having the system asking questions like "Which day in October did you want to travel?"), then you should define your date concept as a frame. On the other hand if your system considers dates as single entities and never discusses each element individually (e.g. "Did you say you wanted to travel on October, 16, 2007?"), then your date concept should be a struct.
Referring to concepts
Concepts are used by name in declarations, definitions, grammar mappings, and conveyances.
In addition, they may be referred to by arbitrary C++ code. To get the value of a concept, first get a pointer to the concept class with the C macro. There are several operators defined on the concept class, including
if(*C("destination") == "Orlando") cout << "We're going to Disney!"
string cast operators are defined, so you can convert a concept to its best-guess basic type, as in
string probable_destination = (string)(*C("destination"))