Ejemplo n.º 1
0
def generate_places():
    streets = file_to_list('street')
    cities = file_to_list('city')
    cities.extend(file_to_list('borough'))
    states = file_to_list('state')
    
    num = len(streets)
    city_num = sample_from_list(cities, num, True)
    state_num = sample_from_list(states, num, True)
    final = [s + '\t' + c + '\t'+ st for s, c, st in zip(streets, city_num, state_num)]
    pdb.set_trace()
    list_to_file(final, 'places.txt')
Ejemplo n.º 2
0
 def _get_random_slot_value(self, slot):
     '''Get a random value for the given slot.'''
     values = []
     tables_fields = self._get_slot_mapping(slot)
     for tbf in tables_fields:#sample a value of each table which the slot is connected
         if iscallable(tbf):#slot have values generated dynamic from one or several funs
             v = sample_from_list(tbf(self.goal, slot))
             values.append(v)
         else:  
             tb, f = tbf
             row = self._get_random_row(tb)
             values.append(self.db.get_row_field_value(tb, row, f))
     return sample_from_list(values)#take one in the sampled values
Ejemplo n.º 3
0
def test_random_dialogues(user):
    metadata = get_metadata()
    for i in range(100):
        print '=======================Dialogue %i============================'%(i+1)
        user.new_dialogue()
        print 'Goal:', user.goal
        print '-'*60
        goal_des = metadata['goals'][user.goal['task']]
        ordered_acts = goal_des['acts']
        slots = goal_des['slots']
        for acts in ordered_acts:
            da = DialogueAct()
            for act in acts.split('&'):
                act_des = metadata['act_definitions'][act]
                slot = None
                if act_des['slot_included']:
                    slot = sample_from_list(slots)
                value = None
                if act_des['value_included']:
                    if slot not in user.goal.keys():
                        for s in get_equivalent_slots(goal_des, slot):
                            if s in user.goal.keys():
                                slot = s
                                break
                    if slot in user.goal.keys():
                        if sample_a_prob(0.5):
                            value = user.goal[slot]
                        else:
                            value = 'lct'
                    else:
                        value = 'lct'

                item = DialogueActItem(act, slot, value)
                da.append(item)
            print 'sys_da:\t\t', da
            user.da_in(da)
            da = user.da_out()
            print 'user_da:\t', da[0]
            if len(da[0])==0:
                raise RuntimeError('User simulator doesnt reply anything!!')
                pdb.set_trace()
