1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
__author__ = 'the-kid89'
"""
A sample program that uses multiple intents and disambiguates by
intent confidence
try with the following:
PYTHONPATH=. python examples/multi_intent_parser.py "what's the weather like in tokyo"
PYTHONPATH=. python examples/multi_intent_parser.py "play some music by the clash"
"""
import json
import sys
from adapt.intent import IntentBuilder
from adapt.engine import DomainIntentDeterminationEngine
engine = DomainIntentDeterminationEngine()
engine.register_domain('Domain1')
engine.register_domain('Domain2')
# define vocabulary
weather_keyword = [
"weather"
]
for wk in weather_keyword:
engine.register_entity(wk, "WeatherKeyword", domain='Domain1')
weather_types = [
"snow",
"rain",
"wind",
"sleet",
"sun"
]
for wt in weather_types:
engine.register_entity(wt, "WeatherType", domain='Domain1')
locations = [
"Seattle",
"San Francisco",
"Tokyo"
]
for l in locations:
engine.register_entity(l, "Location", domain='Domain1')
# structure intent
weather_intent = IntentBuilder("WeatherIntent")\
.require("WeatherKeyword")\
.optionally("WeatherType")\
.require("Location")\
.build()
# define music vocabulary
artists = [
"third eye blind",
"the who",
"the clash",
"john mayer",
"kings of leon",
"adelle"
]
for a in artists:
engine.register_entity(a, "Artist", domain='Domain2')
music_verbs = [
"listen",
"hear",
"play"
]
for mv in music_verbs:
engine.register_entity(mv, "MusicVerb", domain='Domain2')
music_keywords = [
"songs",
"music"
]
for mk in music_keywords:
engine.register_entity(mk, "MusicKeyword", domain='Domain2')
music_intent = IntentBuilder("MusicIntent")\
.require("MusicVerb")\
.optionally("MusicKeyword")\
.optionally("Artist")\
.build()
engine.register_intent_parser(weather_intent, domain='Domain1')
engine.register_intent_parser(music_intent, domain='Domain2')
if __name__ == "__main__":
for intents in engine.determine_intent(' '.join(sys.argv[1:])):
print(intents)
|