2014-04-05 10:52:29 -05:00
|
|
|
"""
|
|
|
|
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."""
|
|
|
|
|
2015-05-15 08:32:03 -05:00
|
|
|
name = models.CharField(max_length=200, unique=True)
|
2014-04-05 10:52:29 -05:00
|
|
|
|
|
|
|
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."""
|
|
|
|
|
2015-05-15 08:32:03 -05:00
|
|
|
name = models.CharField(max_length=200, unique=True)
|
2014-04-05 10:52:29 -05:00
|
|
|
context = models.ForeignKey(MarkovContext)
|
|
|
|
|
|
|
|
chatter_chance = models.IntegerField(default=0)
|
|
|
|
|
2014-04-05 15:55:06 -05:00
|
|
|
def __unicode__(self):
|
|
|
|
"""String representation."""
|
|
|
|
|
|
|
|
return u"{0:s}".format(self.name)
|
|
|
|
|
2014-04-05 10:52:29 -05:00
|
|
|
|
|
|
|
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:
|
2014-04-05 23:09:50 -05:00
|
|
|
index_together = [
|
|
|
|
['context', 'k1', 'k2'],
|
|
|
|
['context', 'v'],
|
|
|
|
]
|
2014-04-05 11:20:59 -05:00
|
|
|
permissions = {
|
|
|
|
('import_log_file', "Can import states from a log file"),
|
2014-04-05 14:53:05 -05:00
|
|
|
('teach_line', "Can teach lines"),
|
2014-04-05 11:20:59 -05:00
|
|
|
}
|
2014-04-05 10:52:29 -05:00
|
|
|
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
|