Enums
Enumerations are important for classification tasks or in any situation where you need a choice to be made from a list of options.
Example
You can pass a list of items in any of the supported native types: str, float, int or bool.
Literals#
We can also use Literals:
Example
Extracting to a Literal type returns one of its possible options in its native type (str, float, int or bool).
Enum classes#
Or Enum classes of native types. An example of extracting to Enum classes:
Example
For the model, the important information is actual the value of each enum member, not its name. For example, in this enum, the model would only see the strings to the right of each member (the enum values), not "RED", "ORANGE" nor "GREEN":
See the Tag classification example to see how Enum is used to tag support queries.
Classify#
You can also use the classify() method to extract enumerations, which accepts the enum types we've seen above. It calls extract() internally and its only justification is to make things more readable: