def intent_task_specified(self, intent):
 
     resolution = intent['slots']['TASK']['resolutions']['resolutionsPerAuthority'][0]
     values = resolution['values'][0]
     task = values['value']['id']
     
     # Store task preemptively to pass to pg.generate
     self.session_attributes['state']['task'] = task
 
     card_title         = "Task Chosen"
     speech_output      = pg.generate(self.session_attributes, 'specifying_a_task')
     reprompt_text      = "I'm ready for your input."
     should_end_session = False
     
     # Assign the next state
     self.session_attributes['state'] = {
         'value': 'attempt_task',
         'task' : task,
         'word' : self.word,
         'sen'  : '0',
         'dfn'  : '0',
         'syn'  : '0'
     }
     # Populate prev state
     self.session_attributes = helper.dump_state(self.session_attributes)
     
     return helper.build_response(self.session_attributes, helper.build_speechlet_response(
             card_title, speech_output, reprompt_text, should_end_session))
Exemplo n.º 2
0
    def intent_word_skipped(self, intent):

        #Get User data
        words = db.getUserData(self.userId)
        # Get a new word from the database
        word = db.get_random_word(self.userId)
        #update user info
        #db.addUserData(self.userId, word)

        # Assign that word to the state before passing to speech_output
        self.session_attributes['state']['word'] = word

        card_title = "Word Skipped"
        speech_output = pg.generate(self.session_attributes, 'skip_word')
        reprompt_text = "Is this word satisfactory?"
        should_end_session = False

        # Initialize the select word class
        self.session_attributes['state'] = {
            'value': 'select_word',
            'word': word
        }
        # Dump the state to prev_state
        self.session_attributes = helper.dump_state(self.session_attributes)

        return helper.build_response(
            self.session_attributes,
            helper.build_speechlet_response(card_title, speech_output,
                                            reprompt_text, should_end_session))
Exemplo n.º 3
0
    def intent_try_again(self):
        session_attributes = {}
        card_title = "Agree to Try Again"
        # Introduce the task attempt
        speech_output = pg.generate(self.session_attributes,
                                    'agreeing_to_try_again')
        reprompt_text = "I'm ready for your input."
        should_end_session = False

        # Assign the next state
        self.session_attributes['state'] = {
            'value': 'attempt_task',
            'task': self.task,
            'word': self.word,
            'sen': self.sen_complete,
            'dfn': self.def_complete,
            'syn': self.syn_complete
        }
        # Populate prev_state
        self.session_attributes = helper.dump_state(self.session_attributes)

        return helper.build_response(
            self.session_attributes,
            helper.build_speechlet_response(card_title, speech_output,
                                            reprompt_text, should_end_session))
    def intent_task_specified(self, intent):

        # check to see if we parsed a value
        content_present = intent['slots']['TASK'].get('resolutions')
        task = None
        if content_present:
            resolution = intent['slots']['TASK']['resolutions'][
                'resolutionsPerAuthority'][0]
            # if we have a task match
            if resolution.get('values'):
                values = resolution['values'][0]
                task = values['value']['id']

        # caught an incorrect value
        if task == None:

            self.session_attributes = self.session_attributes

            card_title = "Invalid Task"
            speech_output = "We could not understand your exercise. Could you please repeat?"
            should_end_session = False

            return helper.build_response(
                self.session_attributes,
                helper.build_speechlet_response(card_title, speech_output,
                                                None, should_end_session))

        # Store task preemptively to pass to pg.generate
        self.session_attributes['state']['task'] = task

        card_title = "Task Chosen"
        speech_output = pg.generate(self.session_attributes,
                                    'specifying_a_task')
        reprompt_text = "I'm ready for your input."
        should_end_session = False

        # Assign the next state
        self.session_attributes['state'] = {
            'value': 'attempt_task',
            'task': task,
            'word': self.word,
            'sen': self.sen_complete,
            'dfn': self.def_complete,
            'syn': self.syn_complete
        }
        # Populate prev_state
        self.session_attributes = helper.dump_state(self.session_attributes)

        return helper.build_response(
            self.session_attributes,
            helper.build_speechlet_response(card_title, speech_output,
                                            reprompt_text, should_end_session))
 def intent_word_confirmed(self, intent):
     
     card_title         = "Word Confirmed"
     speech_output      = pg.generate(self.session_attributes, 'confirming_word')
     reprompt_text      = "Please select a task."
     should_end_session = False
     
     # Assign the next state
     self.session_attributes['state'] = {
         'value': 'select_task',
         'word' : self.word,
         'sen'  : '0',
         'dfn'  : '0',
         'syn'  : '0'
     }
     # Populate prev_state
     self.session_attributes = helper.dump_state(self.session_attributes)
     
     return helper.build_response(self.session_attributes, helper.build_speechlet_response(
             card_title, speech_output, reprompt_text, should_end_session))
 def intent_unhandled(self):
 
     card_title         = "Try Again"
     speech_output      = pg.generate(self.session_attributes, 'try_again')
     reprompt_text      = "Would you like to try again?"
     should_end_session = False
     
     # Assign the next state            
     self.session_attributes['state'] = {
         'value': 'try_again',
         'task' : self.task,
         'word' : self.word,
         'sen'  : self.sen_complete,
         'dfn'  : self.def_complete,
         'syn'  : self.syn_complete
     }
     # Dump the state to prev_state
     self.session_attributes = helper.dump_state(self.session_attributes)
     
     return helper.build_response(self.session_attributes, helper.build_speechlet_response(
         card_title, speech_output, reprompt_text, should_end_session))
