Mycroft AI
  • Documentation
  • About Mycroft AI
    • Why use Mycroft AI?
    • Glossary of terms
    • Contributing
    • FAQ
  • Using Mycroft AI
    • Get Mycroft
      • Mark II
        • Mark II Dev Kit
      • Mark 1
      • Picroft
      • Linux
      • Mac OS and Windows with VirtualBox
      • Docker
      • Android
    • Pairing Your Device
    • Basic Commands
    • Installing New Skills
    • Customizations
      • Configuration Manager
      • mycroft.conf
      • Languages
        • Français (French)
        • Deutsch (German)
      • Using a Custom Wake Word
      • Speech-To-Text
      • Text-To-Speech
    • Troubleshooting
      • General Troubleshooting
      • Audio Troubleshooting
      • Wake Word Troubleshooting
      • Log Files
      • Support Skill
      • Getting more support
  • Skill Development
    • Voice User Interface Design Guidelines
      • What can a Skill do?
      • Design Process
      • Voice Assistant Personas
      • Interactions
        • Intents
        • Statements and Prompts
        • Confirmations
      • Conversations
      • Error Handling
      • Example Interaction Script
      • Prototyping
      • Design to Development
    • Development Setup
      • Python Resources
      • Your First Skill
    • Skill Structure
      • Lifecycle Methods
      • Logging
      • Skill Settings
      • Dependencies
        • Manifest.yml
        • Requirements files
      • Filesystem access
      • Skill API
    • Integration Tests
      • Test Steps
      • Scenario Outlines
      • Test Runner
      • Reviewing the Report
      • Adding Custom Steps
      • Old Test System
    • User interaction
      • Intents
        • Padatious Intents
        • Adapt Intents
      • Statements
      • Prompts
      • Parsing Utterances
      • Confirmations
      • Conversational Context
      • Converse
    • Displaying information
      • GUI Framework
      • Show Simple Content
      • Mycroft-GUI on a PC
      • Mark 1 Display
    • Advanced Skill Types
      • Fallback Skill
      • Common Play Framework
      • Common Query Framework
      • Common IoT Framework
    • Mycroft Skills Manager
      • Troubleshooting
    • Marketplace Submission
      • Skills Acceptance Process
        • Information Review Template
        • Code Review Template
        • Functional Review Template
        • Combined Template
      • Skill README.md
    • FAQ
  • Mycroft Technologies
    • Technology Overview
    • Roadmap
    • Mycroft Core
      • MessageBus
      • Message Types
      • Services
        • Enclosure
        • Voice Service
        • Audio Service
        • Skills Service
      • Plugins
        • Audioservice Plugins
        • STT Plugins
        • TTS Plugins
        • Wake Word Plugins
      • Testing
      • Legacy Repo
    • Adapt
      • Adapt Examples
      • Adapt Tutorial
    • Lingua Franca
    • Mimic TTS
      • Mimic 3
      • Mimic 2
      • Mimic 1
      • Mimic Recording Studio
    • Mycroft GUI
      • Remote STT and TTS
    • Mycroft Skills Kit
    • Mycroft Skills Manager
    • Padatious
    • Precise
    • Platforms
Powered by GitBook
On this page
  • Prerequisites
  • Step 1 - Sample Intent
  • Step 2 - Import Libraries

Was this helpful?

  1. Mycroft Technologies
  2. Adapt

Adapt Tutorial

A step by step tutorial in using Adapt Intent Parser, using the `single_intent_parser.py` file as a starting point.

PreviousAdapt ExamplesNextLingua Franca

Last updated 5 years ago

Was this helpful?

Prerequisites

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.

If you are looking to use Adapt in a Mycroft Skill, please see

Step 1 - Sample Intent

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"

Step 2 - Import Libraries

First, we need to import json for serializing the Adapt Intent Parser output, and sys for reading in command line arguments.

import json
import sys

Next, we import the IntentBuilder and `IntentDeterminationEngine.

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 = [
    "weather"
]

Register each Keyword with the engine.

for wk in weather_keyword:
    engine.register_entity(wk, "WeatherKeyword")

Next, we declare a collection of weather types. These act as a query parameter on a Weather Intent.

For example, in the sentence:

Will it rain in Seattle tomorrow?

the collection of weather types can then be used to determine whether that weather type is occurring in Seattle.

Next, each weather type is registered with the engine.

for wt in weather_types:
    engine.register_entity(wt, "WeatherType")

Next, a collection of locations is declared. These also act as a query parameter on a Weather Intent, and can be used in combination with the weather type collection.

locations = [
    "Seattle",
    "San Francisco",
    "Tokyo"
]

Next, each location is registered with the engine.

for loc in locations:
    engine.register_entity(loc, "Location")

Next, we construct an intent parser. The intent parser is named WeatherIntent and requires both a WeatherKeyword and Location, and can optionally include a WeatherType.

weather_intent = IntentBuilder("WeatherIntent")
    .require("WeatherKeyword")
    .optionally("WeatherType")
    .require("Location")
    .build()

Next, we register the intent parser with the engine.

engine.register_intent_parser(weather_intent)

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 stdout.

print(json.dumps(intent, indent=4))

Of course, you don't just have to output the Intent to stdout - you can use it to build all sorts of tools.

Skill Development > Intents