Comment on page
A step by step tutorial in using Adapt Intent Parser, using the `single_intent_parser.py` file as a starting point.
To complete this tutorial, you should have some basic knowledge of the Python programming language, and be comfortable executing commands on a Linux command line.
This is the sample Intent around which the tutorial is based.
A sample intent that uses a fixed vocabulary to extract entities for an intent
try with the following:
PYTHONPATH=. python examples/single_intent_parser.py "what's the weather like in tokyo"
First, we need to import
jsonfor serializing the Adapt Intent Parser output, and
sysfor reading in command line arguments.
Next, we import the
from adapt.intent import IntentBuilder
from adapt.engine import IntentDeterminationEngine
Next, we instantiate an IntentDeterminationEngine object.
engine = IntentDeterminationEngine()
Next, we delcare a collection of weather Keywords, in JSON syntax. These Keywords act as hints to the Adapt Intent Parser about which intent context is being referenced by an Utterance.
weather_keyword = [
Register each Keyword with the
for wk in weather_keyword:
Next, we declare a
collectionof weather types. These act as a query parameter on a Weather Intent.
For example, in the sentence:
Will it rain in Seattle tomorrow?
collectionof weather types can then be used to determine whether that weather type is occurring in Seattle.
Next, each weather type is registered with the
for wt in weather_types:
collectionof locations is declared. These also act as a query parameter on a Weather Intent, and can be used in combination with the weather type
locations = [
Next, each location is registered with the
for loc in locations:
Next, we construct an
intent parser. The
intent parseris named
WeatherIntentand requires both a
Location, and can optionally include a
weather_intent = IntentBuilder("WeatherIntent")
Next, we register the
intent parserwith the
We then declare an entry point for the script. @TODO - need to explain here what an entry point is.
if __name__ == "__main__":
Next, pass the command line arguments to this script as an Utterance into
engine.determine_intent(). This function returns a generator, and we then use the generator to iterate through the results.
for intent in engine.determine_intent(' '.join(sys.argv[1:])):
If the confidence is >0, this is a valid Intent.
if intent.get('confidence') > 0:
Next, serialize the Intent and print it to
Of course, you don't just have to output the Intent to
stdout- you can use it to build all sorts of tools.