Exemplo n.º 7
0
    def intent_next_task(self):

        card_title = "Next Task after Fail"
        # Just use the value in the database
        speech_output = pg.generate(self.session_attributes, 'go_to_next_task')
        should_end_session = False

        # Assign the next state
        self.session_attributes['state'] = {
            'value': 'select_task',
            'word': self.word,
            'sen': self.sen_complete,
            'dfn': self.def_complete,
            'syn': self.syn_complete
        }
        # Dump the state to prev_state
        self.session_attributes = helper.dump_state(self.session_attributes)

        return helper.build_response(
            self.session_attributes,
            helper.build_speechlet_response(card_title, speech_output, None,
                                            should_end_session))
    def intent_verify(self, intent):

        # Get the answer from the intent
        answer = intent['slots']['ANSWER']['value']

        # Query the database for the correct answer set
        query = db.get_word_info(self.word)
        # Set the query to the value for this task
        query_task = query[self.task]
        # Set the query_syn to the synonym list of the word
        query_syn = query['syn']
        # Call the verification function with this info
        success = True
        try:
            verifier = Verification(self.word, query_syn, answer, query_task)
            if self.task == 'syn':
                success = verifier.synonym()
            if self.task == 'exa':
                success = verifier.sample()
            if self.task == 'def':
                success = verifier.definition()
        except:
            success = True

        self.session_attributes = self.session_attributes
        card_title = ""
        speech_output = ""
        should_end_session = False
        if (success):

            # Set the task as completed
            if (self.task == "syn"):
                self.syn_complete = '1'
            elif (self.task == "def"):
                self.def_complete = '1'
            else:
                self.sen_complete = '1'

            # Check to see if all tasks are completed
            if (self.sen_complete == '1' and self.def_complete == '1' and self.syn_complete == '1'):
                
                #Get User data
                words = (db.getUserData(self.userId))
                # Get a new word from the database
                self.word = db.get_random_word(self.userId)
                #update user info
                #db.addUserData(self.userId, self.word)
                
                # Update the word for the session attributes
                self.session_attributes['state']['word'] = self.word

                card_title = "Tasks Complete"
                speech_output = pg.generate(self.session_attributes, 'tasks_complete')
                reprompt_text = "Is this word satisfactory?"
                                
                # Initialize the select word class
                self.session_attributes['state'] = {
                    'value': 'select_word',
                    'word' : self.word
                }
                # Dump the state to prev_state
                self.session_attributes = helper.dump_state(self.session_attributes)

            # Move on to the next task for this word
            else:

                card_title = "Next Task"
                speech_output = pg.generate(self.session_attributes, 'next_task')
                reprompt_text = "Please choose a new task for this word."
                                            
                # Assign the next state
                self.session_attributes['state'] = {
                    'value': 'select_task',
                    'word' : self.word,
                    'sen'  : self.sen_complete,
                    'dfn'  : self.def_complete,
                    'syn'  : self.syn_complete
                }
                # Dump the state to prev_state
                self.session_attributes = helper.dump_state(self.session_attributes)

        # Prompt the user to try again
        else:
            card_title    = "Try Again"
            speech_output = pg.generate(self.session_attributes, 'try_again')
            reprompt_text = "Would you like to try again?"
            
            # Assign the next state            
            self.session_attributes['state'] = {
                'value': 'try_again',
                'task' : self.task,
                'word' : self.word,
                'sen'  : self.sen_complete,
                'dfn'  : self.def_complete,
                'syn'  : self.syn_complete
            }
            # Dump the state to prev_state
            self.session_attributes = helper.dump_state(self.session_attributes)

        # Return
        return helper.build_response(self.session_attributes, helper.build_speechlet_response(
            card_title, speech_output, reprompt_text, should_end_session))