Markov: make some attempt to avoid name: chains

there are a lot of these, so it's a hard problem to solve entirely, but
this will avoided some cases at least
This commit is contained in:
Brian S. Stephan 2013-02-15 10:24:45 -06:00
parent 6a12763c81
commit 7322ebde8f
1 changed files with 11 additions and 4 deletions

View File

@ -449,8 +449,8 @@ class Markov(Module):
new_sentence = self._create_chain_with_k1_k2(self.start1,
self.start2,
3,
context_id)
3, context_id,
avoid_address=True)
if len(new_sentence) > 0:
self.log.debug("started new sentence "
@ -587,7 +587,8 @@ class Markov(Module):
raise
finally: cur.close()
def _create_chain_with_k1_k2(self, k1, k2, length, context_id):
def _create_chain_with_k1_k2(self, k1, k2, length, context_id,
avoid_address=False):
"""Create a chain of the given length, using k1,k2.
k1,k2 does not appear in the resulting chain.
@ -604,7 +605,13 @@ class Markov(Module):
if v:
chain.append(v)
return chain[2:]
# check for addresses (the "whoever:" in
# __start1 __start2 whoever: some words)
addressing_suffixes = [':', ',']
if chain[2][-1] in addressing_suffixes and avoid_address:
return chain[3:]
else:
return chain[2:]
def _get_chatter_targets(self):
"""Get all possible chatter targets."""