Add configuration settings for using adapt's context
@@ -22,6 +22,8 @@ from mycroft.messagebus.message import Message
from mycroft.skills.core import open_intent_envelope
from mycroft.util.log import getLogger
from mycroft.util.parse import normalize
+from mycroft.configuration import ConfigurationManager
+
from adapt.context import ContextManagerFrame
import time
__author__ = 'seanfitz'
@@ -35,13 +37,15 @@ class ContextManager(object):
Use to track context throughout the course of a conversational session.
How to manage a session's lifecycle is not captured here.
"""
- def __init__(self):
+ def __init__(self, timeout):
self.frame_stack = []
+ self.timeout = timeout * 60 # minutes to seconds
def clear_context(self):
self.frame_stack = []
def remove_context(self, context_id):
+ print "REMOVING CONTEXT!"
self.frame_stack = [f for f in self.frame_stack
if context_id in f.get('data', [])]
@@ -77,13 +81,16 @@ class ContextManager(object):
list: a list of entities
"""
relevant_frames = [frame[0] for frame in self.frame_stack if
- time.time() - frame[1] < 120]
+ time.time() - frame[1] < self.timeout]
if not max_frames or max_frames > len(relevant_frames):
max_frames = len(relevant_frames)
missing_entities = list(missing_entities)
context = []
+ print "Recalculate confidence"
+ print len(relevant_frames)
for i in xrange(max_frames):
+ print i
frame_entities = [entity.copy() for entity in
relevant_frames[i].entities]
for entity in frame_entities:
@@ -110,8 +117,12 @@ class ContextManager(object):
class IntentService(object):
def __init__(self, emitter):
+ self.config = ConfigurationManager.get()
self.engine = IntentDeterminationEngine()
- self.context_manager = ContextManager()
+ self.context_keywords = self.config.get('context_keywords', [])
+ self.context_max_frames = self.config.get('context_max_frames', 3)
+ self.context_timeout = self.config.get('context_timeout', 2)
+ self.context_manager = ContextManager(self.context_timeout)
self.emitter = emitter
self.emitter.on('register_vocab', self.handle_register_vocab)
self.emitter.on('register_intent', self.handle_register_intent)
@@ -150,6 +161,8 @@ class IntentService(object):
if best_intent and best_intent.get('confidence', 0.0) > 0.0:
for tag in best_intent['__tags__']:
context_entity = tag.get('entities')[0]
+ print context_entity['data'][0]
+ if context_entity['data'][0][1] in self.context_keywords:
self.context_manager.inject_context(context_entity)
reply = message.reply(
best_intent.get('intent_type'), best_intent)
