dr.botzo/dr_botzo/markov/models.py

73 lines
1.7 KiB
Python

"""
markov/models.py --- save brain pieces for chaining
"""
import logging
from django.db import models
log = logging.getLogger('dr_botzo.markov')
class MarkovContext(models.Model):
"""Define contexts for Markov chains."""
name = models.CharField(max_length=200, unique=True)
def __unicode__(self):
"""String representation."""
return u"{0:s}".format(self.name)
class MarkovTarget(models.Model):
"""Define IRC targets that relate to a context, and can occasionally be talked to."""
name = models.CharField(max_length=200, unique=True)
context = models.ForeignKey(MarkovContext)
chatter_chance = models.IntegerField(default=0)
def __unicode__(self):
"""String representation."""
return u"{0:s}".format(self.name)
class MarkovState(models.Model):
"""One element in a Markov chain, some text or something."""
_start1 = '__start1'
_start2 = '__start2'
_stop = '__stop'
k1 = models.CharField(max_length=128)
k2 = models.CharField(max_length=128)
v = models.CharField(max_length=128)
count = models.IntegerField(default=0)
context = models.ForeignKey(MarkovContext)
class Meta:
index_together = [
['context', 'k1', 'k2'],
['context', 'v'],
]
permissions = {
('import_log_file', "Can import states from a log file"),
('teach_line', "Can teach lines"),
}
unique_together = ('context', 'k1', 'k2', 'v')
def __unicode__(self):
"""String representation."""
return u"{0:s},{1:s} -> {2:s} (count: {3:d})".format(self.k1, self.k2, self.v, self.count)
# vi:tabstop=4:expandtab:autoindent