def determine_action_confidence( self, param_dict ):
        # determine the action code in question
        action_code = self.determine_action_code( param_dict['feature_set'] )


        # This uses the adaboost_score
        pomdp_dict = self.determine_pomdp_dict( action_code, param_dict,
                                                    use_confidence_scores=True )

        # Include the belief vector in the action_dict also
        action_dict = \
            tbh_action_dict_manager.process_code( \
            self.machine_action, \
                skype_contacts_dict=self.skype_contacts_dict )

        action_dict['pomdp_dict'] = pomdp_dict
        
        return action_dict    
    def determine_action( self, feature_set, use_confidence_scores=False ):

        # Here, we need to use the confidence scores also
        if use_confidence_scores == False:
            action_code = self.determine_action_code( feature_set )

            pomdp_dict = self.determine_pomdp_dict( action_code, \
                                                    use_confidence_scores=False )
        else:
            # We are using the confidence scores
            # determine the main goal that will potentially receive most of the probability mass
            action_code = self.determine_action_code( feature_set )


            # determine the probability to assign to this

        """
        if use_confidence_scores == False:
            action_code = self.determine_action_code( feature_set )

            # note that self.machine_action gets set here
            pomdp_dict = self.determine_pomdp_dict( action_code, \
                                                        use_confidence_scores=False )
        else:
            # feature_set is actually a feature_set_list
            action_code_list = []
            for item in feature_set:
                action_code = self.determine_action_code( item  )
                action_code_list.append( action_code )

            # determine the self.machine_action
            pomdp_dict = self.determine_pomdp_dict( action_code_list, \
                                                        use_confidence_scores=True )
        """
        # Include the belief vector in the action_dict also

        action_dict = \
            tbh_action_dict_manager.process_code( \
            self.machine_action, \
                skype_contacts_dict=self.skype_contacts_dict )

        action_dict['pomdp_dict'] = pomdp_dict

        return action_dict
Ejemplo n.º 3
0
    def determine_action( self, feature_set, use_confidence_scores=False ):

        if use_confidence_scores == False:
            action_code = self.determine_action_code( feature_set )

            # note that self.machine_action gets set here
            pomdp_dict = self.determine_pomdp_dict( action_code, \
                                                        use_confidence_scores=False )
        else:
            # feature_set is actually a feature_set_list
            action_code_list = []
            for item in feature_set:
                action_code = self.determine_action_code( item  )
                action_code_list.append( action_code )

            # determine the self.machine_action
            pomdp_dict = self.determine_pomdp_dict( action_code_list, \
                                                        use_confidence_scores=True )

        # Include the belief vector in the action_dict also



        action_dict = \
            tbh_action_dict_manager.process_code( \
            self.machine_action, \
                skype_contacts_dict=self.skype_contacts_dict )

        action_dict['pomdp_dict'] = pomdp_dict





        

        return action_dict
