- Timestamp:
- 03/14/09 11:23:38 (3 years ago)
- Files:
-
- imbot/MessageQueue.py (modified) (2 diffs)
- imbot/SABBrain.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
imbot/MessageQueue.py
r114 r118 154 154 155 155 def smiley_to_code(self, text): 156 ''' Converts smileys :-) to codes SMILE1'''156 ''' Converts smileys :-) to codes 01SMILE ''' 157 157 for smiley, code in self.smiley_codes.items(): 158 158 text = re.sub(re.escape(smiley), code, text) … … 160 160 161 161 def code_to_smiley(self, text): 162 ''' Converts codes SMILE1to smileys :-) '''162 ''' Converts codes 01SMILE to smileys :-) ''' 163 163 for smiley, code in self.smiley_codes.items(): 164 164 text = re.sub(re.escape(code), smiley, text) imbot/SABBrain.py
r116 r118 66 66 67 67 # 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() 68 70 self.their_history = dict() 69 71 self.our_history = dict() 70 self.history_length = 572 self.history_length = 7 71 73 self.history_weight = 0.0 72 74 for i in range(1, self.history_length+1): … … 234 236 ''' Appends 'sentence' to their_name's history ''' 235 237 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 236 246 237 247 self.pronoun_handlers.add_to_history(sentence, their_name) … … 359 369 360 370 # give every sentence a weight 371 all_repeat_replies = True 372 contains_repeat = False 361 373 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() 364 398 365 399 # narrow our choices down to just the best sentences … … 556 590 if len(reply_choices) == 0: 557 591 if len(questions) == 0 and len(statements) == 0: 558 return [("lol", 'VPB')]# we're speechless592 return "tell me something new" # we're speechless 559 593 elif len(questions) == 0: 560 594 return choice(statements) … … 620 654 space = '' if group[i_tag] in ['.', ',', '(', '{', '['] or '\'' in group[i_word] else ' ' 621 655 except: 622 print "group:", group656 #print "group:", group 623 657 space = '' 624 658 reply_plaintext += '%s%s' % (space, group[i_word])
