Skip to content

Instantly share code, notes, and snippets.

@forslund
Created September 10, 2018 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forslund/d98c98816dc90600aed7ad62bfd0f223 to your computer and use it in GitHub Desktop.
Save forslund/d98c98816dc90600aed7ad62bfd0f223 to your computer and use it in GitHub Desktop.
import json
from adapt.intent import IntentBuilder
from adapt.engine import IntentDeterminationEngine
from adapt.context import ContextManager
engine = IntentDeterminationEngine()
context_manager = ContextManager()
# define vocabulary
weather_keyword = [
"weather"
]
for wk in weather_keyword:
engine.register_entity(wk, "WeatherKeyword")
# structure intent
weather_intent = IntentBuilder("WeatherIntent")\
.require("WeatherKeyword")\
.one_of("Location", "LocationContext").build()
# .require("LocationContext").build()
engine.register_intent_parser(weather_intent)
word='lizard'
context='LocationContext'
entity = {}
entity['data'] = [(word, context)]
entity['match'] = word
entity['key'] = word
context_manager.inject_context(entity)
if __name__ == "__main__":
for intent in engine.determine_intent('weather',
context_manager=context_manager):
if intent and intent.get('confidence') > 0:
print(json.dumps(intent, indent=4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment