Classes allow you to categorize similar types of objects, items or, any related concept in order to respond and extract useful pieces of data. For example, a clothing company might create a class called "products" that contains entries like "hat, shoes, pants, dress, jacket, etc".
Classes consist of three main parts:
Name - The name of the class, for example, we could create a class that contains a list of the most popular musicians.
Entries - The entries that make up a class. In the case of the musician example, this would be the name of individual musician, for example “the Beatles”
Synonyms - Synonyms for each entry are other ways users might reference individual entries. For example a user might enter "Fab Four" as a synonym for The Beatles.
Snap’s NLP is equipped with a number of system classes, which are built in classes that already handle some of the most common instances, things like location, time, age, currency, and temperature.
- Go to the NLP section of your left-hand nav and select classes
- Select “NEW” to create a new class
In order to use a class in an intent, we must first create a slot. Slots indicate where we expect a class to be called in a given intent.
- Select the intent in which you want to create your slot.
- Click the “create” button.
- Give your slot a name and select the class you’d like to evoke.
- Once you’ve created your slot, you’ll see it appear next to your samples in your intent.
- In order to use the newly created slot, you’ll need to highlight the word in your sample where you’d expect the slot to be evoked. In this example we’ll highlight "Jay Z" and select the musician slot.
- Once the proper word has been highlighted and tagged anytime a user says something that matches an entry in the Musician class, the bot will will be able to respond correctly. Instead of having to create entries for “do you have Jay Z tickets for sale”, “do you have Rihanna tickets for sale”, etc. you can create one sample, tag the proper word, and respond correctly to ticket requests for any artist in your musician class.
Composite classes allow you to combine the functionality of a system class with the flexibility of a custom class. For example, you might wish to create a composite class that contains a list of real locations (the system location class) and combine it with a list of fictional locations.
- Use the @ symbol in the class entry field to open and select from a dropdown of all of your available classes.
- You can either add individual entries or existing classes to your composite class.
(Left) A composite class set up with a class and individual entries.(Right) A composite class made up of two classes.
Synonyms in composite classes
Composite classes can have multiple classes and entries, but cannot contain any synonyms. If you want to use synonyms, add them to one of the classes being used in your composite class.