コード例 #1
0
 def intent_repeat_value_field(self):
     """we select the number and type of slots and we select a sentence 
     from the corresponding file in the database 
     there are 3 cases: 0- zero, 1- one_name, 2- two_names"""
     try:
         length = len(self.text_fields)
         if length >= 2:
             upper = 2
         else:
             upper = 1
         number = randint(0, upper)
         if number == 0:
             answer = self.get_interaction_message(cts.repeat_value_field,
                                                   ifk.zero)
         elif number == 1:
             field = gen.get_random_value(self.text_fields)
             sentence = self.get_interaction_message(
                 cts.repeat_value_field, ifk.one_name)
             answer = sentence.format(field)
         else:
             # 2, two_names
             fields = gen.get_random_value(self.text_fields, number=2)
             sentence = self.get_interaction_message(
                 cts.repeat_value_field, ifk.two_names)
             answer = sentence.format(fields[0], fields[1])
         return answer
     except:
         print(
             'Fail in finding a message to ask to repeat the value of a field'
         )
         raise Exception
コード例 #2
0
 def intent_spelling(self):
     # we have two cases, when the spelling did not start already and when the spelling already started
     try:
         value_type = self.dialogue_state[u.value_type]
         field = self.dialogue_state[u.slot_name].lower()
         if self.spelling_string == '':
             # we are not in a choice, we should look if it is date, time, address not email, name, country, city
             value = self.get_not_choice_value(value_type, field)
             self.spelling_string = value
             self.spelling_string_index = -1
             print(f'[User - Input to be inserted by spelling: {value}]')
         # we update first the spelling data and then we analyze the char
         self.spelling_string_index += 1
         if self.spelling_string_index >= len(self.spelling_string):
             self.reset_spelling_data()
             char = gen.get_random_value(u.terminator)
             return char
         char = self.spelling_string[self.spelling_string_index]
         # now we analyze the char, mainly the special characters
         if char in u.spec_char_symbol:
             index = u.spec_char_symbol.index(char)
             char = u.special_characters[index]
         return char
     except:
         print('Fail in finding a message to spell a field')
         raise Exception
コード例 #3
0
 def get_filling_message(self, file_name):
     # For the moment all the filling elements are lists
     try:
         elements = self.data[cts.filling][file_name]
         element = gen.get_random_value(elements)
         return element
     except:
         print(f'Fail to get a filling message')
         raise Exception
コード例 #4
0
 def intent_explain_field(self):
     # we select a sentence from the corresponding file in the database
     try:
         field = gen.get_random_value(self.text_fields)
         sentence = self.get_interaction_message(cts.explain_field)
         answer = sentence.format(field)
         return answer
     except:
         print(
             'Fail to extract a sentence to ask an explanation about a field'
         )
         raise Exception
コード例 #5
0
 def get_interaction_message(self, file_name, key=''):
     # when key is not void, the file contains a dictionary and we should go to the corresponding
     # key. when key is void, the file contains a list. The file_name here is without extension
     try:
         if u.DEBUG:
             print(f'file_name: {file_name}')
         if key != '':
             elements = self.data[cts.interaction][file_name][key]
         else:
             elements = self.data[cts.interaction][file_name]
         element = gen.get_random_value(elements)
         return element
     except:
         print(f'Fail to get an interaction message')
         raise Exception
コード例 #6
0
 def intent_complete_field(self):
     # we have mainly two cases, when the type is choice and when the type is not a choice
     try:
         value_type = self.dialogue_state[u.value_type]
         value_name = self.dialogue_state[u.value_name]
         field = self.dialogue_state[u.slot_name].lower()
         if value_type in u.choices_type_list:
             choice_list = self.choices_lists[value_name]
             if value_type == u.checkbox:
                 """value type is checbox so we can have more than one choice, for the simulation the maximum is two
                 we have 5 cases: 0- value, 1- name_value, 2- value_name, 3- two_values, 4- name_value_value.
                 The first 3 are linked to the fact that we decide to choose only one value, so identical to radio 
                 and dropdown. the last two are related to the selection of two values"""
                 number = randint(0, 4)
                 if number in range(3, 5):
                     # 3 or 4
                     values = gen.get_random_value(choice_list, number=2)
                     if number == 3:
                         # two_values
                         file_key = ifk.two_values
                         sentence = self.get_interaction_message(
                             cts.complete_field, file_key)
                         answer = sentence.format(values[0], values[1])
                     else:
                         # 4, name_value_value
                         file_key = ifk.name_value_value
                         sentence = self.get_interaction_message(
                             cts.complete_field, file_key)
                         answer = sentence.format(field, values[0],
                                                  values[1])
                     return answer
             # 0, 1, 2 of the checkbox + dropdown + radio
             # we have only one choice
             value = gen.get_random_value(choice_list)
             # we select a sentence with one slot name or two slots (one name one value)
             # so in total three cases: 0 - value, 1 - value_name, 2 - name_value
             number = randint(0, 2)
             if number == 0:
                 # one value
                 file_key = ifk.one_name
                 sentence = self.get_interaction_message(
                     cts.complete_field, file_key)
                 answer = sentence.format(value)
             elif number == 1:
                 # value_name
                 file_key = ifk.value_name
                 sentence = self.get_interaction_message(
                     cts.complete_field, file_key)
                 answer = sentence.format(value, field)
             else:
                 # 2, name_value
                 file_key = ifk.name_value
                 sentence = self.get_interaction_message(
                     cts.complete_field, file_key)
                 answer = sentence.format(field, value)
             return answer
         # we are not in a choice, we should look if it is date, time, address not email, name, country, city
         value = self.get_not_choice_value(value_type, field)
         # we select a sentence with one slot name or two slots (one name one value)
         # so in total three cases: 0 - value, 1 - value_name, 2 - name_value
         number = randint(0, 2)
         if number == 0:
             # one_value
             file_key = ifk.one_value
             sentence = self.get_interaction_message(
                 cts.complete_field, file_key)
             answer = sentence.format(value)
         elif number == 1:
             # value_name
             file_key = ifk.value_name
             sentence = self.get_interaction_message(
                 cts.complete_field, file_key)
             answer = sentence.format(value, field)
         else:
             # 2, name_value
             file_key = ifk.name_value
             sentence = self.get_interaction_message(
                 cts.complete_field, file_key)
             answer = sentence.format(field, value)
         return answer
     except:
         if self.dialogue_state[u.slot_name] is not None:
             print('Fail in finding a message to ask to complete a field')
         raise Exception