コード例 #1
0
ファイル: test.py プロジェクト: MorroLuarvik/pyrpg
    def __init__(self):
        self._createUI()
        self.paused = True
        self.rnd = Rnd()
        self.frameTime = 40

        self.part = None
        self.particleImgId = None
コード例 #2
0
ファイル: aldo.py プロジェクト: AlbertCalmus/aldo
def improvise(message):
    print(" >>> " + message.from_user.first_name + " : " + message.text)
    if "📝" in message.text:
        db = Db(sqlite3.connect('booba.db'), Sql())
        generator = Generator('booba', db, Rnd())
        msg = generator.generate(' ') + "\n" + generator.generate(' ')
        bot.send_message(message.chat.id, msg)
コード例 #3
0
ファイル: test.py プロジェクト: MorroLuarvik/pyrpg
	def __init__(self):
		self._createUI()
		self.paused = True
		self.rnd = Rnd()
		self.frameTime = 40
		
		self.part = None
		self.particleImgId = None
コード例 #4
0
def generate(name, count):
    db = Db(sqlite3.connect(name + '.db'), Sql())
    generator = Generator(name, db, Rnd())
    markov_text = []
    for i in range(0, count):
        markov_text.append(generator.generate(WORD_SEPARATOR))

    return markov_text
コード例 #5
0
def pontificate(bot, trigger):
    print "Generating sentence..."
    markLen = [int(x) for x in trigger.split() if x.isdigit()]

    db = Db(sqlite3.connect(NAME + '.db'), Sql())
    gen = Generator(NAME, db, Rnd())

    for i in range(0, DEFAULT_LENGTH):
        bot.say(gen.generate(WORD_SEPARATOR))
コード例 #6
0
ファイル: __init__.py プロジェクト: UCI-TPL/geo-poetry-server
def MarkovGenerator(sentence_list, depth, db_filepath, db=None, rnd=None):
    """Generator that generates new sentences from a list of sentences.
	Arguments:
		sentence_list		List of strings, each being a single sentence to learn from
		depth				Depth of analysis at which to build the Markov chain
		db_filepath			Path to file where sqlite database will be stored
		db (optional)		Db object (for mocking in unit tests)
		rnd (optional)		Rnd object (for mocking in unit tests)"""
    if not db:
        db = Db(sqlite3.connect(db_filepath), Sql())
        db.setup(depth)
    if not rnd:
        rnd = Rnd()

    parser = Parser(DB_NAME, db, SENTENCE_SEPARATOR).parse_list(sentence_list)
    generator = Generator(DB_NAME, db, rnd)
    while True:
        sentence = generator.generate(WORD_SEPARATOR).strip()
        if len(sentence) == 0:
            continue  # avoid generating the empty string
        else:
            yield sentence
コード例 #7
0
        args[0], )

    if (len(args) < 3):
        raise ValueError(usage)

    mode = args[1]
    name = args[2]

    if mode == 'parse':
        if (len(args) != 5):
            raise ValueError(usage)

        depth = int(args[3])
        file_name = args[4]

        db = Db(sqlite3.connect(name + '.db'), Sql())
        db.setup(depth)

        txt = codecs.open(file_name, 'r', 'utf-8').read()
        Parser(name, db, SENTENCE_SEPARATOR, WORD_SEPARATOR).parse(txt)

    elif mode == 'gen':
        count = int(args[3])
        db = Db(sqlite3.connect(name + '.db'), Sql())
        generator = Generator(name, db, Rnd())
        for i in range(0, count):
            print(generator.generate(WORD_SEPARATOR))

    else:
        raise ValueError(usage)
コード例 #8
0
    return segment


if __name__ == '__main__':
    args = sys.argv
    usage = 'Usage: %s (db_name path_to_json output_mp3_path)' % (args[0], )

    if (len(args) < 3):
        raise ValueError(usage)

    db_name = args[1]
    path_to_json = args[2]
    output_mp3_path = args[3]

    db = Db(sqlite3.connect(db_name + '.db'), Sql())
    generator = GenratorWithSeed(db_name, db, Rnd())

    labels = read_json(path_to_json)

    usedBefore = set()

    fullTrack = textToAudioSegment(
        "Hello, this AI streamer. Markov process on Reddit comments")

    curr_time_mksec = fullTrack.duration_seconds * 1000000

    while (curr_time_mksec < max(labels['end'])):
        observedBefore = set(
            labels[labels['start'] < curr_time_mksec]['Label'])
        candidates = list(observedBefore - usedBefore)
