Ejemplo n.º 1
0
def gen_next():

    global status
    global head
    global poem
    global options
    global gen_options
    global poems
    global g

    print("OPTIONS:", options)
    print("GEN_OPTIONS:", gen_options)

    if options["genre"][1] == gen_options["genre"][1] and \
     options["title"][1] == gen_options["title"][1] and \
     options["part"][1] == gen_options["part"][1]:

        if options["form"][1] == gen_options["form"][1] and \
         len(poems) > options["form"][1] and \
         len(poems[ options["form"][1] ]) > 1:

            ### next with the same options

            options["form"][2] = len(poems) - 1
            options["form"][0] = options["form"][1] / (options["form"][2] + 1)
            options["form"][3] = poems[options["form"][1]][0]

            poem = poems[options["form"][1]].pop(1) + "\n"

            if len(poems[options["form"][1]]) == 1:
                poems.pop(options["form"][1])
                options["form"][2] = len(poems) - 1
                options["form"][1] = int(options["form"][0] *
                                         options["form"][2])
                if len(poems) > options["form"][1]:
                    options["form"][3] = poems[options["form"][1]][0]

        else:

            ### not exists with the same options

            if options["part"][1] < options["part"][2]:
                options["part"][1] += 1
            else:
                options["part"][1] = 0

            print("GEN with another part")

            gen_fail = 1

            while gen_fail == 1:

                gen_fail = 0

                g = generator.gen_poem(options["genre"][0],
                                       options["title"][0], options["part"][0],
                                       -1)
                poems = g.poems

                name = options["form"][3]

                i = -1
                for item in range(0, len(poems)):
                    if name == poems[item][0]:
                        i = item
                        continue

                n = len(poems) - 1

                if i == -1 or len(poems[i]) < 2:

                    if len(poems[i]) < 2: poems.pop(i)
                    n = len(poems) - 1
                    i = int(n * options["form"][0])

                    if (len(poems) > i):
                        name = poems[i][0]
                    else:
                        gen_fail = 1
                        options["part"] = [0, 0, 0, 0]

            options["form"][1:4] = [i, n, name]

            poem = poems[options["form"][1]].pop(1) + "\n"

    else:

        print("GEN with new options")

        gen_fail = 1

        while gen_fail == 1:

            gen_fail = 0

            g = generator.gen_poem(options["genre"][0], options["title"][0],
                                   options["part"][0], -1)

            poems = g.poems

            name = options["form"][3]

            i = -1
            for item in range(0, len(poems)):
                if name == poems[item][0]:
                    i = item
                    continue

            n = len(poems) - 1

            if i == -1 or len(poems[i]) < 2:

                if len(poems[i]) < 2: poems.pop(i)

                n = len(poems) - 1
                i = int(n * options["form"][0])

                if (len(poems) > i):
                    name = poems[i][0]
                else:
                    gen_fail = 1
                    options["part"] = [0, 0, 0, 0]

        options["form"][1:4] = [i, n, name]

        print("options:", options)

        poem = poems[i].pop(1) + "\n"

        if len(poems[i]) == 1:
            poems.pop(i)
            options["form"][2] = len(poems) - 1

    head = "%s\n%s\n%s\n%s\n" % (options["genre"][3], options["title"][3],
                                 options["part"][3], options["form"][3])

    print(head)  ####
    print(poem)  ####

    gen_options = copy.deepcopy(options)

    status = 1
