Changeset 118 for imbot

Show
Ignore:
Timestamp:
03/14/09 11:23:38 (3 years ago)
Author:
pantley2
Message:

IMBOT: still trying to prevent it from repeating itself

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • imbot/MessageQueue.py

    r114 r118  
    154154         
    155155        def smiley_to_code(self, text): 
    156                 ''' Converts smileys :-) to codes SMILE1 ''' 
     156                ''' Converts smileys :-) to codes 01SMILE ''' 
    157157                for smiley, code in self.smiley_codes.items(): 
    158158                        text = re.sub(re.escape(smiley), code, text) 
     
    160160         
    161161        def code_to_smiley(self, text): 
    162                 ''' Converts codes SMILE1 to smileys :-) ''' 
     162                ''' Converts codes 01SMILE to smileys :-) ''' 
    163163                for smiley, code in self.smiley_codes.items(): 
    164164                        text = re.sub(re.escape(code), smiley, text) 
  • imbot/SABBrain.py

    r116 r118  
    6666                 
    6767                # message history per user, where weight is the maximum weight that can be applied to any given word pair 
     68                self.forget_history_seconds = 60 
     69                self.history_last_updated = dict() 
    6870                self.their_history = dict() 
    6971                self.our_history = dict() 
    70                 self.history_length = 5 
     72                self.history_length = 7 
    7173                self.history_weight = 0.0 
    7274                for i in range(1, self.history_length+1): 
     
    234236                ''' Appends 'sentence' to their_name's history ''' 
    235237                self.log.enter(locals=locals()) 
     238                 
     239                if self.history_last_updated.has_key(their_name) and self.history_last_updated[their_name] < time(): 
     240                        print "This is the first message from %s in awhile, clearing history before replying..." % str(their_name) 
     241                        self.history_last_updated[their_name] = time() + self.forget_history_seconds 
     242                        self.their_history[their_name] = [] 
     243                        self.our_history[their_name] = [] 
     244                else: 
     245                        self.history_last_updated[their_name] = time() + self.forget_history_seconds 
    236246                 
    237247                self.pronoun_handlers.add_to_history(sentence, their_name) 
     
    359369                 
    360370                # give every sentence a weight 
     371                all_repeat_replies = True 
     372                contains_repeat = False 
    361373                for sentence in sentenceChoices: 
    362                         all_sentences[tuple(sentence)] = self.compute_sentence_weight(sentence, recipient) 
    363                         self.log.add("%f = %s" % (all_sentences[tuple(sentence)], str(sentence))) 
     374                        weight = self.compute_sentence_weight(sentence, recipient) 
     375                        all_sentences[tuple(sentence)] = weight 
     376                        self.log.add("%f = %s" % (weight, str(sentence))) 
     377                        if weight < 100: 
     378                                all_repeat_replies = False 
     379                        else: 
     380                                contains_repeat = True 
     381                 
     382                # when we have a mix of new replies and repeats 
     383                if all_repeat_replies: 
     384                        return choice(["tell me more", "teach me", "explain something new to me", "I don't know much about that. Teach me more.", 
     385                                "my small brain can't comprehend what you said yet", "can you rephrase that?", "what do you mean?"]) 
     386                elif contains_repeat: 
     387                        self.log.enter("some non-repeats and some repeats were created") 
     388                        everything = all_sentences.items() 
     389                         
     390                        # remove the repeats 
     391                        for key, value in everything: 
     392                                if value >= 100: 
     393                                        self.log.add("remove: %s" % str(key)) 
     394                                        del all_sentences[key] 
     395                                else: 
     396                                        self.log.add("keep: %s" % str(key)) 
     397                        self.log.leave() 
    364398                 
    365399                # narrow our choices down to just the best sentences 
     
    556590                if len(reply_choices) == 0: 
    557591                        if len(questions) == 0 and len(statements) == 0:                                 
    558                                 return [("lol", 'VPB')] # we're speechless 
     592                                return "tell me something new" # we're speechless 
    559593                        elif len(questions) == 0: 
    560594                                return choice(statements) 
     
    620654                                                        space = '' if group[i_tag] in ['.', ',', '(', '{', '['] or '\'' in group[i_word] else ' ' 
    621655                                                except: 
    622                                                         print "group:", group 
     656                                                        #print "group:", group 
    623657                                                        space = '' 
    624658                                                reply_plaintext += '%s%s' % (space, group[i_word])