Ejemplo n.º 4
0
    def determine_action( self, feature_set ):
        action_code = [ 'null', [ 'no_record' ] ]

        # --- CUSTOM TO YOUR DM --- #
        # Fill in code to do convert the features into action codes,
        # where an action code consists of two strings: an action type
        # and an input parameter

        #### Acting on the Feature Set ####
        # Does the input text start with relevant phrase?
        # (i.e. "chair") -- else we should ignore the input
        if self.system_state == 'attentive':
            ignore_input = False
        else:
            ignore_input = ( feature_set['tbh_first_word']['found_word'] == False )

        # If we've got invalid input, don't store it, possibly ask for
        # the keyword to be said
        if ignore_input == True:
            if self.system_state != 'sleeping':
                action_code = [ 'system' , [ 'request_keyword' ] ]
     
        # If the keyword is detected, then we can go through the
        # action decision process, starting with getting the action
        # code (set of numbers)
        else:
                      
            # The only command that will trigger anything while the
            # system is sleeping is if the command is to wake up the
            # system
            if self.system_state == 'sleeping':
                if feature_set['tbh_keyword_sequence']['wake_up'] or \
                        feature_set['tbh_keyword_sequence']['good_day']:
                    action_code = [ 'system' , [ 'wake_up' ] ]
                else:
                    action_code = [ 'null', [ 'yes_record' ] ]
              
            # If the system is awake or attentive, consider actions
            else:                
                # Consider each of the possible actions Note: the
                # else-if structure means that only one action code is
                # possible in this current dialog manager

                #for item in feature_set['tbh_keyword_sequence'].keys():
                #    print item, feature_set['tbh_keyword_sequence'][item]
        
                ## SYSTEM COMMANDS
                if feature_set['tbh_keyword_sequence']['wake_up'] or \
                        feature_set['tbh_keyword_sequence']['good_day']:
                    action_code = [ 'system', [ 'wake_up' ] ]
                elif feature_set['tbh_keyword_sequence']['go_to_sleep'] or \
                        feature_set['tbh_keyword_sequence']['good_night']:
                    action_code = [ 'system', [ 'go_to_sleep' ] ]
                elif feature_set['tbh_keyword_sequence']['listen_up'] or \
                        feature_set['tbh_keyword_sequence']['enter_attentive_mode']:
                    action_code = [ 'system', [ 'enter_attentive_mode' ] ]
                elif feature_set['tbh_keyword_sequence']["that's_all"] or \
                        feature_set['tbh_keyword_sequence']['exit_attentive_mode']:
                    action_code = [ 'system', [ 'exit_attentive_mode' ] ]
                

                ## CONFIRMATORY (YES/NO)
                elif self.confirmation_buffer != None and \
                        ( feature_set['tbh_keyword']['yes'] or \
                        feature_set['tbh_keyword']['yeah'] or \
                        feature_set['tbh_keyword']['confirming'] ):
                    if self.confirmation_buffer != None:
                        action_code = self.confirmation_buffer
                        self.confirmation_buffer = None
                    else:
                        action_code = [ 'null', [ 'yes_record' ] ]

                    self.system_state = 'awake'

                    #action_code = [ 'confirmatory', [ 'yes' ] ]
                 
                elif self.confirmation_buffer != None and ( feature_set['tbh_keyword']['no'] or \
                        feature_set['tbh_keyword']['nope'] ):
                    self.confirmation_buffer = None
                    action_code = [ 'system', [ 'wake_up' ] ]
                    self.system_state = 'awake'


                else:
                    self.confirmation_buffer = None
                    self.system_state = 'awake'

                    environmental_control_detected = False
                    # Environmental control commands                  
                    for key in feature_set['tbh_environmental_control_keyword'].keys():
                        print key
                        if feature_set['tbh_environmental_control_keyword'][key]:
                            action_code = [ 'environmental_control', [ key ] ]
                            environmental_control_detected = True
                        else:
                            pass
                        
                    if environmental_control_detected:
                        pass

                    ## VOICE SYNTHESIZER COMMANDS             
                    elif feature_set['tbh_keyword_sequence']['audio_on'] or \
                            feature_set['tbh_keyword_sequence']['voice_on']:
                        action_code = [ 'voice_synthesizer', [ 'audio_on' ] ]
                    elif feature_set['tbh_keyword_sequence']['audio_off'] or \
                            feature_set['tbh_keyword_sequence']['voice_off']:
                        action_code = [ 'voice_synthesizer', [ 'audio_off' ] ]
                    elif feature_set['tbh_keyword']['interrupt'] or \
                            feature_set['tbh_keyword_sequence']['be_quiet']:
                        action_code = [ 'voice_synthesizer', [ 'interrupt' ] ]
                    elif feature_set['tbh_keyword_sequence']['speak_it'] or \
                            feature_set['tbh_keyword_sequence']['say_it'] or \
                            feature_set['tbh_keyword_sequence']['speak_text_on_screen'] or \
                            feature_set['tbh_keyword_sequence']['say_text_on_screen'] or \
                            ( feature_set['tbh_keyword']['say'] and \
                                  feature_set['tbh_keyword']['again'] ):
                        action_code = [ 'voice_synthesizer', [ 'speak_text_on_screen' ] ]




                    ## ACTIVITIES
                    elif feature_set['tbh_keyword']['activity'] or \
                            feature_set['tbh_keyword']['activities'] or \
                            feature_set['tbh_keyword']['schedule'] or \
                            feature_set['tbh_keyword']['events']:

                        # Determine which day of the week
                        day = self.determine_day( feature_set )
                        action_code = [ 'activities', [ day ] ]

                    ## MEALS
                    elif feature_set['tbh_keyword']['breakfast']:
                        day = self.determine_day( feature_set )
                        action_code = ['breakfast', [ day ] ]

                    elif feature_set['tbh_keyword']['lunch']:
                        day = self.determine_day( feature_set )
                        action_code = ['lunch', [ day ] ]

                    elif feature_set['tbh_keyword']['dinner'] or feature_set['tbh_keyword']['supper']:
                        day = self.determine_day( feature_set )
                        action_code = [ 'dinner', [ day ] ]

                    # Note that the search for "menus" comes after
                    # 'breakfast', 'lunch', 'dinner' or 'supper'; this
                    # means that none of those keywords appeared, and that
                    # the user wants "general" menus
                    elif feature_set['tbh_keyword']['menus'] or \
                            feature_set['tbh_keyword']['menu']:
                        day = self.determine_day( feature_set )
                        action_code = [ 'menus', [ day ] ]


                    ## WEATHER
                    elif feature_set['tbh_keyword']['weather'] or \
                            feature_set['tbh_keyword']['forecast'] or \
                            feature_set['tbh_keyword']['temperature']:                        
                        if feature_set['tbh_keyword_sequence']['three_day'] or \
                                feature_set['tbh_keyword_sequence']['four_day']:
                            parameter = 'three_day'
                        else:
                            parameter = self.determine_day( feature_set )
                        action_code = [ 'weather', [ parameter ] ]

                    ## TIME/DATE
                    elif feature_set['tbh_keyword']['time']:
                        action_code = [ 'time', [ 'time' ] ]

                    elif feature_set['tbh_keyword']['date'] or \
                            feature_set['tbh_keyword']['day']:
                        action_code = [ 'time', [ 'date' ] ]                

                    # SKYPE PHONE OPERATIONS
                    elif feature_set['tbh_keyword_sequence']['make_phone_call'] or \
                            feature_set['tbh_keyword_sequence']['make_a_phone_call']:
                        action_code = [ 'phone', [ 'make_phone_call' ] ]

                    elif feature_set['tbh_keyword_sequence']['resume_call'] or \
                            feature_set['tbh_keyword']['resume']:
                        action_code = [ 'phone', [ 'resume_call' ] ]

                    elif feature_set['tbh_keyword_sequence']['answer_phone'] or \
                            feature_set['tbh_keyword']['answer']:
                        action_code = [ 'phone', [ 'answer_phone' ] ]

                    elif feature_set['tbh_keyword']['extension'] and \
                            ( feature_set['tbh_keyword']['dial'] or \
                                  feature_set['tbh_keyword']['call'] ):
                        action_code = [ 'phone', [ 'dial_extension']  ]

                    elif feature_set['tbh_keyword_sequence']['who_can_i_talk_to'] or \
                            feature_set['tbh_keyword_sequence']['whom_can_i_talk_to'] or \
                            feature_set['tbh_keyword_sequence']['show_phone_list'] or \
                            feature_set['tbh_keyword_sequence']['show_contacts']:
                        action_code = [ 'phone', [ 'show_contacts' ] ]

                    elif feature_set['tbh_keyword']['hold'] and \
                            feature_set['tbh_keyword']['call']:
                        action_code = [ 'phone', [ 'hold_call' ] ]

                    elif feature_set['tbh_keyword_sequence']['hang_up'] or \
                            feature_set['tbh_keyword_sequence']['end_call']:
                        self.confirmation_buffer = [ 'phone', [ 'hang_up' ] ]
                        self.system_state = 'attentive'
                        action_code = [ 'system', [ 'request_confirmation', 'hang_up' ] ]

                    elif feature_set['tbh_keyword_sequence']['full_screen_video'] or \
                            feature_set['tbh_keyword_sequence']['maximize_video']:
                        action_code = [ 'phone', [ 'fullscreen_video'] ]
                    elif feature_set['tbh_keyword_sequence']['minimize_video']:
                        action_code = [ 'phone', ['unfullscreen_video'] ]

                    elif feature_set['tbh_keyword_sequence']['next_page']:
                        action_code = [ 'phone', [ 'next_page' ] ]
                    ## VOICE DIAL
                    elif feature_set['tbh_keyword']['cancel'] or \
                            feature_set['tbh_keyword']['exit']:
                        action_code = [ 'voice_dial', [ 'cancel' ] ]

                    elif feature_set['tbh_keyword']['dial'] and \
                            feature_set['tbh_keyword']['number']:
                        action_code = [ 'voice_dial', [ 'dial_number' ] ]

                    elif feature_set['tbh_keyword']['finished']:
                        action_code = [ 'voice_dial', [ 'finished' ] ]

                    elif feature_set['tbh_keyword']['restart'] or \
                            feature_set['tbh_keyword_sequence']['start_over'] or \
                            feature_set['tbh_keyword_sequence']['start_again']:
                        action_code = [ 'voice_dial', [ 'start_over' ] ]


                    ## CALL CONTACT
                    # Note that the search for 'call' comes after the phone call commands
                    elif feature_set['tbh_keyword']['call']:                    
                        contact = self.determine_user_specific_contact( feature_set )
                        if contact != 'unknown':
                            self.confirmation_buffer = [ 'call_contact', [ contact ] ]
                            action_code = [ 'system', \
                                                ['request_confirmation', \
                                                     'call_contact', contact ] ]
                        else:
                            action_code = [ 'call_contact', 'unknown' ]

                        self.system_state = 'attentive'


                    elif feature_set['tbh_keyword']['cancel']:
                        action_code = ['system', ['wake_up'] ]




                    # DIGITS
                    elif feature_set['tbh_keyword']['one'] or \
                            feature_set['tbh_keyword']['two'] or \
                            feature_set['tbh_keyword']['three'] or \
                            feature_set['tbh_keyword']['four'] or \
                            feature_set['tbh_keyword']['five'] or \
                            feature_set['tbh_keyword']['six'] or \
                            feature_set['tbh_keyword']['seven'] or \
                            feature_set['tbh_keyword']['eight'] or \
                            feature_set['tbh_keyword']['nine'] or \
                            feature_set['tbh_keyword']['oh'] or \
                            feature_set['tbh_keyword']['zero']:
                        # pass the entire string so that it can be dialed
                        action_code = [ 'digits', [ feature_set['tbh_digits']['digits'] ] ]

                    # NO ACTION
                    # Did not parse successfully
                    else:
                        action_code = [ 'null', [ 'yes_record' ] ]

            # convert the action code into a dictionary of specific
            # actions, add the action code to set of action codes if new            

        # comment back in 
        #existing_code = tbh_action_code_manager.verify_action_code( action_code ) 
        #if not existing_code: 
        #    tbh_action_code_manager.add_action_code( action_code )
        

        print action_code

        action_dict = \
            tbh_action_dict_manager.process_code( \
            action_code, \
                skype_contacts_dict=self.skype_contacts_dict )

        #print action_dict

        return action_dict