Ejemplo n.º 2
0
def gen_next():

	global status
	global head
	global poem
	global options
	global gen_options
	global poems
	global g

	print("OPTIONS:", options)
	print("GEN_OPTIONS:", gen_options)

	if options["genre"][1] == gen_options["genre"][1] and \
		options["title"][1] == gen_options["title"][1] and \
		options["part"][1] == gen_options["part"][1]:

		if options["form"][1] == gen_options["form"][1] and \
			len(poems) > options["form"][1] and \
			len(poems[ options["form"][1] ]) > 1:
			
			### next with the same options

			options["form"][2] = len(poems) - 1
			options["form"][0] = options["form"][1] / (options["form"][2] + 1)
			options["form"][3] = poems[ options["form"][1] ][0]

			poem = poems[ options["form"][1] ].pop(1) + "\n"

			if len(poems[ options["form"][1] ]) == 1:
			 	poems.pop(options["form"][1])
			 	options["form"][2] = len(poems) - 1
			 	options["form"][1] = int(options["form"][0] * options["form"][2])
			 	if len(poems) > options["form"][1]:
			 		options["form"][3] = poems[ options["form"][1] ][0]

		else:

			### not exists with the same options

			if options["part"][1] < options["part"][2]:
				options["part"][1] += 1
			else:
				options["part"][1] = 0

			print("GEN with another part")

			gen_fail = 1

			while gen_fail == 1:

				gen_fail = 0

				g = generator.gen_poem (
					options["genre"][0], options["title"][0], options["part"][0], -1)
				poems = g.poems

				name = options["form"][3]
				
				i = -1
				for item in range(0, len(poems)):
					if name == poems[item][0]:
						i = item
						continue
				
				n = len(poems) - 1

				if i == -1 or len(poems[i]) < 2:
					
					if len(poems[i]) < 2: poems.pop(i)
					n = len(poems) - 1
					i = int(n * options["form"][0])

					if (len(poems) > i):
						name = poems[i][0]
					else:
						gen_fail = 1
						options["part"] = [0, 0, 0, 0]

			options["form"][1:4] = [i, n, name]
			
			poem = poems[ options["form"][1] ].pop(1) + "\n"

	else:

		print("GEN with new options")

		gen_fail = 1

		while gen_fail == 1:
			
			gen_fail = 0

			g = generator.gen_poem (
				options["genre"][0], options["title"][0], options["part"][0], -1)
			
			poems = g.poems

			name = options["form"][3]
			
			i = -1
			for item in range(0, len(poems)):
				if name == poems[item][0]:
					i = item
					continue
			
			n = len(poems) - 1

			if i == -1 or len(poems[i]) < 2:
				
				if len(poems[i]) < 2: poems.pop(i)
				
				n = len(poems) - 1
				i = int(n * options["form"][0])

				if (len(poems) > i):
					name = poems[i][0]
				else:
					gen_fail = 1
					options["part"] = [0, 0, 0, 0]

		options["form"][1:4] = [i, n, name]

		print("options:", options)

		poem = poems[i].pop(1) + "\n"

		if len(poems[i]) == 1:
			poems.pop(i)
			options["form"][2] = len(poems) - 1

	head = "%s\n%s\n%s\n%s\n" % (
		options["genre"][3], options["title"][3], options["part"][3], options["form"][3])

	print(head) ####
	print(poem) ####

	gen_options = copy.deepcopy(options)

	status = 1
Ejemplo n.º 3
0
import generator

SERVER_PORT = 12345
DATA_PATH = pth + '/../data/corpus_mark'

options = {}
name_re = re.compile("(.*) \d+( trans)?")

t_g = random.uniform(0, 1)
t_t = random.uniform(0, 1)
t_p = random.uniform(0, 1)
t_f = random.uniform(0, 1)

gen_options = {}
g = generator.gen_poem(t_g, t_t, t_p, -1)
poems = g.poems


def gen_next():

    global status
    global head
    global poem
    global options
    global gen_options
    global poems
    global g

    print("OPTIONS:", options)
    print("GEN_OPTIONS:", gen_options)
Ejemplo n.º 4
0
import generator

SERVER_PORT = 12345
DATA_PATH = pth + '/../data/corpus_mark'

options = {}
name_re = re.compile("(.*) \d+( trans)?")

t_g = random.uniform(0, 1)
t_t = random.uniform(0, 1)
t_p = random.uniform(0, 1)
t_f = random.uniform(0, 1)

gen_options = {}
g = generator.gen_poem(t_g, t_t, t_p, -1)
poems = g.poems

def gen_next():

	global status
	global head
	global poem
	global options
	global gen_options
	global poems
	global g

	print("OPTIONS:", options)
	print("GEN_OPTIONS:", gen_options)