Created
September 10, 2018 09:40
-
-
Save forslund/d98c98816dc90600aed7ad62bfd0f223 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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