Ejemplo n.º 4
0
    def infer_info(self, goal):
        ds = None
        accepted_slots = None
        self.goal = copy.deepcopy(goal)

        # retrieve the slot variables
        from_city_val = self.get_accepted_mpv(ds, 'from_city', accepted_slots)
        from_borough_val = self.get_accepted_mpv(ds, 'from_borough', accepted_slots)
        from_stop_val = self.get_accepted_mpv(ds, 'from_stop', accepted_slots)
        from_street_val = self.get_accepted_mpv(ds, 'from_street', accepted_slots)
        from_street2_val = self.get_accepted_mpv(ds, 'from_street2', accepted_slots)
        to_city_val = self.get_accepted_mpv(ds, 'to_city', accepted_slots)
        to_borough_val = self.get_accepted_mpv(ds, 'to_borough', accepted_slots)
        to_stop_val = self.get_accepted_mpv(ds, 'to_stop', accepted_slots)
        to_street_val = self.get_accepted_mpv(ds, 'to_street', accepted_slots)
        to_street2_val = self.get_accepted_mpv(ds, 'to_street2', accepted_slots)
        vehicle_val = self.get_accepted_mpv(ds, 'vehicle', accepted_slots)
        max_transfers_val = self.get_accepted_mpv(ds, 'num_transfers', accepted_slots)

        # infer cities based on stops
        from_cities, to_cities = None, None
        if from_stop_val != 'none' and from_city_val == 'none':
            from_cities = self.ontology.get_compatible_vals('stop_city', from_stop_val)
            if len(from_cities) == 1:
                from_city_val = from_cities.pop()
            elif len(from_cities)>1:
                from_city_val = sample_from_list(from_cities)
            #if from_city_val != 'none':
                self.goal['from_city']= from_city_val

        if to_stop_val != 'none' and to_city_val == 'none':
            to_cities = self.ontology.get_compatible_vals('stop_city', to_stop_val)
            if len(to_cities) == 1:
                to_city_val = to_cities.pop()
            elif len(to_cities)>1:
                to_city_val = sample_from_list(to_cities)
            #if to_city_val != 'none':
                self.goal['to_city']= to_city_val

        # infer cities based on street
        from_cities_st, to_cities_st = None, None
        if from_street_val != 'none' and from_city_val == 'none':
            from_cities_st = self.ontology.get_compatible_vals('street_city', from_street_val)
            if len(from_cities_st) == 1:
                from_city_val = from_cities_st.pop()
            elif len(from_cities_st)>1:
                from_city_val = sample_from_list(from_cities_st)
            #if from_city_val != 'none':
                self.goal['from_city']= from_city_val

        if to_street_val != 'none' and to_city_val == 'none':
            to_cities_st = self.ontology.get_compatible_vals('street_city', to_stop_val)
            if len(to_cities_st) == 1:
                to_city_val = to_cities_st.pop()
            elif len(to_cities_st)>1:
                to_city_val = sample_from_list(to_cities_st)
            #if to_city_val != 'none':
                self.goal['to_city']= to_city_val

        # infer boroughs based on stops
        from_boroughs, to_boroughs = None, None
        if from_stop_val != 'none' and from_borough_val == 'none':
            from_boroughs = self.ontology.get_compatible_vals('stop_borough', from_stop_val)
            if len(from_boroughs) == 1:
                from_borough_val = from_boroughs.pop()
            elif len(from_boroughs)>1:
                from_borough_val = sample_from_list(from_boroughs)
            #if from_borough_val != 'none':
                self.goal['from_borough']= from_borough_val

        if to_stop_val != 'none' and to_borough_val == 'none':
            to_boroughs = self.ontology.get_compatible_vals('stop_borough', to_stop_val)
            if len(to_boroughs) == 1:
                to_borough_val = to_boroughs.pop()
            elif len(to_boroughs)>1:
                to_borough_val = sample_from_list(to_boroughs)
            #if to_borough_val != 'none':
                self.goal['to_borough']= to_borough_val

        # infer boroughs based on streets
        from_boroughs_st, to_boroughs_st = None, None
        if to_street_val != 'none' and to_borough_val == 'none':
            to_boroughs_st = self.ontology.get_compatible_vals('street_borough', to_street_val)
            if len(to_boroughs_st) == 1:
                to_borough_val = to_boroughs_st.pop()
            elif len(to_boroughs_st)>1:
                to_borough_val = sample_from_list(to_boroughs_st)
            #if to_borough_val != 'none':
                self.goal['to_borough']= to_borough_val

        if from_street_val != 'none' and from_borough_val == 'none':
            from_boroughs_st = self.ontology.get_compatible_vals('street_borough', from_street_val)
            if len(from_boroughs_st) == 1:
                from_borough_val = from_boroughs_st.pop()
            elif len(from_boroughs_st)>1:
                from_borough_val= sample_from_list(from_boroughs_st)
            #if from_borough_val!= 'none':
                self.goal['from_borough']= from_borough_val

        '''
        #set 'none' for slot which could find info in database present I don't know
        val = 'none'
        if 'from_borough' not in self.goal and ('from_stop' in self.goal or 'from_street' in self.goal):
            self.goal['from_borough'] = val
        if 'to_borough' not in self.goal and ('to_stop' in self.goal or 'to_street' in self.goal):
            self.goal['to_borough'] = val
        if 'from_city' not in self.goal:
            self.goal['from_city'] = val
        if 'to_city' not in self.goal:
            self.goal['to_city'] = val
        '''
    
        return self.goal
Ejemplo n.º 5
0
def alternative_value_fun():
    '''A generator for a slot during conversation'''
    a = ['next', 'prev', 'last', '1', '2', '3', '4', 'next hour']
    return sample_from_list(a)