From e17c76a8bee9a2236fdcce54f56408e27a93f735 Mon Sep 17 00:00:00 2001 From: lickthecheese Date: Wed, 22 Apr 2020 21:43:07 -0400 Subject: [PATCH] functional --- bot.py | 2 +- modules/__pycache__/nlp.cpython-36.pyc | Bin 0 -> 2045 bytes modules/nlp.py | 47 +++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 modules/__pycache__/nlp.cpython-36.pyc diff --git a/bot.py b/bot.py index a91f75d..960c0e2 100755 --- a/bot.py +++ b/bot.py @@ -37,7 +37,7 @@ class Oven(pydle.Client): async def on_message(self, chan, source, msg): if source != self.nickname: 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: await self.raw[i](self, chan,source,msg) if msg[:len(self.prefix)] == self.prefix: diff --git a/modules/__pycache__/nlp.cpython-36.pyc b/modules/__pycache__/nlp.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cad3594e74323cd9fa38787bd2ca7a8cca95f4c6 GIT binary patch literal 2045 zcmcIl%Wfk@6s=c3;y6qQ^N0h2(eMzKP>h%b(#VQfL?e)pSzKj*XH?AtQfXHWNM zVd-mcBuuwdLs7^w)WHRxbI#JOQaFzfUw9$NSB8ioU)^`yK47I+?OdMK3^!lvST!~A zsa0uql3IBf_pOXmZP^vS-{e-EW=1!KmDogG)>KyLL+j2J)u1IN`TtwA=4TjL}e6@xe$#BmymY;nbJb8`o)D<6)+!q5*vHQ8@iJMg&ox7^F$4Op9*<`wRmx57bpPj$k zkBbi2*=>)rs5j2{U@Z3;i9O&+j^bxc&#Yr+)lmWhy$DAND<=tPMFgzg!m4>2UDqSF zb1Sox!rUV-F>!qp8!TQ)Smrf!jBf+o8sFmP1I$+V2AHgr{s$)4O0P0#sqGcgQhStH z&hOt~KZ zz5XTg==kvgqj)aTTZp6(>E$BQ%hDfuuSC1mV7k7Dw$XqdkVVT#KOu8`5V+ZKqW&+m z8)EfMc$;l3ypOh|e5W6$-<=e1WSq42|J{PvUEHEdT9WxC(F_Tb5?mHvk{1rjXy?8B z8;^NFUf-$EP?lQX^irKotRD@sB#Nyf;aa~poubAxgG!MkVTbK?sjw<3Vq*xB*QM!K z(7cDGRVCPV>h$?t{t>T3r`2da#h!@ZqK7I0rJ$<>Ll~u`n*Sqeu@a)yTJBqod}(ox*RF1Pq% zN-RVgf$bn5ehL&ojT9=`5A?UfP~Jqly0Yw?-^q_rLr z8;~!L3mZgPn#NI4(M~T!sqURZ9j@NIR#{Y%CdET+${jJhF3cC0K?^Mm=0obJ>bUQ( ikf4xm(~a+TQK@L!uwDI6>`}GM3C@s*BHRoEYX1O{yO8q$ literal 0 HcmV?d00001 diff --git a/modules/nlp.py b/modules/nlp.py index fcf3262..4d0a691 100644 --- a/modules/nlp.py +++ b/modules/nlp.py @@ -2,11 +2,54 @@ import dataset 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): self.db = dataset.connect('sqlite:///database.db') + self.raw['nlp'] = filter +