The Adapt Intent Parser is a flexible and extensible intent definition and determination framework. It is intended to parse natural language text into a structured intent that can then be invoked programatically.
To take a dependency on Adapt, it's recommended to use virtualenv and pip to install source from github.
$ virtualenv myvirtualenv
$ . myvirtualenv/bin/activate
$ pip install -e git+https://github.com/mycroftai/adapt#egg=adapt-parserExecutable examples can be found in the examples folder.
In this context, an Intent is an action the system should perform. In the context of Pandora, we’ll define two actions: List Stations, and Select Station (aka start playback)
With the Adapt intent builder:
list_stations_intent = IntentBuilder('pandora:list_stations')\
.require('Browse Music Command')\
.build()For the above, we are describing a “List Stations” intent, which has a single requirement of a “Browse Music Command” entity.
play_music_command = IntentBuilder('pandora:select_station')\
.require('Listen Command')\
.require('Pandora Station')\
.optionally('Music Keyword')\
.build()For the above, we are describing a “Select Station” (aka start playback) intent, which requires a “Listen Command” entity, a “Pandora Station”, and optionally a “Music Keyword” entity.
Entities are a named value. Examples include:
Blink 182 is an Artist
The Big Bang Theory is a Television Show
Play is a Listen Command
Song(s) is a Music Keyword
For my Pandora implementation, there is a static set of vocabulary for the Browse Music Command, Listen Command, and Music Keyword (defined by me, a native english speaker and all-around good guy). Pandora Station entities are populated via a "List Stations" API call to Pandora. Here’s what the vocabulary registration looks like.
def register_vocab(entity_type, entity_value):
pass
# a tiny bit of code
def register_pandora_vocab(emitter):
for v in ["stations"]:
register_vocab('Browse Music Command', v)
for v in ["play", "listen", "hear"]:
register_vocab('Listen Command', v)
for v in ["music", "radio"]:
register_vocab('Music Keyword', v)
for v in ["Pandora"]:
register_vocab('Plugin Name', v)
station_name_regex = re.compile(r"(.*) Radio")
p = get_pandora()
for station in p.stations:
m = station_name_regex.match(station.get('stationName'))
if not m:
continue
for match in m.groups():
register_vocab('Pandora Station', match)Further documentation can be found at https://adapt.mycroft.ai
Adapt Intent Parser - это гибкий и расширяемый фреймворк для распознавания и определения намерений пользователя. Он предназначен для парсинга текста на естественном языке в специальную структуру намерения, которую затем можно вызывать программно.
Чтобы работать с Adapt, рекомендуется использовать virtualenv и pip для установки исходного кода из github.
$ virtualenv myvirtualenv
$ . myvirtualenv/bin/activate
$ pip install -e git+https://github.com/mycroftai/adapt#egg=adapt-parserИсполняемые примеры можно найти в папке [examples] (https://github.com/MycroftAI/adapt/tree/master/examples).
В этом контексте "Намерение" - это действие, которое должна выполнить система. В контексте Pandora мы определили два действия: Список станций (List Stations) и Выбор станции (Station Select или начало воспроизведения)
С помощью Adapt intent builder:
list_stations_intent = IntentBuilder('pandora:list_stations')\
.require('Browse Music Command')\
.build()Выше мы описываем намерение «Список станций» («List Stations»), в котором есть единственное требование к сущности «Browse Music Command».
play_music_command = IntentBuilder('pandora:select_station')\
.require('Listen Command')\
.require('Pandora Station')\
.optionally('Music Keyword')\
.build()Выше мы описываем намерение «Выбор станции» (Station Select, он же начало воспроизведения), для которого требуется объект «Команда прослушивания», «Станция Пандора» и, необязательно, объект «Музыкальное ключевое слово».
Сущности являются именованными значениеми. Пример:
Blink 182 - это Артист
The Big Bang Theory is a Television Show
Play - это Listen Command
Song (s) - это Music Keyword
Для реализации Pandora есть статический набор слов для команд «Просмотр музыки», «Слушать команда» и «Ключевое слово музыки» (определено автором, носителем английского языка и отличным парнем). Объекты станции Пандоры заполняются посредством вызова API «Станции списка» для Пандоры. Вот как выглядит регистрация словаря.
def register_vocab(entity_type, entity_value):
pass
#Чуть-чуть кода
def register_pandora_vocab(emitter):
for v in ["stations"]:
register_vocab('Browse Music Command', v)
for v in ["play", "listen", "hear"]:
register_vocab('Listen Command', v)
for v in ["music", "radio"]:
register_vocab('Music Keyword', v)
for v in ["Pandora"]:
register_vocab('Plugin Name', v)
station_name_regex = re.compile(r"(.*) Radio")
p = get_pandora()
for station in p.stations:
m = station_name_regex.match(station.get('stationName'))
if not m:
continue
for match in m.groups():
register_vocab('Pandora Station', match)Дополнительную документацию можно найти по адресу https://adapt.mycroft.ai.