コード例 #9
0
def generate(number, name):
    count = number
    db = Db(sqlite3.connect(name + '.db'), Sql())
    generator = Generator(name, db, Rnd())
    for i in range(0, count):
        yield generator.generate(WORD_SEPARATOR)
コード例 #10
0
ファイル: test_rnd.py プロジェクト: MorroLuarvik/pyrpg
#!/usr/bin/python
# -*- coding: utf-8 -*-

from rnd import Rnd

rnd = Rnd()

cou = 0
while rnd.get() <> 0:
    cou += 1
print("from 0 to 0: {0} ones".format(cou))


simples = [2]
end = 7000  # 65535 #1000000000
lastSimple = simples[-1]
while simples[-1] < end:
    lastSimple += 1
    isSimple = False
    for findedSimples in simples:
        if lastSimple % findedSimples == 0:
            isSimple = False
            break
        isSimple = True
    if isSimple:
        simples.append(lastSimple)

print(simples[-1])
print(simples[-20])
print(simples[-30])
コード例 #11
0
ファイル: tweet_bot.py プロジェクト: nmyk/markov-text
def create_tweet():
	db = Db(sqlite3.connect(NAME + '.db'), Sql())
	generator = Generator(NAME, db, Rnd())
	tweet_candidate = generator.generate(WORD_SEPARATOR)
	return tweet_candidate if check_length(tweet_candidate)  else create_tweet()
コード例 #12
0
ファイル: markov.py プロジェクト: AlbertCalmus/aldo
from rnd import Rnd
import sys
import sqlite3
import codecs

SENTENCE_SEPARATOR = '_'
WORD_SEPARATOR = ' '

if __name__ == '__main__':
    args = sys.argv
    usage = 'Usage: %s (parse <name> <depth> <path to txt file>|gen <name> <count>)' % (
        args[0], )

    if (len(args) < 3):
        db = Db(sqlite3.connect('booba' + '.db'), Sql())
        generator = Generator('booba', db, Rnd())
        print(generator.generate(WORD_SEPARATOR))
        print(generator.generate(WORD_SEPARATOR))

    else:
        mode = args[1]
        name = args[2]

        if mode == 'parse':
            if (len(args) != 5):
                raise ValueError(usage)

            depth = int(args[3])
            file_name = args[4]

            db = Db(sqlite3.connect(name + '.db'), Sql())
コード例 #13
0
ファイル: test.py プロジェクト: MorroLuarvik/pyrpg
class MainWindow:
    def __init__(self):
        self._createUI()
        self.paused = True
        self.rnd = Rnd()
        self.frameTime = 40

        self.part = None
        self.particleImgId = None

    def start(self):
        self.root.mainloop()

    def _createUI(self):
        self.root = tk.Tk()
        self.root.title('Test application')
        self.root.geometry('600x400')

        self.firstRow = tk.Frame(self.root)
        self.firstRow.pack(fill=tk.X)

        self.withLabel = tk.Label(self.firstRow, text='Width: ')
        self.withLabel.pack(side=tk.LEFT)
        self.withLabelValue = tk.Label(self.firstRow, text='xxx')
        self.withLabelValue.pack(side=tk.LEFT)

        self.secondRow = tk.Frame(self.root)
        self.secondRow.pack(fill=tk.X)

        self.thirdRow = tk.Frame(self.root)
        self.thirdRow.pack(fill=tk.X)

        self.heightLabel = tk.Label(self.secondRow, text='Height: ')
        self.heightLabel.pack(side=tk.LEFT)
        self.heightLabelValue = tk.Label(self.secondRow, text='yyy')
        self.heightLabelValue.pack(side=tk.LEFT)

        self.speedLabelValue = tk.Label(self.secondRow, text='speed')
        self.speedLabelValue.pack(side=tk.LEFT)

        self.actionButton = tk.Button(self.thirdRow, text='Animate', width=10)
        self.actionButton.pack(side=tk.LEFT)

        self.spaceLabel = tk.Label(self.thirdRow, text='   ')
        self.spaceLabel.pack(side=tk.LEFT)

        self.otherButton = tk.Button(self.thirdRow,
                                     text='other',
                                     width=10,
                                     padx=10)
        self.otherButton.pack(side=tk.LEFT)

        self.bgg = '#111'

        self.canvas = tk.Canvas(self.root, bg=self.bgg)  #, bg=self.bgg
        self.canvas.pack(fill=tk.BOTH, expand=tk.YES)

        self.img = tk.PhotoImage()  #width=800, height=600
        #self.img.blank()

        self.canvas.create_image(0, 0, image=self.img,
                                 anchor='nw')  # , state="normal", anchor='nw'

        self._setBindings()

        self.root.after(1000, self.animate)

    def animate(self):
        startTime = time()
        if not (self.paused):
            for cou in xrange(0, 20):
                size = self.rnd.get(32)
                self.plotPixel(
                    self.img, self.rnd.get(self.canvas.winfo_width() - size),
                    self.rnd.get(self.canvas.winfo_height() - size),
                    '#{0:1X}{1:1X}{2:1X}'.format(self.rnd.get(10),
                                                 self.rnd.get(10),
                                                 self.rnd.get(10)), size)

        if self.part:
            self.part.animate(self.particleImg)
            #print(self.part.elems)

        execTime = int((time() - startTime) * 1000)
        if execTime:
            speed = 1000 // execTime
        else:
            speed = 'inf'
        self.speedLabelValue.config(text=speed)
        #frameTime = 40
        waiting = max(1, self.frameTime - execTime)
        self.root.after(waiting, self.animate)

    def _setBindings(self):
        self.root.bind('<Configure>', self._resizeApp)
        self.actionButton.bind('<Button-1>', self._click)
        self.otherButton.bind('<Button-1>', self._otherAction)

    def _resizeApp(self, event):
        self.withLabelValue.config(text=self.canvas.winfo_width())
        self.heightLabelValue.config(text=self.canvas.winfo_height())

    def plotPixel(self, img, x, y, color, size=3):
        img.put(color, (x, y, x + size, y + size))
        #for sy in xrange(0, size):
        #img.put('{' + (color + ' ') * size + '}', (x, y+sy))

    def _click(self, event):
        self.paused = not (self.paused)
        if self.paused:
            self.actionButton.config(text='Animate')
        else:
            self.actionButton.config(text='Pause')

    def _otherAction(self, event):
        #self.otherImg = tk.PhotoImage(file='mark')
        #self.otherImg = tk.PhotoImage(width=16, height=16)

        #self.otherImg.put('#f11', (0, 0, 7, 7))
        #self.otherImg.put('#111', (1, 1, 6, 6))
        #self.otherImg.put('#11f', (8, 8, 16, 16))

        #self.canvas.create_image(100, 100, image=self.otherImg, anchor='nw')  # , state="normal", anchor='nw'

        #self.otherImg.write('mark')

        #print(self.otherImg)

        self.part = Particle(self.rnd)
        self.particleImg = tk.PhotoImage(width=192, height=192)

        if (self.particleImgId):
            self.canvas.delete(self.particleImgId)

        self.particleImgId = self.canvas.create_image(
            100,
            self.canvas.winfo_height() - self.particleImg.height(),
            image=self.particleImg,
            anchor='nw')

        #print(self.part.elems)
        print('created: {}'.format(self.particleImgId))
        print(self.canvas.find_all())
        print('_otherAction')
コード例 #14
0
ファイル: test.py プロジェクト: MorroLuarvik/pyrpg
class MainWindow:
	def __init__(self):
		self._createUI()
		self.paused = True
		self.rnd = Rnd()
		self.frameTime = 40
		
		self.part = None
		self.particleImgId = None
			
	def start(self):
		self.root.mainloop()
		
	def _createUI(self):
		self.root = tk.Tk()
		self.root.title('Test application')
		self.root.geometry('600x400')
		
		self.firstRow = tk.Frame(self.root)
		self.firstRow.pack(fill=tk.X)

		self.withLabel = tk.Label(self.firstRow, text='Width: ')
		self.withLabel.pack(side=tk.LEFT)
		self.withLabelValue = tk.Label(self.firstRow, text='xxx')
		self.withLabelValue.pack(side=tk.LEFT)

		self.secondRow = tk.Frame(self.root)
		self.secondRow.pack(fill=tk.X)
		
		self.thirdRow = tk.Frame(self.root)
		self.thirdRow.pack(fill=tk.X)

		self.heightLabel = tk.Label(self.secondRow, text='Height: ')
		self.heightLabel.pack(side=tk.LEFT)
		self.heightLabelValue = tk.Label(self.secondRow, text='yyy')
		self.heightLabelValue.pack(side=tk.LEFT)
		
		self.speedLabelValue = tk.Label(self.secondRow, text='speed')
		self.speedLabelValue.pack(side=tk.LEFT)
		
		self.actionButton = tk.Button(self.thirdRow, text='Animate', width=10)
		self.actionButton.pack(side=tk.LEFT)
		
		self.spaceLabel = tk.Label(self.thirdRow, text='   ')
		self.spaceLabel.pack(side=tk.LEFT)
		
		self.otherButton = tk.Button(self.thirdRow, text='other', width=10, padx=10)
		self.otherButton.pack(side=tk.LEFT)

		self.bgg = '#111';
		
		self.canvas = tk.Canvas(self.root, bg=self.bgg) #, bg=self.bgg
		self.canvas.pack(fill=tk.BOTH, expand=tk.YES)
		
		self.img = tk.PhotoImage() #width=800, height=600
		#self.img.blank()

		self.canvas.create_image(0, 0, image=self.img, anchor='nw')  # , state="normal", anchor='nw'
		
		self._setBindings()
		
		self.root.after(1000, self.animate)
		
	def animate(self):
		startTime = time()
		if not(self.paused):
			for cou in xrange(0, 20):
				size = self.rnd.get(32)
				self.plotPixel(
					self.img, 
					self.rnd.get(self.canvas.winfo_width() - size), 
					self.rnd.get(self.canvas.winfo_height() - size), 
					'#{0:1X}{1:1X}{2:1X}'.format(
						self.rnd.get(10), 
						self.rnd.get(10), 
						self.rnd.get(10)), 
					size)
		
		if self.part: 
			self.part.animate(self.particleImg)
			#print(self.part.elems)
		
				
		execTime = int((time() - startTime) * 1000)
		if execTime:
			speed = 1000 // execTime
		else:
			speed = 'inf'
		self.speedLabelValue.config(text=speed)
		#frameTime = 40
		waiting = max(1, self.frameTime - execTime)
		self.root.after(waiting, self.animate)
		
	def _setBindings(self):
		self.root.bind('<Configure>', self._resizeApp)
		self.actionButton.bind('<Button-1>', self._click)
		self.otherButton.bind('<Button-1>', self._otherAction)

	def _resizeApp(self, event):
		self.withLabelValue.config(text=self.canvas.winfo_width())
		self.heightLabelValue.config(text=self.canvas.winfo_height())

	def plotPixel(self, img, x, y, color, size = 3):
		img.put(color, (x, y, x+size, y+size))
		#for sy in xrange(0, size):
			#img.put('{' + (color + ' ') * size + '}', (x, y+sy))
		
	def _click(self, event):
		self.paused = not(self.paused)
		if self.paused:
			self.actionButton.config(text='Animate')
		else:
			self.actionButton.config(text='Pause')

	def _otherAction(self, event):
		#self.otherImg = tk.PhotoImage(file='mark')
		#self.otherImg = tk.PhotoImage(width=16, height=16)
		
		#self.otherImg.put('#f11', (0, 0, 7, 7))
		#self.otherImg.put('#111', (1, 1, 6, 6))
		#self.otherImg.put('#11f', (8, 8, 16, 16))
		
		#self.canvas.create_image(100, 100, image=self.otherImg, anchor='nw')  # , state="normal", anchor='nw'
		
		#self.otherImg.write('mark')
		
		#print(self.otherImg)
		
		self.part = Particle(self.rnd)
		self.particleImg = tk.PhotoImage(width=192, height=192)
		
		if (self.particleImgId):
			self.canvas.delete(self.particleImgId)
			
		self.particleImgId = self.canvas.create_image(100, self.canvas.winfo_height()-self.particleImg.height(), image=self.particleImg, anchor='nw')
		
		#print(self.part.elems)
		print('created: {}'.format(self.particleImgId))
		print(self.canvas.find_all())
		print('_otherAction')