functional
This commit is contained in:
parent
555efcf586
commit
e17c76a8be
3 changed files with 46 additions and 3 deletions
2
bot.py
2
bot.py
|
@ -37,7 +37,7 @@ class Oven(pydle.Client):
|
||||||
async def on_message(self, chan, source, msg):
|
async def on_message(self, chan, source, msg):
|
||||||
if source != self.nickname:
|
if source != self.nickname:
|
||||||
if msg == '!botlist':
|
if msg == '!botlist':
|
||||||
await self.message(chan, 'dah helooooooo i am kim jong un, pingus me to have a nice conversation')
|
await self.message(chan, 'dah helooooooo i am kim jong un, pingus me to have a nice conversation with llckthecheese')
|
||||||
for i in self.raw:
|
for i in self.raw:
|
||||||
await self.raw[i](self, chan,source,msg)
|
await self.raw[i](self, chan,source,msg)
|
||||||
if msg[:len(self.prefix)] == self.prefix:
|
if msg[:len(self.prefix)] == self.prefix:
|
||||||
|
|
BIN
modules/__pycache__/nlp.cpython-36.pyc
Normal file
BIN
modules/__pycache__/nlp.cpython-36.pyc
Normal file
Binary file not shown.
|
@ -2,11 +2,54 @@
|
||||||
import dataset
|
import dataset
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
async def rec(self, m):
|
||||||
|
prew = self.db['prew']
|
||||||
|
noch = self.db['noun']
|
||||||
|
beg = self.db['beg']
|
||||||
|
end = self.db['end']
|
||||||
|
pre = ''
|
||||||
|
words = m.split(' ')
|
||||||
|
for w in words:
|
||||||
|
if pre == '':
|
||||||
|
beg.insert(dict(word=w))
|
||||||
|
else:
|
||||||
|
prew.insert(dict(pre=pre, pro=w))
|
||||||
|
pre = w
|
||||||
|
noch.insert(dict(word=w))
|
||||||
|
end.insert(dict(word=pre))
|
||||||
|
|
||||||
|
async def getNoun(self, words):
|
||||||
|
nouns = [i['word'] for i in self.db['noun'].find()]
|
||||||
|
out = {}
|
||||||
|
for i in words:
|
||||||
|
out[i] = nouns.count(i)
|
||||||
|
return min(out, key=out.get)
|
||||||
|
|
||||||
|
async def genOut(self, noun):
|
||||||
|
prew = self.db['prew']
|
||||||
|
beg = [ i['word'] for i in self.db['beg'].find() ]
|
||||||
|
end = [ i['word'] for i in self.db['end'].find() ]
|
||||||
|
iter=0
|
||||||
|
out = [noun]
|
||||||
|
while out[0] not in beg and iter < 7:
|
||||||
|
out = [ random.choice(list(prew.find(pro=out[0])))['pre'] ] + out
|
||||||
|
iter += 1
|
||||||
|
iter = 0
|
||||||
|
while out[-1] not in end and iter < 7:
|
||||||
|
out.append(random.choice(list(prew.find(pre=out[-1])))['pro'])
|
||||||
|
iter += 1
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
async def filter(self, c, n, m):
|
||||||
|
if m[:5] == 'kim: ':
|
||||||
|
m = m[5:]
|
||||||
|
await rec(self, m)
|
||||||
|
words = m.split(' ')
|
||||||
|
await self.message(c, ' '.join(await genOut(self, await getNoun(self, words))))
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
self.db = dataset.connect('sqlite:///database.db')
|
self.db = dataset.connect('sqlite:///database.db')
|
||||||
|
|
||||||
|
self.raw['nlp'] = filter
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue