-
Notifications
You must be signed in to change notification settings - Fork 9
/
AIMLBayes.py
65 lines (52 loc) · 1.38 KB
/
AIMLBayes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
from reverend.thomas import Bayes
class AIMLBayes(Bayes):
"""
Just a wrapper around the Reverend Bayes parser.
Duncan Gough 13/03/04
- Updated to create a Bayes file if one doesn't exist at startup.
Duncan Gough 11/01/09
"""
def __init__(self,name):
Bayes.__init__(self)
self.brain = name + '.bay'
try:
Bayes.load(self,self.brain)
print "[Bayes] Brain loaded ok"
except:
print "[Alert] Failed to load bayesian brain - %s, creating it now" % self.brain
Bayes.save(self,self.brain)
Bayes.load(self,self.brain)
def train(self,bucket,words):
"""
Nominate a bucket to which the words apply, and train accordingly
"""
if bucket != "" and words != "":
try:
Bayes.train(self,bucket,words)
Bayes.save(self,self.brain)
except:
print "Failed to learn"
else:
return None
def untrain(self,bucket,words):
"""
Remove nominated words from the relevant bucket
"""
Bayes.untrain(self,bucket,words)
Bayes.save(self,self.brain)
def guess(self,line):
"""
Guess what category these words apply to
"""
#print Bayes.guess(self,line)
return Bayes.guess(self,line)
def forget(self):
pass
def save(self):
"""
Save the brain to disk
"""
Bayes.save(self,self.brain)
if __name__ == "__main__":
AIMLBayes()