Markov: heed k1/k2/v length limit when importing

This commit is contained in:
Brian S. Stephan 2014-04-05 11:09:03 -05:00
parent 77e52acc75
commit 399d419824
1 changed files with 4 additions and 0 deletions

View File

@ -66,6 +66,10 @@ def _learn_line(line, context):
words = line.split()
words = [MarkovState._start1, MarkovState._start2] + words + [MarkovState._stop]
for word in words:
if len(word) > MarkovState._meta.get_field('k1').max_length:
return
for i, word in enumerate(words):
log.debug("{0:s},{1:s} -> {2:s}".format(words[i], words[i+1], words[i+2]))
state, created = MarkovState.objects.get_or_create(context=context,